"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/scripts/check-dependencies.ts" (20 Feb 2024, 2752 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 * as depcheck from 'depcheck';
    2 import * as fs from 'fs';
    3 import * as path from 'path';
    4 import * as glob from 'glob';
    5 import { config } from '../check-dependencies.config';
    6 import { icon } from '../src/lib/theme';
    7 
    8 const checkDependencies = async () => {
    9   let exitCode = 0;
   10 
   11   const rootPackagePath = path.resolve(__dirname, '..');
   12   const packageJson = JSON.parse(
   13     fs.readFileSync(path.resolve(rootPackagePath, 'package.json'), 'utf-8'),
   14   );
   15   const workspaceGlobs = [rootPackagePath].concat(packageJson.workspaces);
   16 
   17   console.log();
   18   console.log('-'.repeat(32));
   19   console.log();
   20 
   21   for (const workspaceGlob of workspaceGlobs) {
   22     const workspacePaths = glob.sync(workspaceGlob).map((p) => path.resolve(p));
   23     for (const workspacePath of workspacePaths) {
   24       console.log(`Checking ${workspacePath}`);
   25       const workspaceResults = await depcheck(workspacePath, config);
   26       const missingDependencies = Object.entries(workspaceResults.missing);
   27       const hasProblems =
   28         workspaceResults.dependencies.length > 0 ||
   29         workspaceResults.devDependencies.length > 0 ||
   30         missingDependencies.length > 0;
   31 
   32       if (hasProblems) {
   33         exitCode = 1;
   34 
   35         if (workspaceResults.dependencies.length > 0) {
   36           console.log(
   37             `\n  ${workspaceResults.dependencies.length} Unused Production Dependencies`,
   38           );
   39           for (const packageName of workspaceResults.dependencies) {
   40             console.log(`    - ${packageName}`);
   41           }
   42         }
   43 
   44         if (workspaceResults.devDependencies.length > 0) {
   45           console.log(
   46             `\n  ${workspaceResults.devDependencies.length} Unused Development Dependencies`,
   47           );
   48           for (const packageName of workspaceResults.devDependencies) {
   49             console.log(`    - ${packageName}`);
   50           }
   51         }
   52 
   53         if (missingDependencies.length > 0) {
   54           console.log(`\n  ${missingDependencies.length} Missing Dependencies`);
   55           for (const [packageName, dependentFiles] of missingDependencies) {
   56             console.log(`    - ${packageName}`);
   57             for (const file of dependentFiles) {
   58               console.log(`      > ${file}`);
   59             }
   60           }
   61         }
   62       } else {
   63         console.log(`\n ${icon.VALID} No problems found.`);
   64       }
   65 
   66       console.log();
   67       console.log('-'.repeat(32));
   68       console.log();
   69     }
   70   }
   71 
   72   if (exitCode !== 0) {
   73     console.log(
   74       'Problems found. See output above.\n',
   75       '  If you think a package is wrongly flagged:\n',
   76       '    1. Add it to ./check-dependencies.config.ts\n',
   77       '    2. Provide a reason next to it.',
   78     );
   79     process.exit(exitCode);
   80   }
   81 
   82   console.log('No problems found.');
   83 };
   84 
   85 checkDependencies();