Skip to content

Commit

Permalink
❄️: fix finternal file-registration mapping in revivable bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
merryman authored and linusha committed Aug 1, 2024
1 parent c075f92 commit e920616
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lively.freezer/src/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,9 @@ export default class LivelyRollup {
const modules = Object.values(bundle);
modules.forEach(chunk => {
if (chunk.code) {
if (this.isResurrectionBuild) chunk.code = chunk.code.replace('System.register', 'BootstrapSystem.register');
if (this.isResurrectionBuild) {
chunk.code = chunk.code.replace('System.register', `BootstrapSystem._currentFile = "${chunk.fileName}";\nBootstrapSystem.register`);
}
chunk.code = chunk.code.replace("'use strict'", "var __contextModule__ = typeof module !== 'undefined' ? module : arguments[1];\n");
}
});
Expand Down
15 changes: 7 additions & 8 deletions lively.freezer/src/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,23 @@ export function instrumentStaticSystemJS (system) {
if (typeof name !== 'string') {
def = deps;
deps = name;
res = _originalRegister(deps, (exports, module) => {
let registerFn = (exports, module) => {
let res = def(exports, module);
if (!res.setters) res.setters = [];
return res;
});
const hit = Object.values(system.REGISTER_INTERNAL?.records || {})
.find((rec) => !rec.module && !rec.loadError && !rec.metadata && !rec.registration);
};
res = _originalRegister(deps, registerFn);
const key = system.baseURL + system._currentFile;
// this is not a reliable way to detect the key once we have the module already present
if (hit) { system.moduleRegisters[hit.key] = system.REGISTER_INTERNAL.lastRegister; }
if (!system.moduleRegisters[key]) { system.moduleRegisters[key] = [deps, registerFn]; }
} else {
res = _originalRegister(name, deps, (exports, module) => {
let res = def(exports, module);
if (!res.setters) res.setters = [];
return res;
});
const hit = Object.values(system.REGISTER_INTERNAL?.records || {})
.find((rec) => !rec.module && !rec.loadError && !rec.metadata && !rec.registration);
if (hit) { system.moduleRegisters[hit.key] = system.REGISTER_INTERNAL.lastRegister; }
const key = system.baseURL + system._currentFile;
if (!system.moduleRegisters[key]) { system.moduleRegisters[key] = [name, deps, registerFn]; }
}
return res;
};
Expand Down

0 comments on commit e920616

Please sign in to comment.