From 56c041c8582cedb8650028fa1ed45540edd1d955 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 13 Oct 2016 18:33:36 -0400 Subject: [PATCH] Filter out node_modules/babel-runtime/* when Meteor provides babel-runtime. Should fix #7872 and others (e.g. #7833). --- tools/isobuild/compiler-plugin.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index 844f399fba..456d3ab72d 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -1088,14 +1088,38 @@ export class PackageSourceBatch { this._warnAboutMissingModules(allMissingNodeModules); + const meteorProvidesBabelRuntime = map.has("babel-runtime"); + scannerMap.forEach((scanner, name) => { const isApp = ! name; + const isWeb = scanner.isWeb(); + const outputFiles = scanner.getOutputFiles(); if (isApp) { const appFilesWithoutNodeModules = []; - scanner.getOutputFiles().forEach(file => { + outputFiles.forEach(file => { const parts = file.installPath.split("/"); + + if (meteorProvidesBabelRuntime || ! isWeb) { + // If the Meteor babel-runtime package is installed, it will + // provide implementations for babel-runtime/helpers/* and + // babel-runtime/regenerator at runtime, so we should filter + // out any node_modules/babel-runtime/* modules from the app. + // If the Meteor babel-runtime package is not installed, then + // we should rely on node_modules/babel-runtime/* instead. On + // the server that still means removing bundled files here and + // relying on programs/server/npm/node_modules/babel-runtime, + // but on the web these bundled files are all we have, so we'd + // better not remove them. + if (parts[0] === "node_modules" && + parts[1] === "babel-runtime" && + // Can't just be node_modules/babel-runtime. + parts.length > 2) { + return; + } + } + const nodeModulesIndex = parts.indexOf("node_modules"); if (nodeModulesIndex === -1 || (nodeModulesIndex === 0 && @@ -1118,7 +1142,7 @@ export class PackageSourceBatch { map.get(null).files = appFilesWithoutNodeModules; } else { - map.get(name).files = scanner.getOutputFiles(); + map.get(name).files = outputFiles; } });