fix: ship verified npm panel packages and test production migrations

This commit is contained in:
whyour
2026-10-19 14:17:53 +08:00
parent e8b6a30bd9
commit 3f02b04dff
10 changed files with 747 additions and 28 deletions
+32
View File
@@ -0,0 +1,32 @@
const fs = require('node:fs');
const path = require('node:path');
const { createHash, randomUUID } = require('node:crypto');
function restorePackageLock(root = path.resolve(__dirname, '..')) {
const copy = path.join(root, 'shell/upgrade-lock.yaml');
const destination = path.join(root, 'pnpm-lock.yaml');
if (!fs.existsSync(copy)) {
// Source checkouts already have the canonical lock; no built artifacts yet.
if (fs.existsSync(destination)) return;
throw new Error('Missing npm package upgrade lockfile');
}
const bytes = fs.readFileSync(copy);
const manifest = JSON.parse(
fs.readFileSync(path.join(root, 'static/build-info.json'), 'utf8'),
);
if (
manifest.dirty !== false ||
manifest.lockfileSha256 !== createHash('sha256').update(bytes).digest('hex')
)
throw new Error('npm package lockfile does not match its build manifest');
const temporary = path.join(root, `.upgrade-lock-${randomUUID()}`);
try {
fs.writeFileSync(temporary, bytes, { flag: 'wx', mode: 0o644 });
fs.renameSync(temporary, destination);
} finally {
fs.rmSync(temporary, { force: true });
}
}
module.exports = { restorePackageLock };
if (require.main === module) restorePackageLock();