fix(replay): link the complete ESM graph before evaluating (#515)

* fix(replay): link the complete ESM graph before evaluating

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* fix(replay): rename shadowed module bindings in ESM link graph

---------

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-05 15:03:59 +08:00
committed by GitHub
co-authored by morluto
parent 9975bd23cd
commit 4200a425d5
2 changed files with 148 additions and 9 deletions
+14 -9
View File
@@ -213,7 +213,7 @@ const loadEntry = async (
return module.exports;
};
const loadEsm = async (alias: string): Promise<Module> => {
const loadEsm = (alias: string): Module => {
const cached = esmCache.get(alias);
if (cached !== undefined) return cached;
const descriptor = requiredModule(modules, alias);
@@ -245,13 +245,6 @@ const loadEntry = async (
});
}
esmCache.set(alias, module);
await module.link(async (specifier) => {
const dependency = descriptor.dependencies[specifier];
if (dependency === undefined)
throw new ReplayDeniedError(`Undeclared import: ${specifier}`);
return loadEsm(dependency);
});
await module.evaluate();
return module;
};
@@ -262,7 +255,19 @@ const loadEntry = async (
? (exported.default ?? exported)
: exported[side.entryExport];
}
const namespace = (await loadEsm(side.entryAlias)).namespace;
const entryModule = loadEsm(side.entryAlias);
await entryModule.link((specifier, referencingModule) => {
const descriptor = requiredModule(
modules,
referencingModule.identifier.slice("rea:".length),
);
const dependency = descriptor.dependencies[specifier];
if (dependency === undefined)
throw new ReplayDeniedError(`Undeclared import: ${specifier}`);
return loadEsm(dependency);
});
await entryModule.evaluate();
const namespace = entryModule.namespace;
return Reflect.get(namespace, side.entryExport);
};