mirror of
https://github.com/qybaihe/bla.git
synced 2026-11-20 08:20:59 +08:00
3c18b1460b
scripts/sync-version.mjs previously rewrote only src/identity.ts, leaving package-lock.json root version and challenge SEALs silently out of sync after a version bump (package.json 1.6.4 vs lock/SEAL 1.6.3). sync now updates package-lock.json too; crackme v7 seal rejects seal.blaVersion != package.json.version; regenerate both SEALs at 1.6.4. Co-authored-by: Timo Zhang <qybaihe@gmail.com>
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
const root = resolve(import.meta.dirname, "..");
|
|
const pkgPath = resolve(root, "package.json");
|
|
const identityPath = resolve(root, "src/identity.ts");
|
|
const lockPath = resolve(root, "package-lock.json");
|
|
|
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
const version = String(pkg.version);
|
|
|
|
const identityText = readFileSync(identityPath, "utf8");
|
|
const updated = identityText.replace(
|
|
/version:\s*"[^"]+"/,
|
|
`version: "${version}"`,
|
|
);
|
|
|
|
if (updated !== identityText) {
|
|
writeFileSync(identityPath, updated, "utf8");
|
|
console.log(`Synced BLA_IDENTITY.version -> ${version}`);
|
|
} else {
|
|
console.log(`BLA_IDENTITY.version already at ${version}`);
|
|
}
|
|
|
|
// Keep package-lock.json's root version in lockstep — `npm version` normally
|
|
// does this, but manual bumps / partial releases leave the lockfile behind and
|
|
// the drift silently passes CI (npm ci tolerates a root-version mismatch).
|
|
try {
|
|
const lock = JSON.parse(readFileSync(lockPath, "utf8"));
|
|
const rootEntry = lock.packages?.[""];
|
|
const stale =
|
|
lock.version !== version || (rootEntry && rootEntry.version !== version);
|
|
if (stale) {
|
|
lock.version = version;
|
|
if (rootEntry) rootEntry.version = version;
|
|
writeFileSync(lockPath, JSON.stringify(lock, null, 2) + "\n", "utf8");
|
|
console.log(`Synced package-lock.json version -> ${version}`);
|
|
} else {
|
|
console.log(`package-lock.json already at ${version}`);
|
|
}
|
|
} catch (err) {
|
|
console.warn(`Skipped package-lock.json sync: ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|