Skip to content

Commit 3520547

Browse files
author
王璨
committed
fix: enforce public npm registry to fix GitHub Actions npm ci failures
1 parent 5cf34fd commit 3520547

3 files changed

Lines changed: 136 additions & 117 deletions

File tree

scripts/lockfile-check.mjs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
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
22
import { readFileSync } from "fs";
33
import { resolve, dirname } from "path";
44
import { fileURLToPath } from "url";
55

66
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+
];
911

1012
const PRIVATE_REGISTRIES = [
1113
"bnpm.byted.org",
1214
// add other private registries here if needed
1315
];
1416

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+
}
1630

17-
if (found.length > 0) {
31+
if (fail) {
1832
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` +
2334
` then run: rm -rf node_modules package-lock.json && npm install\n`
2435
);
2536
process.exit(1);
2637
}
2738

28-
console.log("✅ lockfile:check passed — all packages use public registry");
39+
console.log("✅ lockfile:check passed — all lockfiles use public registry");

web/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

0 commit comments

Comments
 (0)