Skip to content

Commit a8c5d94

Browse files
committed
fix(codemod): load both registries as ES modules in the --arrays proof (#29987)
Under the spec package's CommonJS default the tsx loader rewrites every imported call to (0, import_x.name)(...), so a moved entry's function source differed only by the loader's spelling of its import (93 of 112 digests). Both trees now load from a scratch copy marked type: module, and the probe refuses a CommonJS-loaded function instead of comparing it. Result: 112 of 112 digests equal. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzg1QFj9ukYzafVoAqg
1 parent 5553ee4 commit a8c5d94

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎scripts/codemod-split-conversions-registry.mjs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,12 @@ const ARRAYS_PROBE = `
804804
import { createHash } from 'node:crypto';
805805
import { pathToFileURL } from 'node:url';
806806
const m = await import(pathToFileURL(process.argv[2]).href);
807-
const digest = (c) => createHash('sha256').update(JSON.stringify(c, (k, v) => (typeof v === 'function' ? 'fn:' + v.toString() : v))).digest('hex');
807+
const source = (v) => {
808+
const text = v.toString();
809+
if (/\\(0,\\s*import_[\\w$]+\\./.test(text)) throw new Error('arrays probe: a function was loaded as CommonJS (its imports are rewritten), so its source is not comparable');
810+
return 'fn:' + text;
811+
};
812+
const digest = (c) => createHash('sha256').update(JSON.stringify(c, (k, v) => (typeof v === 'function' ? source(v) : v))).digest('hex');
808813
const byMajor = {};
809814
for (const k of Object.keys(m.CONVERSIONS_BY_MAJOR)) byMajor[k] = m.CONVERSIONS_BY_MAJOR[k].map((c) => c.id);
810815
process.stdout.write(JSON.stringify({
@@ -839,6 +844,10 @@ function arraysProof(ref) {
839844
try {
840845
const probe = join(scratch, 'probe.mts');
841846
writeFileSync(probe, ARRAYS_PROBE);
847+
// Both trees load as ES modules. Under the spec package's CommonJS default the loader rewrites every
848+
// imported call to `(0, import_x.name)(…)`, so a moved entry's function source would differ only by the
849+
// loader's spelling of its import (measured on #29987: 93 of 112 digests). The probe refuses that spelling.
850+
writeFileSync(join(scratch, 'package.json'), '{"type":"module"}\n');
842851
// Base: this tree's src, with conversions/ exactly as REF has it.
843852
const baseSrc = join(scratch, 'base-src');
844853
cpSync(join(ROOT, SPEC_REL, 'src'), baseSrc, { recursive: true });
@@ -850,7 +859,9 @@ function arraysProof(ref) {
850859
execFileSync('tar', ['-xf', tar, '-C', unpack]);
851860
cpSync(join(unpack, CONV_REL), join(baseSrc, 'conversions'), { recursive: true });
852861
const before = loadTables(join(baseSrc, 'conversions', HOST_BASENAME), probe);
853-
const after = loadTables(HOST_PATH, probe);
862+
const headSrc = join(scratch, 'head-src');
863+
cpSync(join(ROOT, SPEC_REL, 'src'), headSrc, { recursive: true });
864+
const after = loadTables(join(headSrc, 'conversions', HOST_BASENAME), probe);
854865
const failures = compareTables(before, after);
855866
return {
856867
failures,

0 commit comments

Comments
 (0)