From e920616481797256b2b6c7c857c3c051b9e948d6 Mon Sep 17 00:00:00 2001 From: Robin Schreiber Date: Wed, 31 Jul 2024 13:48:54 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9D=84=EF=B8=8F:=20fix=20finternal=20file-re?= =?UTF-8?q?gistration=20mapping=20in=20revivable=20bundles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lively.freezer/src/bundler.js | 4 +++- lively.freezer/src/util/helpers.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lively.freezer/src/bundler.js b/lively.freezer/src/bundler.js index 671fb1f7d..14cac6ef3 100644 --- a/lively.freezer/src/bundler.js +++ b/lively.freezer/src/bundler.js @@ -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"); } }); diff --git a/lively.freezer/src/util/helpers.js b/lively.freezer/src/util/helpers.js index 8c453e999..9c5f9ac20 100644 --- a/lively.freezer/src/util/helpers.js +++ b/lively.freezer/src/util/helpers.js @@ -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; };