|
1 | | -// Check that package-lock.json doesn't leak private registry URLs |
| 1 | +// Check that package-lock.json files don't leak private registry URLs |
2 | 2 | import { readFileSync } from "fs"; |
3 | 3 | import { resolve, dirname } from "path"; |
4 | 4 | import { fileURLToPath } from "url"; |
5 | 5 |
|
6 | 6 | const __dirname = dirname(fileURLToPath(import.meta.url)); |
7 | | -const lockfilePath = resolve(__dirname, "..", "package-lock.json"); |
8 | | -const lockfile = readFileSync(lockfilePath, "utf8"); |
| 7 | +const LOCKFILES = [ |
| 8 | + resolve(__dirname, "..", "package-lock.json"), |
| 9 | + resolve(__dirname, "..", "web", "package-lock.json"), |
| 10 | +]; |
9 | 11 |
|
10 | 12 | const PRIVATE_REGISTRIES = [ |
11 | 13 | "bnpm.byted.org", |
12 | 14 | // add other private registries here if needed |
13 | 15 | ]; |
14 | 16 |
|
15 | | -const found = PRIVATE_REGISTRIES.filter((reg) => lockfile.includes(reg)); |
| 17 | +let fail = false; |
| 18 | +for (const lockfilePath of LOCKFILES) { |
| 19 | + const lockfile = readFileSync(lockfilePath, "utf8"); |
| 20 | + const found = PRIVATE_REGISTRIES.filter((reg) => lockfile.includes(reg)); |
| 21 | + |
| 22 | + if (found.length > 0) { |
| 23 | + console.error( |
| 24 | + `❌ ${lockfilePath} contains private registry URLs:\n` + |
| 25 | + ` ${found.join(", ")}` |
| 26 | + ); |
| 27 | + fail = true; |
| 28 | + } |
| 29 | +} |
16 | 30 |
|
17 | | -if (found.length > 0) { |
| 31 | +if (fail) { |
18 | 32 | console.error( |
19 | | - `❌ LOCKFILE CHECK FAILED: package-lock.json contains private registry URLs:\n` + |
20 | | - ` ${found.join(", ")}\n` + |
21 | | - `\n` + |
22 | | - ` Fix: ensure project .npmrc has 'registry=https://registry.npmjs.org',\n` + |
| 33 | + `\n Fix: ensure .npmrc has 'registry=https://registry.npmjs.org',\n` + |
23 | 34 | ` then run: rm -rf node_modules package-lock.json && npm install\n` |
24 | 35 | ); |
25 | 36 | process.exit(1); |
26 | 37 | } |
27 | 38 |
|
28 | | -console.log("✅ lockfile:check passed — all packages use public registry"); |
| 39 | +console.log("✅ lockfile:check passed — all lockfiles use public registry"); |
0 commit comments