(args: Args)
| 67 | } |
| 68 | |
| 69 | function main(args: Args): void { |
| 70 | if (!args.dist) { |
| 71 | console.error( |
| 72 | 'Usage: check_dist_package_json --dist <dist-dir> --package <package-dir>=<package-json>...' |
| 73 | ) |
| 74 | process.exit(1) |
| 75 | } |
| 76 | |
| 77 | const packageArgs = Array.isArray(args.package) |
| 78 | ? args.package |
| 79 | : args.package |
| 80 | ? [args.package] |
| 81 | : [] |
| 82 | if (packageArgs.length === 0) { |
| 83 | console.error('FAIL: at least one --package must be provided') |
| 84 | process.exit(1) |
| 85 | } |
| 86 | |
| 87 | const errors: string[] = [] |
| 88 | const packageJsons: Array<{ |
| 89 | actualPath: string |
| 90 | actualJson: PackageJson |
| 91 | }> = [] |
| 92 | const workspacePackageNames = new Set<string>() |
| 93 | |
| 94 | for (const packageArg of packageArgs) { |
| 95 | const [packageDir, expectedPath] = parsePackageArg(packageArg) |
| 96 | const actualPath = join(args.dist, 'packages', packageDir, 'package.json') |
| 97 | const errorCountBefore = errors.length |
| 98 | |
| 99 | for (const path of [actualPath, expectedPath]) { |
| 100 | if (!existsSync(path)) { |
| 101 | errors.push(`${path} does not exist`) |
| 102 | continue |
| 103 | } |
| 104 | try { |
| 105 | readPackageJson(path) |
| 106 | } catch (err) { |
| 107 | errors.push(`${path} is not valid JSON: ${(err as Error).message}`) |
| 108 | } |
| 109 | } |
| 110 | if (errors.length > errorCountBefore) continue |
| 111 | |
| 112 | const actualJson = readPackageJson(actualPath) |
| 113 | const actual = readFileSync(actualPath, 'utf8') |
| 114 | const expected = readFileSync(expectedPath, 'utf8') |
| 115 | if (actual !== expected) { |
| 116 | errors.push( |
| 117 | `${actualPath} does not match generated manifest ${expectedPath}` |
| 118 | ) |
| 119 | } |
| 120 | |
| 121 | if (typeof actualJson.name === 'string') { |
| 122 | workspacePackageNames.add(actualJson.name) |
| 123 | } |
| 124 | packageJsons.push({ |
| 125 | actualPath, |
| 126 | actualJson, |
no test coverage detected