From f60663ca12ffbcc6a33eb044de80fc699949da25 Mon Sep 17 00:00:00 2001 From: zodern Date: Fri, 27 Jan 2023 17:07:03 -0600 Subject: [PATCH] Fix handling implied packages in linker --- tools/isobuild/compiler-plugin.js | 12 +++++++++--- tools/isobuild/linker.js | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index 4ae0213777..a14c5e79b6 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -1071,6 +1071,8 @@ export class PackageSourceBatch { // decision of whether or not an unrelated package in the target // depends on something). self.importedSymbolToPackageName = {}; // map from symbol to supplying package name + + self.deps = []; } async init() { @@ -1093,13 +1095,17 @@ export class PackageSourceBatch { skipDebugOnly: true, skipProdOnly: true, skipTestOnly: true, - }, depUnibuild => { + }, (depUnibuild, { weak, unordered }) => { + let packageName = depUnibuild.pkg.name; + _.each(depUnibuild.declaredExports, function (symbol) { // Slightly hacky implementation of test-only exports. if (! symbol.testOnly || self.unibuild.pkg.isTest) { - self.importedSymbolToPackageName[symbol.name] = depUnibuild.pkg.name; + self.importedSymbolToPackageName[symbol.name] = packageName; } }); + + self.deps.push({ package: packageName, weak, unordered }); }); self.useMeteorInstall = @@ -1694,7 +1700,7 @@ export class PackageSourceBatch { imports: self.importedSymbolToPackageName, // XXX report an error if there is a package called global-imports includeSourceMapInstructions: isWeb, - uses: self.unibuild.uses + deps: self.deps }; const fileHashes = []; diff --git a/tools/isobuild/linker.js b/tools/isobuild/linker.js index 3a2700f2a5..573e990210 100644 --- a/tools/isobuild/linker.js +++ b/tools/isobuild/linker.js @@ -941,16 +941,17 @@ var getHeader = function (options) { var isApp = options.name === null; var chunks = []; - let deps = []; - options.uses.forEach(uses => { - if (!uses.unordered) { - deps.push(JSON.stringify(uses.package)) + let orderedDeps = []; + + options.deps.forEach(dep => { + if (!dep.unordered) { + orderedDeps.push(JSON.stringify(dep.package)) } }); chunks.push( `Package["core-runtime"].queue("${options.name}", [`, - deps.join(', '), + orderedDeps.join(', '), '], function () {' ); @@ -1139,8 +1140,9 @@ export var fullLink = Profile("linker.fullLink", async function (inputFiles, { // how to use them in a browser. includeSourceMapInstructions, - // List of packages this bundle uses - uses + // List of packages this bundle directly uses, or is implied by the packages + // it uses + deps }) { buildmessage.assertInJob(); @@ -1157,7 +1159,7 @@ export var fullLink = Profile("linker.fullLink", async function (inputFiles, { // we can be sure the runtime will be available // The main situations it is not available is the core-runtime // package itself, or any build plugins with no dependencies - let hasRuntime = uses.some(entry => entry.unordered !== true); + let hasRuntime = deps.some(entry => entry.unordered !== true); _.each(inputFiles, file => module.addFile(file)); @@ -1192,7 +1194,7 @@ export var fullLink = Profile("linker.fullLink", async function (inputFiles, { imports, packageVariables: [], hasRuntime, - uses + deps }); let footer = getFooter({ name: null, @@ -1253,7 +1255,7 @@ export var fullLink = Profile("linker.fullLink", async function (inputFiles, { imports, packageVariables: _.union(assignedVariables, declaredExports), hasRuntime, - uses + deps }); var footer = getFooter({