From 9df98e65f842cf3acae09cbdd969966f42d64469 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 14 Oct 2017 18:40:54 +0200 Subject: update dependencies --- .../webpack/lib/optimize/CommonsChunkPlugin.js | 53 ++++++++++++------ .../webpack/lib/optimize/ConcatenatedModule.js | 65 +++++++++++----------- .../lib/optimize/EnsureChunkConditionsPlugin.js | 1 + .../lib/optimize/ModuleConcatenationPlugin.js | 1 + 4 files changed, 72 insertions(+), 48 deletions(-) (limited to 'node_modules/webpack/lib/optimize') diff --git a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js index 465b7ff7a..ab7b69f4a 100644 --- a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js +++ b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js @@ -4,6 +4,7 @@ */ "use strict"; let nextIdent = 0; + class CommonsChunkPlugin { constructor(options) { if(arguments.length > 1) { @@ -31,6 +32,7 @@ The available options are: this.minChunks = normalizedOptions.minChunks; this.selectedChunks = normalizedOptions.selectedChunks; this.children = normalizedOptions.children; + this.deepChildren = normalizedOptions.deepChildren; this.async = normalizedOptions.async; this.minSize = normalizedOptions.minSize; this.ident = __filename + (nextIdent++); @@ -76,6 +78,7 @@ You can however specify the name of the async chunk by passing the desired strin minChunks: options.minChunks, selectedChunks: options.chunks, children: options.children, + deepChildren: options.deepChildren, async: options.async, minSize: options.minSize }; @@ -211,6 +214,37 @@ You can however specify the name of the async chunk by passing the desired strin Take a look at the "name"/"names" or async/children option.`); } + getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption) { + let chunks = targetChunk.chunks; + chunks && chunks.forEach((chunk) => { + if(chunk.isInitial()) { + return; + } + // If all the parents of a chunk are either + // a) the target chunk we started with + // b) themselves affected chunks + // we can assume that this chunk is an affected chunk too, as there is no way a chunk that + // isn't only depending on the target chunk is a parent of the chunk tested + if(asyncOption || chunk.parents.every((parentChunk) => parentChunk === targetChunk || affectedChunks.has(parentChunk))) { + // This check not only dedupes the affectedChunks but also guarantees we avoid endless loops + if(!affectedChunks.has(chunk) || affectedChunks.values().next().value === chunk) { + // We mutate the affected chunks before going deeper, so the deeper levels and other branches + // Have the information of this chunk being affected for their assertion if a chunk should + // not be affected + affectedChunks.add(chunk); + + // We recurse down to all the children of the chunk, applying the same assumption. + // This guarantees that if a chunk should be an affected chunk, + // at the latest the last connection to the same chunk meets the + // condition to add it to the affected chunks. + if(this.deepChildren === true) { + this.getAffectedUnnamedChunks(affectedChunks, chunk, asyncOption); + } + } + } + }); + } + getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, children) { const asyncOrNoSelectedChunk = children || asyncOption; @@ -223,22 +257,9 @@ Take a look at the "name"/"names" or async/children option.`); } if(asyncOrNoSelectedChunk) { - // nothing to do here - if(!targetChunk.chunks) { - return []; - } - - return targetChunk.chunks.filter((chunk) => { - // we only are interested in on-demand chunks - if(chunk.isInitial()) - return false; - - // we can only move modules from this chunk if the "commonChunk" is the only parent - if(!asyncOption) - return chunk.parents.length === 1; - - return true; - }); + let affectedChunks = new Set(); + this.getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption); + return Array.from(affectedChunks); } /** diff --git a/node_modules/webpack/lib/optimize/ConcatenatedModule.js b/node_modules/webpack/lib/optimize/ConcatenatedModule.js index 6cb503f0d..8b201009a 100644 --- a/node_modules/webpack/lib/optimize/ConcatenatedModule.js +++ b/node_modules/webpack/lib/optimize/ConcatenatedModule.js @@ -17,7 +17,6 @@ const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportS const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency"); const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency"); const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency"); -const HarmonyModulesHelpers = require("../dependencies/HarmonyModulesHelpers"); function ensureNsObjSource(info, moduleToInfoMap, requestShortener) { if(!info.hasNamespaceObject) { @@ -172,7 +171,7 @@ class ConcatenatedModule extends Module { this.built = modules.some(m => m.built); this.cacheable = modules.every(m => m.cacheable); const modulesSet = new Set(modules); - this.reasons = rootModule.reasons.filter(reason => !modulesSet.has(reason.module)); + this.reasons = rootModule.reasons.filter(reason => !(reason.dependency instanceof HarmonyImportDependency) || !modulesSet.has(reason.module)); this.meta = rootModule.meta; this.moduleArgument = rootModule.moduleArgument; this.exportsArgument = rootModule.exportsArgument; @@ -193,7 +192,7 @@ class ConcatenatedModule extends Module { const m = info.module; // populate dependencies - m.dependencies.filter(dep => !modulesSet.has(dep.module)) + m.dependencies.filter(dep => !(dep instanceof HarmonyImportDependency) || !modulesSet.has(dep.module)) .forEach(d => this.dependencies.push(d)); // populate dep warning m.dependenciesWarnings.forEach(depWarning => this.dependenciesWarnings.push(depWarning)); @@ -308,35 +307,42 @@ class ConcatenatedModule extends Module { const reexportMap = new Map(); info.module.dependencies.forEach(dep => { if(dep instanceof HarmonyExportSpecifierDependency) { - exportMap.set(dep.name, dep.id); + if(!exportMap.has(dep.name)) + exportMap.set(dep.name, dep.id); } else if(dep instanceof HarmonyExportExpressionDependency) { - exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__"); + if(!exportMap.has("default")) + exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__"); } else if(dep instanceof HarmonyExportImportedSpecifierDependency) { const exportName = dep.name; const importName = dep.id; const importedModule = dep.importDependency.module; if(exportName && importName) { - reexportMap.set(exportName, { - module: importedModule, - exportName: importName, - dependency: dep - }); + if(!reexportMap.has(exportName)) { + reexportMap.set(exportName, { + module: importedModule, + exportName: importName, + dependency: dep + }); + } } else if(exportName) { - reexportMap.set(exportName, { - module: importedModule, - exportName: true, - dependency: dep - }); - } else { - var activeExports = new Set(HarmonyModulesHelpers.getActiveExports(dep.originModule, dep)); - importedModule.providedExports.forEach(name => { - if(activeExports.has(name) || name === "default") - return; - reexportMap.set(name, { + if(!reexportMap.has(exportName)) { + reexportMap.set(exportName, { module: importedModule, - exportName: name, + exportName: true, dependency: dep }); + } + } else if(importedModule) { + importedModule.providedExports.forEach(name => { + if(dep.activeExports.has(name) || name === "default") + return; + if(!reexportMap.has(name)) { + reexportMap.set(name, { + module: importedModule, + exportName: name, + dependency: dep + }); + } }); } } @@ -352,7 +358,6 @@ class ConcatenatedModule extends Module { internalNames: new Map(), exportMap: exportMap, reexportMap: reexportMap, - needCompatibilityFlag: false, hasNamespaceObject: false, namespaceObjectSource: null }; @@ -451,7 +456,7 @@ class ConcatenatedModule extends Module { const allUsedNames = new Set([ "__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name - "abstract", "arguments", "await", "boolean", "break", "byte", "case", "catch", "char", "class", + "abstract", "arguments", "async", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", @@ -576,7 +581,8 @@ class ConcatenatedModule extends Module { const result = new ConcatSource(); // add harmony compatibility flag (must be first because of possible circular dependencies) - if(moduleToInfoMap.get(this.rootModule).needCompatibilityFlag) { + const usedExports = this.rootModule.usedExports; + if(usedExports === true) { result.add(`Object.defineProperty(${this.exportsArgument || "exports"}, "__esModule", { value: true });\n`); } @@ -741,8 +747,6 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate { } getExports(dep) { - const active = HarmonyModulesHelpers.isActive(dep.originModule, dep); - if(!active) return []; const importModule = dep.importDependency.module; if(dep.id) { // export { named } from "module" @@ -761,8 +765,7 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate { }]; } // export * from "module" - const activeExports = new Set(HarmonyModulesHelpers.getActiveExports(dep.originModule, dep)); - return importModule.providedExports.filter(exp => exp !== "default" && !activeExports.has(exp)).map(exp => { + return importModule.providedExports.filter(exp => exp !== "default" && !dep.activeExports.has(exp)).map(exp => { return { name: exp, id: exp, @@ -807,9 +810,7 @@ class HarmonyCompatibilityDependencyConcatenatedTemplate { } apply(dep, source, outputOptions, requestShortener, dependencyTemplates) { - if(dep.originModule === this.rootModule) { - this.modulesMap.get(this.rootModule).needCompatibilityFlag = true; - } + // do nothing } } diff --git a/node_modules/webpack/lib/optimize/EnsureChunkConditionsPlugin.js b/node_modules/webpack/lib/optimize/EnsureChunkConditionsPlugin.js index 46324c4e9..2b291fdad 100644 --- a/node_modules/webpack/lib/optimize/EnsureChunkConditionsPlugin.js +++ b/node_modules/webpack/lib/optimize/EnsureChunkConditionsPlugin.js @@ -22,6 +22,7 @@ class EnsureChunkConditionsPlugin { chunk.parents.forEach((parent) => { if(!usedChunks.has(parent)) { parent.addModule(module); + module.addChunk(parent); newChunks.push(parent); } }); diff --git a/node_modules/webpack/lib/optimize/ModuleConcatenationPlugin.js b/node_modules/webpack/lib/optimize/ModuleConcatenationPlugin.js index 9e797c75e..8a6a660cb 100644 --- a/node_modules/webpack/lib/optimize/ModuleConcatenationPlugin.js +++ b/node_modules/webpack/lib/optimize/ModuleConcatenationPlugin.js @@ -163,6 +163,7 @@ class ModuleConcatenationPlugin { } chunks.forEach(chunk => { chunk.addModule(newModule); + newModule.addChunk(chunk); if(chunk.entryModule === concatConfiguration.rootModule) chunk.entryModule = newModule; }); -- cgit v1.2.3