From 01f5600caadfe97df899fe29ae58594475eb2ed2 Mon Sep 17 00:00:00 2001 From: Robin Schreiber Date: Mon, 29 Jul 2024 13:48:47 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9D=84=EF=B8=8F:=20properly=20exclude=20modu?= =?UTF-8?q?les=20in=20freezer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the exclusion mechanism would mostly just declare excluded modules as externs, which would not really shim the missing exports. This new mechanism just returns empty source strings for excluded modules, which leverages the module shimming in rollup.js --- lively.freezer/src/bundler.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lively.freezer/src/bundler.js b/lively.freezer/src/bundler.js index 4c9d804bce..78e235862b 100644 --- a/lively.freezer/src/bundler.js +++ b/lively.freezer/src/bundler.js @@ -397,7 +397,7 @@ export default class LivelyRollup { */ async transform (source, id) { const originalSource = source; - if (id.startsWith('\0') || id.endsWith('.json')) { + if (id.startsWith('\0') || id.endsWith('.json') || this.excludedModules.find(m => id.startsWith(m))) { return source; } // We use the string 'projectAsset' there in regular code to enable correct reconciliation. @@ -467,6 +467,7 @@ export default class LivelyRollup { if (!mapping[id] && this.globalMap[id]) { console.warn(`[freezer] No mapping for "${id}" provided by package "${importingPackage.name}". Guessing "${this.globalMap[id]}" based on past resolutions. Please consider adding a map entry to this package config in oder to make the package definition sound and work independently of the current setup!`); // eslint-disable-line no-console } + if (this.excludedModules.includes(id)) return id; let remapped = mapping[id] || this.globalMap[id]; const ctx = this.asBrowserModule ? '~node' : 'node'; if (remapped[ctx]) remapped = remapped[ctx]; @@ -490,7 +491,7 @@ export default class LivelyRollup { // results since we are not taking into account in package.json absolutePath = this.resolver.resolveModuleId(id, importer, this.getResolutionContext()); - if (this.belongsToExcludedPackage(absolutePath)) return null; + if (this.belongsToExcludedPackage(absolutePath)) return id; return this.resolved[resolutionId(id, importer)] = absolutePath; } @@ -529,7 +530,7 @@ export default class LivelyRollup { * @returns { string } The source code. */ async load (id) { - if (this.excludedModules.includes(id)) { + if (this.excludedModules.find(m => id.startsWith(m))) { if (id === 'lively.ast') { return ` let nodes = {}, query = {}, transform = {}, BaseVisitor = Object; @@ -540,6 +541,7 @@ export default class LivelyRollup { let scripting = {}; export { scripting };`; } + return ''; } if (id === ROOT_ID) {