(args: Args)
| 68 | } |
| 69 | |
| 70 | function main(args: Args): void { |
| 71 | if (!args.pkg) { |
| 72 | console.error( |
| 73 | 'Usage: check_package_json --pkg <package.json> --bundle <path>...' |
| 74 | ) |
| 75 | process.exit(1) |
| 76 | } |
| 77 | const bundles = Array.isArray(args.bundle) |
| 78 | ? args.bundle |
| 79 | : args.bundle |
| 80 | ? [args.bundle] |
| 81 | : [] |
| 82 | if (bundles.length === 0) { |
| 83 | console.error('FAIL: at least one --bundle must be provided') |
| 84 | process.exit(1) |
| 85 | } |
| 86 | |
| 87 | const pkg = JSON.parse(readFileSync(args.pkg, 'utf8')) |
| 88 | const declared = new Set<string>([ |
| 89 | ...Object.keys(pkg.dependencies ?? {}), |
| 90 | ...Object.keys(pkg.peerDependencies ?? {}), |
| 91 | ]) |
| 92 | |
| 93 | const errors: string[] = [] |
| 94 | for (const bundle of bundles) { |
| 95 | checkBundle(bundle, declared, errors) |
| 96 | } |
| 97 | |
| 98 | if (errors.length > 0) { |
| 99 | for (const err of errors) console.error(`FAIL: ${err}`) |
| 100 | process.exit(1) |
| 101 | } |
| 102 | |
| 103 | console.log('PASS: all bundle imports are declared in package.json') |
| 104 | } |
| 105 | |
| 106 | if (import.meta.filename === process.argv[1]) { |
| 107 | main(minimist<Args>(process.argv.slice(2))) |
no test coverage detected