补齐固定旧版的浏览器逐笔写入对照并记录账务差异

This commit is contained in:
黄健铭 committed 2026-12-05 02:33:01 -08:00
1 parent e77588b337
commit 7d2007955f
39 files changed
+3653 -41

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
export const app = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
const repo = path.dirname(app);
export const git = (...args) =>
execFileSync('git', ['-C', repo, ...args], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }).trimEnd();
export const reference = git('rev-parse', 'f1a4e69^{commit}');
export function fixedReference(temp, supplied) {
if (supplied) {
const root = path.resolve(supplied);
const tree = git('ls-tree', '-rz', reference, '--', path.basename(app));
for (const entry of tree.split('\0').filter(Boolean)) {
const [meta, name] = entry.split('\t');
const content = fs.readFileSync(path.join(root, path.relative(path.basename(app), name)));
const actual = createHash('sha1')
.update('blob ' + content.length + '\0')
.update(content)
.digest('hex');
assert.equal(actual, meta.split(' ')[2], '旧版检出不符合 ' + reference + ': ' + name);
}
return root;
}
const archive = path.join(temp, 'reference.tar');
git('archive', '--output=' + archive, reference, '--', path.basename(app));
execFileSync('tar', ['-xf', archive, '-C', temp]);
const root = path.join(temp, path.basename(app));
for (const folder of ['', 'e2e', 'web']) {
const modules = path.join(app, folder, 'node_modules');
if (fs.existsSync(modules)) fs.symlinkSync(modules, path.join(root, folder, 'node_modules'), 'dir');
}
return root;
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
console.log(fixedReference(process.argv[2], process.env.LEDGER_REFERENCE_APP));
}