"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/plugins/rubygems/index.ts" (20 Feb 2024, 1625 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import { inspectors, Spec } from './inspectors';
    2 import { MissingTargetFileError } from '../../errors/missing-targetfile-error';
    3 import gemfileLockToDependencies = require('./gemfile-lock-to-dependencies');
    4 import * as get from 'lodash.get';
    5 import { MultiProjectResult } from '@snyk/cli-interface/legacy/plugin';
    6 import * as types from '../types';
    7 
    8 export async function inspect(
    9   root: string,
   10   targetFile: string,
   11   options: types.Options = {},
   12 ): Promise<MultiProjectResult> {
   13   if (!targetFile) {
   14     throw MissingTargetFileError(root);
   15   }
   16   const specs = await gatherSpecs(root, targetFile, options);
   17 
   18   return {
   19     plugin: {
   20       name: 'bundled:rubygems',
   21       runtime: 'unknown',
   22     },
   23     scannedProjects: [
   24       {
   25         depTree: {
   26           name: specs.packageName,
   27           targetFile: specs.targetFile,
   28           dependencies: getDependenciesFromSpecs(specs),
   29         },
   30       },
   31     ],
   32   };
   33 }
   34 
   35 function getDependenciesFromSpecs(specs) {
   36   const gemfileLockBase64 = get(specs, 'files.gemfileLock.contents');
   37   const gemspecBase64 = get(specs, 'files.gemspec.contents');
   38   const contents = Buffer.from(
   39     gemfileLockBase64 || gemspecBase64,
   40     'base64',
   41   ).toString();
   42   const dependencies = gemfileLockToDependencies(contents);
   43   return dependencies;
   44 }
   45 
   46 async function gatherSpecs(
   47   root: string,
   48   targetFile: string,
   49   options: types.Options,
   50 ): Promise<Spec> {
   51   for (const inspector of inspectors) {
   52     if (inspector.canHandle(targetFile)) {
   53       return await inspector.gatherSpecs(root, targetFile, options);
   54     }
   55   }
   56 
   57   throw new Error(`Could not handle rubygems file: ${targetFile}`);
   58 }