From 2437f72cd7fa482891abd99f75d6f06124761971 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 14 Nov 2016 10:25:47 -0500 Subject: [PATCH] Strip unnecessary imports for packages with no modules. Note that even an empty package needs to define Package[name] = {}, so that other packages can tell at runtime whether it's installed. Fixes #7927. --- tools/isobuild/linker.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/isobuild/linker.js b/tools/isobuild/linker.js index 1dbd48ebc2..04d524d618 100644 --- a/tools/isobuild/linker.js +++ b/tools/isobuild/linker.js @@ -1002,6 +1002,21 @@ export var fullLink = Profile("linker.fullLink", function (inputFiles, { return []; } + // If none of the prelinkedFiles contain any code, then the only + // possible purpose of this package is to re-export imported symbols, so + // we filter the set of imported symbols according to declaredExports. + // When there are no declaredExports, this effectively slims the package + // bundle down to just Package[name] = {}. + if (prelinkedFiles.every(file => ! file.source)) { + const newImports = {}; + declaredExports.forEach(name => { + if (_.has(imports, name)) { + newImports[name] = imports[name] + } + }); + imports = newImports; + } + // Otherwise we're making a package and we have to actually combine the files // into a single scope. var header = getHeader({