From 9df98e65f842cf3acae09cbdd969966f42d64469 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 14 Oct 2017 18:40:54 +0200 Subject: update dependencies --- node_modules/webpack/lib/CachePlugin.js | 34 +- node_modules/webpack/lib/Compilation.js | 191 +++- node_modules/webpack/lib/Compiler.js | 1052 ++++++++++---------- node_modules/webpack/lib/ContextExclusionPlugin.js | 17 + node_modules/webpack/lib/ContextModuleFactory.js | 9 +- node_modules/webpack/lib/DelegatedModule.js | 190 ++-- node_modules/webpack/lib/ExternalModule.js | 7 + .../webpack/lib/FunctionModuleTemplatePlugin.js | 10 +- .../webpack/lib/HotModuleReplacement.runtime.js | 3 +- .../webpack/lib/JsonpMainTemplate.runtime.js | 3 +- .../webpack/lib/JsonpMainTemplatePlugin.js | 2 + node_modules/webpack/lib/Module.js | 2 + node_modules/webpack/lib/NormalModule.js | 11 +- node_modules/webpack/lib/OptionsDefaulter.js | 2 + node_modules/webpack/lib/Parser.js | 99 +- node_modules/webpack/lib/SourceMapDevToolPlugin.js | 6 +- node_modules/webpack/lib/Template.js | 38 +- node_modules/webpack/lib/UmdMainTemplatePlugin.js | 2 +- .../webpack/lib/WebpackOptionsDefaulter.js | 244 ++--- .../AMDDefineDependencyParserPlugin.js | 6 +- .../lib/dependencies/AMDRequireArrayDependency.js | 2 + .../dependencies/AMDRequireContextDependency.js | 9 - .../CommonJsRequireContextDependency.js | 10 - .../webpack/lib/dependencies/ContextDependency.js | 20 + .../HarmonyExportDependencyParserPlugin.js | 16 +- .../HarmonyExportExpressionDependency.js | 7 - .../HarmonyExportImportedSpecifierDependency.js | 111 +-- .../HarmonyExportSpecifierDependency.js | 13 - .../HarmonyImportDependencyParserPlugin.js | 3 + .../lib/dependencies/HarmonyModulesHelpers.js | 53 - .../lib/dependencies/ImportContextDependency.js | 10 - .../RequireResolveContextDependency.js | 10 - .../webpack/lib/optimize/CommonsChunkPlugin.js | 53 +- .../webpack/lib/optimize/ConcatenatedModule.js | 65 +- .../lib/optimize/EnsureChunkConditionsPlugin.js | 1 + .../lib/optimize/ModuleConcatenationPlugin.js | 1 + node_modules/webpack/lib/webpack.js | 2 + 37 files changed, 1238 insertions(+), 1076 deletions(-) create mode 100644 node_modules/webpack/lib/ContextExclusionPlugin.js (limited to 'node_modules/webpack/lib') diff --git a/node_modules/webpack/lib/CachePlugin.js b/node_modules/webpack/lib/CachePlugin.js index 1b8d6a30e..9c19b8140 100644 --- a/node_modules/webpack/lib/CachePlugin.js +++ b/node_modules/webpack/lib/CachePlugin.js @@ -18,15 +18,31 @@ class CachePlugin { c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {})); }); } else { - compiler.plugin("compilation", compilation => { - if(!compilation.notCacheable) { - compilation.cache = this.cache; - } else if(this.watching) { - compilation.warnings.push( - new Error(`CachePlugin - Cache cannot be used because of: ${compilation.notCacheable}`) - ); - } - }); + const registerCacheToCompiler = (compiler, cache) => { + compiler.plugin("this-compilation", compilation => { + // TODO remove notCacheable for webpack 4 + if(!compilation.notCacheable) { + compilation.cache = cache; + compilation.plugin("child-compiler", (childCompiler, compilerName, compilerIndex) => { + if(cache) { + let childCache; + if(!cache.children) cache.children = {}; + if(!cache.children[compilerName]) cache.children[compilerName] = []; + if(cache.children[compilerName][compilerIndex]) + childCache = cache.children[compilerName][compilerIndex]; + else + cache.children[compilerName].push(childCache = {}); + registerCacheToCompiler(childCompiler, childCache); + } + }); + } else if(this.watching) { + compilation.warnings.push( + new Error(`CachePlugin - Cache cannot be used because of: ${compilation.notCacheable}`) + ); + } + }); + }; + registerCacheToCompiler(compiler, this.cache); compiler.plugin("watch-run", (compiler, callback) => { this.watching = true; callback(); diff --git a/node_modules/webpack/lib/Compilation.js b/node_modules/webpack/lib/Compilation.js index b59c0eb53..72b195745 100644 --- a/node_modules/webpack/lib/Compilation.js +++ b/node_modules/webpack/lib/Compilation.js @@ -232,7 +232,10 @@ class Compilation extends Tapable { callback(); }; - _this.semaphore.acquire(() => { + const semaphore = _this.semaphore; + semaphore.acquire(() => { + if(_this === null) return semaphore.release(); + const factory = item[0]; factory.create({ contextInfo: { @@ -242,6 +245,8 @@ class Compilation extends Tapable { context: module.context, dependencies: dependencies }, function factoryCallback(err, dependentModule) { + if(_this === null) return semaphore.release(); + let afterFactory; function isOptional() { @@ -265,11 +270,11 @@ class Compilation extends Tapable { } if(err) { - _this.semaphore.release(); + semaphore.release(); return errorOrWarningAndCallback(new ModuleNotFoundError(module, err, dependencies)); } if(!dependentModule) { - _this.semaphore.release(); + semaphore.release(); return process.nextTick(callback); } if(_this.profile) { @@ -302,7 +307,7 @@ class Compilation extends Tapable { } } - _this.semaphore.release(); + semaphore.release(); return process.nextTick(callback); } @@ -322,7 +327,7 @@ class Compilation extends Tapable { module.profile.building = afterBuilding - afterFactory; } - _this.semaphore.release(); + semaphore.release(); if(recursive) { return process.nextTick(_this.processModuleDependencies.bind(_this, dependentModule, callback)); } else { @@ -335,8 +340,10 @@ class Compilation extends Tapable { iterationDependencies(dependencies); _this.buildModule(dependentModule, isOptional(), module, dependencies, err => { + if(_this === null) return semaphore.release(); + if(err) { - _this.semaphore.release(); + semaphore.release(); return errorOrWarningAndCallback(err); } @@ -345,7 +352,7 @@ class Compilation extends Tapable { dependentModule.profile.building = afterBuilding - afterFactory; } - _this.semaphore.release(); + semaphore.release(); if(recursive) { _this.processModuleDependencies(dependentModule, callback); } else { @@ -578,8 +585,8 @@ class Compilation extends Tapable { chunk.entryModule = module; self.assignIndex(module); self.assignDepth(module); - self.processDependenciesBlockForChunk(module, chunk); }); + self.processDependenciesBlocksForChunks(self.chunks.slice()); self.sortModules(self.modules); self.applyPlugins0("optimize"); @@ -846,62 +853,90 @@ class Compilation extends Tapable { } } - processDependenciesBlockForChunk(module, chunk) { - let block = module; - const initialChunk = chunk; + // This method creates the Chunk graph from the Module graph + processDependenciesBlocksForChunks(inputChunks) { + // Process is splitting into two parts: + // Part one traverse the module graph and builds a very basic chunks graph + // in chunkDependencies. + // Part two traverse every possible way through the basic chunk graph and + // tracks the available modules. While traversing it connects chunks with + // eachother and Blocks with Chunks. It stops traversing when all modules + // for a chunk are already available. So it doesn't connect unneeded chunks. + const chunkDependencies = new Map(); // Map> + const allCreatedChunks = new Set(); + + // PART ONE + const blockChunks = new Map(); + + // Start with the provided modules/chunks + const queue = inputChunks.map(chunk => ({ + block: chunk.entryModule, + chunk: chunk + })); + + let block, chunk; + + // For each async Block in graph const iteratorBlock = b => { - let c; - if(!b.chunks) { + // 1. We create a chunk for this Block + // but only once (blockChunks map) + let c = blockChunks.get(b); + if(c === undefined) { c = this.addChunk(b.chunkName, b.module, b.loc); - b.chunks = [c]; - c.addBlock(b); - } else { - c = b.chunks[0]; + blockChunks.set(b, c); + allCreatedChunks.add(c); + // We initialize the chunks property + // this is later filled with the chunk when needed + b.chunks = []; } + + // 2. We store the Block+Chunk mapping as dependency for the chunk let deps = chunkDependencies.get(chunk); if(!deps) chunkDependencies.set(chunk, deps = []); deps.push({ - chunk: c, - module + block: b, + chunk: c }); + + // 3. We enqueue the DependenciesBlock for traversal queue.push({ block: b, - module: null, chunk: c }); }; + // For each Dependency in the graph const iteratorDependency = d => { + // We skip Dependencies without Module pointer if(!d.module) { return; } + // We skip weak Dependencies if(d.weak) { return; } + // We connect Module and Chunk when not already done if(chunk.addModule(d.module)) { d.module.addChunk(chunk); + + // And enqueue the Module for traversal queue.push({ block: d.module, - module: d.module, chunk }); } }; - const queue = [{ - block, - module, - chunk - }]; - + // Iterative traversal of the Module graph + // Recursive would be simpler to write but could result in Stack Overflows while(queue.length) { const queueItem = queue.pop(); block = queueItem.block; - module = queueItem.module; chunk = queueItem.chunk; + // Traverse all variables, Dependencies and Blocks if(block.variables) { iterationBlockVariable(block.variables, iteratorDependency); } @@ -915,46 +950,108 @@ class Compilation extends Tapable { } } - chunk = initialChunk; - let chunks = new Set(); - const queue2 = [{ + // PART TWO + + let availableModules; + let newAvailableModules; + const queue2 = inputChunks.map(chunk => ({ chunk, - chunks - }]; + availableModules: new Set() + })); - const filterFn = dep => { - if(chunks.has(dep.chunk)) return false; - for(const chunk of chunks) { - if(chunk.containsModule(dep.module)) + // Helper function to check if all modules of a chunk are available + const areModulesAvailable = (chunk, availableModules) => { + for(const module of chunk.modulesIterable) { + if(!availableModules.has(module)) return false; } return true; }; + // For each edge in the basic chunk graph + const filterFn = dep => { + // Filter egdes that are not needed because all modules are already available + // This also filters circular dependencies in the chunks graph + const depChunk = dep.chunk; + if(areModulesAvailable(depChunk, newAvailableModules)) + return false; // break all modules are already available + return true; + }; + + const minAvailableModulesMap = new Map(); + + // Iterative traversing of the basic chunk graph while(queue2.length) { const queueItem = queue2.pop(); chunk = queueItem.chunk; - chunks = queueItem.chunks; + availableModules = queueItem.availableModules; + + // 1. Get minimal available modules + // It doesn't make sense to traverse a chunk again with more available modules. + // This step calculates the minimal available modules and skips traversal when + // the list didn't shrink. + let minAvailableModules = minAvailableModulesMap.get(chunk); + if(minAvailableModules === undefined) { + minAvailableModulesMap.set(chunk, new Set(availableModules)); + } else { + let deletedModules = false; + for(const m of minAvailableModules) { + if(!availableModules.has(m)) { + minAvailableModules.delete(m); + deletedModules = true; + } + } + if(!deletedModules) + continue; + } + // 2. Get the edges at this point of the graph const deps = chunkDependencies.get(chunk); if(!deps) continue; + if(deps.length === 0) continue; - const depsFiltered = deps.filter(filterFn); + // 3. Create a new Set of available modules at this points + newAvailableModules = new Set(availableModules); + for(const m of chunk.modulesIterable) + newAvailableModules.add(m); - for(let i = 0; i < depsFiltered.length; i++) { - const dep = depsFiltered[i]; + // 4. Filter edges with available modules + const filteredDeps = deps.filter(filterFn); + + // 5. Foreach remaining edge + const nextChunks = new Set(); + for(let i = 0; i < filteredDeps.length; i++) { + const dep = filteredDeps[i]; const depChunk = dep.chunk; - chunk.addChunk(depChunk); - depChunk.addParent(chunk); + const depBlock = dep.block; + + // 6. Connnect block with chunk + if(depChunk.addBlock(depBlock)) { + depBlock.chunks.push(depChunk); + } + + // 7. Connect chunk with parent + if(chunk.addChunk(depChunk)) { + depChunk.addParent(chunk); + } - const newChunks = depsFiltered.length > 1 ? new Set(chunks) : chunks; - newChunks.add(chunk); + nextChunks.add(depChunk); + } + + // 8. Enqueue further traversal + for(const nextChunk of nextChunks) { queue2.push({ - chunk: depChunk, - chunks: newChunks + chunk: nextChunk, + availableModules: newAvailableModules }); } } + + // Remove all unconnected chunks + for(const chunk of allCreatedChunks) { + if(chunk.parents.length === 0) + chunk.remove("unconnected"); + } } removeChunkFromDependencies(block, chunk) { diff --git a/node_modules/webpack/lib/Compiler.js b/node_modules/webpack/lib/Compiler.js index 8e3118a8c..943ae48a6 100644 --- a/node_modules/webpack/lib/Compiler.js +++ b/node_modules/webpack/lib/Compiler.js @@ -1,529 +1,523 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -"use strict"; - -const path = require("path"); -const Tapable = require("tapable"); - -const Compilation = require("./Compilation"); -const Stats = require("./Stats"); -const NormalModuleFactory = require("./NormalModuleFactory"); -const ContextModuleFactory = require("./ContextModuleFactory"); - -const makePathsRelative = require("./util/identifier").makePathsRelative; - -class Watching { - constructor(compiler, watchOptions, handler) { - this.startTime = null; - this.invalid = false; - this.handler = handler; - this.callbacks = []; - this.closed = false; - if(typeof watchOptions === "number") { - this.watchOptions = { - aggregateTimeout: watchOptions - }; - } else if(watchOptions && typeof watchOptions === "object") { - this.watchOptions = Object.assign({}, watchOptions); - } else { - this.watchOptions = {}; - } - this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200; - this.compiler = compiler; - this.running = true; - this.compiler.readRecords(err => { - if(err) return this._done(err); - - this._go(); - }); - } - - _go() { - this.startTime = Date.now(); - this.running = true; - this.invalid = false; - this.compiler.applyPluginsAsync("watch-run", this, err => { - if(err) return this._done(err); - const onCompiled = (err, compilation) => { - if(err) return this._done(err); - if(this.invalid) return this._done(); - - if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) { - return this._done(null, compilation); - } - - this.compiler.emitAssets(compilation, err => { - if(err) return this._done(err); - if(this.invalid) return this._done(); - - this.compiler.emitRecords(err => { - if(err) return this._done(err); - - if(compilation.applyPluginsBailResult("need-additional-pass")) { - compilation.needAdditionalPass = true; - - const stats = new Stats(compilation); - stats.startTime = this.startTime; - stats.endTime = Date.now(); - this.compiler.applyPlugins("done", stats); - - this.compiler.applyPluginsAsync("additional-pass", err => { - if(err) return this._done(err); - this.compiler.compile(onCompiled); - }); - return; - } - return this._done(null, compilation); - }); - }); - }; - this.compiler.compile(onCompiled); - }); - } - - _getStats(compilation) { - const stats = new Stats(compilation); - stats.startTime = this.startTime; - stats.endTime = Date.now(); - return stats; - } - - _done(err, compilation) { - this.running = false; - if(this.invalid) return this._go(); - - const stats = compilation ? this._getStats(compilation) : null; - if(err) { - this.compiler.applyPlugins("failed", err); - this.handler(err, stats); - return; - } - - this.compiler.applyPlugins("done", stats); - this.handler(null, stats); - if(!this.closed) { - this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies); - } - this.callbacks.forEach(cb => cb()); - this.callbacks.length = 0; - } - - watch(files, dirs, missing) { - this.pausedWatcher = null; - this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, (err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) => { - this.pausedWatcher = this.watcher; - this.watcher = null; - if(err) return this.handler(err); - - this.compiler.fileTimestamps = fileTimestamps; - this.compiler.contextTimestamps = contextTimestamps; - this.invalidate(); - }, (fileName, changeTime) => { - this.compiler.applyPlugins("invalid", fileName, changeTime); - }); - } - - invalidate(callback) { - if(callback) { - this.callbacks.push(callback); - } - if(this.watcher) { - this.pausedWatcher = this.watcher; - this.watcher.pause(); - this.watcher = null; - } - if(this.running) { - this.invalid = true; - return false; - } else { - this._go(); - } - } - - close(callback) { - if(callback === undefined) callback = function() {}; - - this.closed = true; - if(this.watcher) { - this.watcher.close(); - this.watcher = null; - } - if(this.pausedWatcher) { - this.pausedWatcher.close(); - this.pausedWatcher = null; - } - if(this.running) { - this.invalid = true; - this._done = () => { - this.compiler.applyPlugins("watch-close"); - callback(); - }; - } else { - this.compiler.applyPlugins("watch-close"); - callback(); - } - } -} - -class Compiler extends Tapable { - constructor() { - super(); - this.outputPath = ""; - this.outputFileSystem = null; - this.inputFileSystem = null; - - this.recordsInputPath = null; - this.recordsOutputPath = null; - this.records = {}; - - this.fileTimestamps = {}; - this.contextTimestamps = {}; - - this.resolvers = { - normal: null, - loader: null, - context: null - }; - let deprecationReported = false; - this.parser = { - plugin: (hook, fn) => { - if(!deprecationReported) { - console.warn("webpack: Using compiler.parser is deprecated.\n" + - "Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " + - "It was called " + new Error().stack.split("\n")[2].trim() + "."); - deprecationReported = true; - } - this.plugin("compilation", (compilation, data) => { - data.normalModuleFactory.plugin("parser", parser => { - parser.plugin(hook, fn); - }); - }); - }, - apply: () => { - const args = arguments; - if(!deprecationReported) { - console.warn("webpack: Using compiler.parser is deprecated.\n" + - "Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " + - "It was called " + new Error().stack.split("\n")[2].trim() + "."); - deprecationReported = true; - } - this.plugin("compilation", (compilation, data) => { - data.normalModuleFactory.plugin("parser", parser => { - parser.apply.apply(parser, args); - }); - }); - } - }; - - this.options = {}; - } - - watch(watchOptions, handler) { - this.fileTimestamps = {}; - this.contextTimestamps = {}; - const watching = new Watching(this, watchOptions, handler); - return watching; - } - - run(callback) { - const startTime = Date.now(); - - const onCompiled = (err, compilation) => { - if(err) return callback(err); - - if(this.applyPluginsBailResult("should-emit", compilation) === false) { - const stats = new Stats(compilation); - stats.startTime = startTime; - stats.endTime = Date.now(); - this.applyPlugins("done", stats); - return callback(null, stats); - } - - this.emitAssets(compilation, err => { - if(err) return callback(err); - - if(compilation.applyPluginsBailResult("need-additional-pass")) { - compilation.needAdditionalPass = true; - - const stats = new Stats(compilation); - stats.startTime = startTime; - stats.endTime = Date.now(); - this.applyPlugins("done", stats); - - this.applyPluginsAsync("additional-pass", err => { - if(err) return callback(err); - this.compile(onCompiled); - }); - return; - } - - this.emitRecords(err => { - if(err) return callback(err); - - const stats = new Stats(compilation); - stats.startTime = startTime; - stats.endTime = Date.now(); - this.applyPlugins("done", stats); - return callback(null, stats); - }); - }); - }; - - this.applyPluginsAsync("before-run", this, err => { - if(err) return callback(err); - - this.applyPluginsAsync("run", this, err => { - if(err) return callback(err); - - this.readRecords(err => { - if(err) return callback(err); - - this.compile(onCompiled); - }); - }); - }); - } - - runAsChild(callback) { - this.compile((err, compilation) => { - if(err) return callback(err); - - this.parentCompilation.children.push(compilation); - Object.keys(compilation.assets).forEach(name => { - this.parentCompilation.assets[name] = compilation.assets[name]; - }); - - const entries = Object.keys(compilation.entrypoints).map(name => { - return compilation.entrypoints[name].chunks; - }).reduce((array, chunks) => { - return array.concat(chunks); - }, []); - - return callback(null, entries, compilation); - }); - } - - purgeInputFileSystem() { - if(this.inputFileSystem && this.inputFileSystem.purge) - this.inputFileSystem.purge(); - } - - emitAssets(compilation, callback) { - let outputPath; - - const emitFiles = (err) => { - if(err) return callback(err); - - require("async").forEach(Object.keys(compilation.assets), (file, callback) => { - - let targetFile = file; - const queryStringIdx = targetFile.indexOf("?"); - if(queryStringIdx >= 0) { - targetFile = targetFile.substr(0, queryStringIdx); - } - - const writeOut = (err) => { - if(err) return callback(err); - const targetPath = this.outputFileSystem.join(outputPath, targetFile); - const source = compilation.assets[file]; - if(source.existsAt === targetPath) { - source.emitted = false; - return callback(); - } - let content = source.source(); - - if(!Buffer.isBuffer(content)) { - content = new Buffer(content, "utf8"); // eslint-disable-line - } - - source.existsAt = targetPath; - source.emitted = true; - this.outputFileSystem.writeFile(targetPath, content, callback); - }; - - if(targetFile.match(/\/|\\/)) { - const dir = path.dirname(targetFile); - this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut); - } else writeOut(); - - }, err => { - if(err) return callback(err); - - afterEmit.call(this); - }); - }; - - this.applyPluginsAsync("emit", compilation, err => { - if(err) return callback(err); - outputPath = compilation.getPath(this.outputPath); - this.outputFileSystem.mkdirp(outputPath, emitFiles); - }); - - function afterEmit() { - this.applyPluginsAsyncSeries1("after-emit", compilation, err => { - if(err) return callback(err); - - return callback(); - }); - } - - } - - emitRecords(callback) { - if(!this.recordsOutputPath) return callback(); - const idx1 = this.recordsOutputPath.lastIndexOf("/"); - const idx2 = this.recordsOutputPath.lastIndexOf("\\"); - let recordsOutputPathDirectory = null; - if(idx1 > idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1); - if(idx1 < idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2); - if(!recordsOutputPathDirectory) return writeFile.call(this); - this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => { - if(err) return callback(err); - writeFile.call(this); - }); - - function writeFile() { - this.outputFileSystem.writeFile(this.recordsOutputPath, JSON.stringify(this.records, undefined, 2), callback); - } - } - - readRecords(callback) { - if(!this.recordsInputPath) { - this.records = {}; - return callback(); - } - this.inputFileSystem.stat(this.recordsInputPath, err => { - // It doesn't exist - // We can ignore this. - if(err) return callback(); - - this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => { - if(err) return callback(err); - - try { - this.records = JSON.parse(content.toString("utf-8")); - } catch(e) { - e.message = "Cannot parse records: " + e.message; - return callback(e); - } - - return callback(); - }); - }); - } - - createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) { - const childCompiler = new Compiler(); - if(Array.isArray(plugins)) { - plugins.forEach(plugin => childCompiler.apply(plugin)); - } - for(const name in this._plugins) { - if(["make", "compile", "emit", "after-emit", "invalid", "done", "this-compilation"].indexOf(name) < 0) - childCompiler._plugins[name] = this._plugins[name].slice(); - } - childCompiler.name = compilerName; - childCompiler.outputPath = this.outputPath; - childCompiler.inputFileSystem = this.inputFileSystem; - childCompiler.outputFileSystem = null; - childCompiler.resolvers = this.resolvers; - childCompiler.fileTimestamps = this.fileTimestamps; - childCompiler.contextTimestamps = this.contextTimestamps; - - const relativeCompilerName = makePathsRelative(this.context, compilerName); - if(!this.records[relativeCompilerName]) this.records[relativeCompilerName] = []; - if(this.records[relativeCompilerName][compilerIndex]) - childCompiler.records = this.records[relativeCompilerName][compilerIndex]; - else - this.records[relativeCompilerName].push(childCompiler.records = {}); - - if(this.cache) { - if(!this.cache.children) this.cache.children = {}; - if(!this.cache.children[compilerName]) this.cache.children[compilerName] = []; - if(this.cache.children[compilerName][compilerIndex]) - childCompiler.cache = this.cache.children[compilerName][compilerIndex]; - else - this.cache.children[compilerName].push(childCompiler.cache = {}); - } - - childCompiler.options = Object.create(this.options); - childCompiler.options.output = Object.create(childCompiler.options.output); - for(const name in outputOptions) { - childCompiler.options.output[name] = outputOptions[name]; - } - childCompiler.parentCompilation = compilation; - return childCompiler; - } - - isChild() { - return !!this.parentCompilation; - } - - createCompilation() { - return new Compilation(this); - } - - newCompilation(params) { - const compilation = this.createCompilation(); - compilation.fileTimestamps = this.fileTimestamps; - compilation.contextTimestamps = this.contextTimestamps; - compilation.name = this.name; - compilation.records = this.records; - compilation.compilationDependencies = params.compilationDependencies; - this.applyPlugins("this-compilation", compilation, params); - this.applyPlugins("compilation", compilation, params); - return compilation; - } - - createNormalModuleFactory() { - const normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.options.module || {}); - this.applyPlugins("normal-module-factory", normalModuleFactory); - return normalModuleFactory; - } - - createContextModuleFactory() { - const contextModuleFactory = new ContextModuleFactory(this.resolvers, this.inputFileSystem); - this.applyPlugins("context-module-factory", contextModuleFactory); - return contextModuleFactory; - } - - newCompilationParams() { - const params = { - normalModuleFactory: this.createNormalModuleFactory(), - contextModuleFactory: this.createContextModuleFactory(), - compilationDependencies: [] - }; - return params; - } - - compile(callback) { - const params = this.newCompilationParams(); - this.applyPluginsAsync("before-compile", params, err => { - if(err) return callback(err); - - this.applyPlugins("compile", params); - - const compilation = this.newCompilation(params); - - this.applyPluginsParallel("make", compilation, err => { - if(err) return callback(err); - - compilation.finish(); - - compilation.seal(err => { - if(err) return callback(err); - - this.applyPluginsAsync("after-compile", compilation, err => { - if(err) return callback(err); - - return callback(null, compilation); - }); - }); - }); - }); - } -} - -Compiler.Watching = Watching; -module.exports = Compiler; +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const path = require("path"); +const Tapable = require("tapable"); + +const Compilation = require("./Compilation"); +const Stats = require("./Stats"); +const NormalModuleFactory = require("./NormalModuleFactory"); +const ContextModuleFactory = require("./ContextModuleFactory"); + +const makePathsRelative = require("./util/identifier").makePathsRelative; + +class Watching { + constructor(compiler, watchOptions, handler) { + this.startTime = null; + this.invalid = false; + this.handler = handler; + this.callbacks = []; + this.closed = false; + if(typeof watchOptions === "number") { + this.watchOptions = { + aggregateTimeout: watchOptions + }; + } else if(watchOptions && typeof watchOptions === "object") { + this.watchOptions = Object.assign({}, watchOptions); + } else { + this.watchOptions = {}; + } + this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200; + this.compiler = compiler; + this.running = true; + this.compiler.readRecords(err => { + if(err) return this._done(err); + + this._go(); + }); + } + + _go() { + this.startTime = Date.now(); + this.running = true; + this.invalid = false; + this.compiler.applyPluginsAsync("watch-run", this, err => { + if(err) return this._done(err); + const onCompiled = (err, compilation) => { + if(err) return this._done(err); + if(this.invalid) return this._done(); + + if(this.compiler.applyPluginsBailResult("should-emit", compilation) === false) { + return this._done(null, compilation); + } + + this.compiler.emitAssets(compilation, err => { + if(err) return this._done(err); + if(this.invalid) return this._done(); + + this.compiler.emitRecords(err => { + if(err) return this._done(err); + + if(compilation.applyPluginsBailResult("need-additional-pass")) { + compilation.needAdditionalPass = true; + + const stats = new Stats(compilation); + stats.startTime = this.startTime; + stats.endTime = Date.now(); + this.compiler.applyPlugins("done", stats); + + this.compiler.applyPluginsAsync("additional-pass", err => { + if(err) return this._done(err); + this.compiler.compile(onCompiled); + }); + return; + } + return this._done(null, compilation); + }); + }); + }; + this.compiler.compile(onCompiled); + }); + } + + _getStats(compilation) { + const stats = new Stats(compilation); + stats.startTime = this.startTime; + stats.endTime = Date.now(); + return stats; + } + + _done(err, compilation) { + this.running = false; + if(this.invalid) return this._go(); + + const stats = compilation ? this._getStats(compilation) : null; + if(err) { + this.compiler.applyPlugins("failed", err); + this.handler(err, stats); + return; + } + + this.compiler.applyPlugins("done", stats); + this.handler(null, stats); + if(!this.closed) { + this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies); + } + this.callbacks.forEach(cb => cb()); + this.callbacks.length = 0; + } + + watch(files, dirs, missing) { + this.pausedWatcher = null; + this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, (err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) => { + this.pausedWatcher = this.watcher; + this.watcher = null; + if(err) return this.handler(err); + + this.compiler.fileTimestamps = fileTimestamps; + this.compiler.contextTimestamps = contextTimestamps; + this.invalidate(); + }, (fileName, changeTime) => { + this.compiler.applyPlugins("invalid", fileName, changeTime); + }); + } + + invalidate(callback) { + if(callback) { + this.callbacks.push(callback); + } + if(this.watcher) { + this.pausedWatcher = this.watcher; + this.watcher.pause(); + this.watcher = null; + } + if(this.running) { + this.invalid = true; + return false; + } else { + this._go(); + } + } + + close(callback) { + if(callback === undefined) callback = function() {}; + + this.closed = true; + if(this.watcher) { + this.watcher.close(); + this.watcher = null; + } + if(this.pausedWatcher) { + this.pausedWatcher.close(); + this.pausedWatcher = null; + } + if(this.running) { + this.invalid = true; + this._done = () => { + this.compiler.applyPlugins("watch-close"); + callback(); + }; + } else { + this.compiler.applyPlugins("watch-close"); + callback(); + } + } +} + +class Compiler extends Tapable { + constructor() { + super(); + this.outputPath = ""; + this.outputFileSystem = null; + this.inputFileSystem = null; + + this.recordsInputPath = null; + this.recordsOutputPath = null; + this.records = {}; + + this.fileTimestamps = {}; + this.contextTimestamps = {}; + + this.resolvers = { + normal: null, + loader: null, + context: null + }; + let deprecationReported = false; + this.parser = { + plugin: (hook, fn) => { + if(!deprecationReported) { + console.warn("webpack: Using compiler.parser is deprecated.\n" + + "Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " + + "It was called " + new Error().stack.split("\n")[2].trim() + "."); + deprecationReported = true; + } + this.plugin("compilation", (compilation, data) => { + data.normalModuleFactory.plugin("parser", parser => { + parser.plugin(hook, fn); + }); + }); + }, + apply: () => { + const args = arguments; + if(!deprecationReported) { + console.warn("webpack: Using compiler.parser is deprecated.\n" + + "Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " + + "It was called " + new Error().stack.split("\n")[2].trim() + "."); + deprecationReported = true; + } + this.plugin("compilation", (compilation, data) => { + data.normalModuleFactory.plugin("parser", parser => { + parser.apply.apply(parser, args); + }); + }); + } + }; + + this.options = {}; + } + + watch(watchOptions, handler) { + this.fileTimestamps = {}; + this.contextTimestamps = {}; + const watching = new Watching(this, watchOptions, handler); + return watching; + } + + run(callback) { + const startTime = Date.now(); + + const onCompiled = (err, compilation) => { + if(err) return callback(err); + + if(this.applyPluginsBailResult("should-emit", compilation) === false) { + const stats = new Stats(compilation); + stats.startTime = startTime; + stats.endTime = Date.now(); + this.applyPlugins("done", stats); + return callback(null, stats); + } + + this.emitAssets(compilation, err => { + if(err) return callback(err); + + if(compilation.applyPluginsBailResult("need-additional-pass")) { + compilation.needAdditionalPass = true; + + const stats = new Stats(compilation); + stats.startTime = startTime; + stats.endTime = Date.now(); + this.applyPlugins("done", stats); + + this.applyPluginsAsync("additional-pass", err => { + if(err) return callback(err); + this.compile(onCompiled); + }); + return; + } + + this.emitRecords(err => { + if(err) return callback(err); + + const stats = new Stats(compilation); + stats.startTime = startTime; + stats.endTime = Date.now(); + this.applyPlugins("done", stats); + return callback(null, stats); + }); + }); + }; + + this.applyPluginsAsync("before-run", this, err => { + if(err) return callback(err); + + this.applyPluginsAsync("run", this, err => { + if(err) return callback(err); + + this.readRecords(err => { + if(err) return callback(err); + + this.compile(onCompiled); + }); + }); + }); + } + + runAsChild(callback) { + this.compile((err, compilation) => { + if(err) return callback(err); + + this.parentCompilation.children.push(compilation); + Object.keys(compilation.assets).forEach(name => { + this.parentCompilation.assets[name] = compilation.assets[name]; + }); + + const entries = Object.keys(compilation.entrypoints).map(name => { + return compilation.entrypoints[name].chunks; + }).reduce((array, chunks) => { + return array.concat(chunks); + }, []); + + return callback(null, entries, compilation); + }); + } + + purgeInputFileSystem() { + if(this.inputFileSystem && this.inputFileSystem.purge) + this.inputFileSystem.purge(); + } + + emitAssets(compilation, callback) { + let outputPath; + + const emitFiles = (err) => { + if(err) return callback(err); + + require("async").forEach(Object.keys(compilation.assets), (file, callback) => { + + let targetFile = file; + const queryStringIdx = targetFile.indexOf("?"); + if(queryStringIdx >= 0) { + targetFile = targetFile.substr(0, queryStringIdx); + } + + const writeOut = (err) => { + if(err) return callback(err); + const targetPath = this.outputFileSystem.join(outputPath, targetFile); + const source = compilation.assets[file]; + if(source.existsAt === targetPath) { + source.emitted = false; + return callback(); + } + let content = source.source(); + + if(!Buffer.isBuffer(content)) { + content = new Buffer(content, "utf8"); // eslint-disable-line + } + + source.existsAt = targetPath; + source.emitted = true; + this.outputFileSystem.writeFile(targetPath, content, callback); + }; + + if(targetFile.match(/\/|\\/)) { + const dir = path.dirname(targetFile); + this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut); + } else writeOut(); + + }, err => { + if(err) return callback(err); + + afterEmit.call(this); + }); + }; + + this.applyPluginsAsync("emit", compilation, err => { + if(err) return callback(err); + outputPath = compilation.getPath(this.outputPath); + this.outputFileSystem.mkdirp(outputPath, emitFiles); + }); + + function afterEmit() { + this.applyPluginsAsyncSeries1("after-emit", compilation, err => { + if(err) return callback(err); + + return callback(); + }); + } + + } + + emitRecords(callback) { + if(!this.recordsOutputPath) return callback(); + const idx1 = this.recordsOutputPath.lastIndexOf("/"); + const idx2 = this.recordsOutputPath.lastIndexOf("\\"); + let recordsOutputPathDirectory = null; + if(idx1 > idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1); + if(idx1 < idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2); + if(!recordsOutputPathDirectory) return writeFile.call(this); + this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => { + if(err) return callback(err); + writeFile.call(this); + }); + + function writeFile() { + this.outputFileSystem.writeFile(this.recordsOutputPath, JSON.stringify(this.records, undefined, 2), callback); + } + } + + readRecords(callback) { + if(!this.recordsInputPath) { + this.records = {}; + return callback(); + } + this.inputFileSystem.stat(this.recordsInputPath, err => { + // It doesn't exist + // We can ignore this. + if(err) return callback(); + + this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => { + if(err) return callback(err); + + try { + this.records = JSON.parse(content.toString("utf-8")); + } catch(e) { + e.message = "Cannot parse records: " + e.message; + return callback(e); + } + + return callback(); + }); + }); + } + + createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) { + const childCompiler = new Compiler(); + if(Array.isArray(plugins)) { + plugins.forEach(plugin => childCompiler.apply(plugin)); + } + for(const name in this._plugins) { + if(["make", "compile", "emit", "after-emit", "invalid", "done", "this-compilation"].indexOf(name) < 0) + childCompiler._plugins[name] = this._plugins[name].slice(); + } + childCompiler.name = compilerName; + childCompiler.outputPath = this.outputPath; + childCompiler.inputFileSystem = this.inputFileSystem; + childCompiler.outputFileSystem = null; + childCompiler.resolvers = this.resolvers; + childCompiler.fileTimestamps = this.fileTimestamps; + childCompiler.contextTimestamps = this.contextTimestamps; + + const relativeCompilerName = makePathsRelative(this.context, compilerName); + if(!this.records[relativeCompilerName]) this.records[relativeCompilerName] = []; + if(this.records[relativeCompilerName][compilerIndex]) + childCompiler.records = this.records[relativeCompilerName][compilerIndex]; + else + this.records[relativeCompilerName].push(childCompiler.records = {}); + + childCompiler.options = Object.create(this.options); + childCompiler.options.output = Object.create(childCompiler.options.output); + for(const name in outputOptions) { + childCompiler.options.output[name] = outputOptions[name]; + } + childCompiler.parentCompilation = compilation; + + compilation.applyPlugins("child-compiler", childCompiler, compilerName, compilerIndex); + + return childCompiler; + } + + isChild() { + return !!this.parentCompilation; + } + + createCompilation() { + return new Compilation(this); + } + + newCompilation(params) { + const compilation = this.createCompilation(); + compilation.fileTimestamps = this.fileTimestamps; + compilation.contextTimestamps = this.contextTimestamps; + compilation.name = this.name; + compilation.records = this.records; + compilation.compilationDependencies = params.compilationDependencies; + this.applyPlugins("this-compilation", compilation, params); + this.applyPlugins("compilation", compilation, params); + return compilation; + } + + createNormalModuleFactory() { + const normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.options.module || {}); + this.applyPlugins("normal-module-factory", normalModuleFactory); + return normalModuleFactory; + } + + createContextModuleFactory() { + const contextModuleFactory = new ContextModuleFactory(this.resolvers, this.inputFileSystem); + this.applyPlugins("context-module-factory", contextModuleFactory); + return contextModuleFactory; + } + + newCompilationParams() { + const params = { + normalModuleFactory: this.createNormalModuleFactory(), + contextModuleFactory: this.createContextModuleFactory(), + compilationDependencies: [] + }; + return params; + } + + compile(callback) { + const params = this.newCompilationParams(); + this.applyPluginsAsync("before-compile", params, err => { + if(err) return callback(err); + + this.applyPlugins("compile", params); + + const compilation = this.newCompilation(params); + + this.applyPluginsParallel("make", compilation, err => { + if(err) return callback(err); + + compilation.finish(); + + compilation.seal(err => { + if(err) return callback(err); + + this.applyPluginsAsync("after-compile", compilation, err => { + if(err) return callback(err); + + return callback(null, compilation); + }); + }); + }); + }); + } +} + +Compiler.Watching = Watching; +module.exports = Compiler; diff --git a/node_modules/webpack/lib/ContextExclusionPlugin.js b/node_modules/webpack/lib/ContextExclusionPlugin.js new file mode 100644 index 000000000..db6c81b27 --- /dev/null +++ b/node_modules/webpack/lib/ContextExclusionPlugin.js @@ -0,0 +1,17 @@ +"use strict"; + +class ContextExclusionPlugin { + constructor(negativeMatcher) { + this.negativeMatcher = negativeMatcher; + } + + apply(compiler) { + compiler.plugin("context-module-factory", (cmf) => { + cmf.plugin("context-module-files", (files) => { + return files.filter(filePath => !this.negativeMatcher.test(filePath)); + }); + }); + } +} + +module.exports = ContextExclusionPlugin; diff --git a/node_modules/webpack/lib/ContextModuleFactory.js b/node_modules/webpack/lib/ContextModuleFactory.js index a5947064b..db4ba1022 100644 --- a/node_modules/webpack/lib/ContextModuleFactory.js +++ b/node_modules/webpack/lib/ContextModuleFactory.js @@ -18,7 +18,6 @@ module.exports = class ContextModuleFactory extends Tapable { } create(data, callback) { - const module = this; const context = data.context; const dependencies = data.dependencies; const dependency = dependencies[0]; @@ -59,7 +58,7 @@ module.exports = class ContextModuleFactory extends Tapable { resource = request; } - const resolvers = module.resolvers; + const resolvers = this.resolvers; asyncLib.parallel([ function(callback) { @@ -79,14 +78,14 @@ module.exports = class ContextModuleFactory extends Tapable { ], (err, result) => { if(err) return callback(err); - module.applyPluginsAsyncWaterfall("after-resolve", { + this.applyPluginsAsyncWaterfall("after-resolve", { loaders: loadersPrefix + result[1].join("!") + (result[1].length > 0 ? "!" : ""), resource: result[0], recursive: recursive, regExp: regExp, async: asyncContext, dependencies: dependencies, - resolveDependencies: module.resolveDependencies.bind(module) + resolveDependencies: this.resolveDependencies.bind(this) }, function(err, result) { if(err) return callback(err); @@ -100,11 +99,13 @@ module.exports = class ContextModuleFactory extends Tapable { } resolveDependencies(fs, resource, recursive, regExp, callback) { + const cmf = this; if(!regExp || !resource) return callback(null, []); (function addDirectory(directory, callback) { fs.readdir(directory, (err, files) => { if(err) return callback(err); + files = cmf.applyPluginsWaterfall("context-module-files", files); if(!files || files.length === 0) return callback(null, []); asyncLib.map(files.filter(function(p) { return p.indexOf(".") !== 0; diff --git a/node_modules/webpack/lib/DelegatedModule.js b/node_modules/webpack/lib/DelegatedModule.js index cd80a21ff..223d2c2a2 100644 --- a/node_modules/webpack/lib/DelegatedModule.js +++ b/node_modules/webpack/lib/DelegatedModule.js @@ -1,92 +1,98 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -"use strict"; - -const Module = require("./Module"); -const OriginalSource = require("webpack-sources").OriginalSource; -const RawSource = require("webpack-sources").RawSource; -const WebpackMissingModule = require("./dependencies/WebpackMissingModule"); -const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); -const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); - -class DelegatedModule extends Module { - constructor(sourceRequest, data, type, userRequest, originalRequest) { - super(); - this.sourceRequest = sourceRequest; - this.request = data.id; - this.meta = data.meta; - this.type = type; - this.originalRequest = originalRequest; - this.userRequest = userRequest; - this.built = false; - this.delegated = true; - this.delegateData = data; - } - - libIdent(options) { - return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options); - } - - identifier() { - return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`; - } - - readableIdentifier() { - return `delegated ${this.userRequest} from ${this.sourceRequest}`; - } - - needRebuild() { - return false; - } - - build(options, compilation, resolver, fs, callback) { - this.built = true; - this.builtTime = Date.now(); - this.cacheable = true; - this.dependencies.length = 0; - this.addDependency(new DelegatedSourceDependency(this.sourceRequest)); - this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true)); - callback(); - } - - unbuild() { - this.built = false; - super.unbuild(); - } - - source() { - const sourceModule = this.dependencies[0].module; - let str; - - if(!sourceModule) { - str = WebpackMissingModule.moduleCode(this.sourceRequest); - } else { - str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`; - - switch(this.type) { - case "require": - str += `(${JSON.stringify(this.request)})`; - break; - case "object": - str += `[${JSON.stringify(this.request)}]`; - break; - } - - str += ";"; - } - - if(this.useSourceMap) { - return new OriginalSource(str, this.identifier()); - } else { - return new RawSource(str); - } - } - - size() { - return 42; - } -} - -module.exports = DelegatedModule; +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const Module = require("./Module"); +const OriginalSource = require("webpack-sources").OriginalSource; +const RawSource = require("webpack-sources").RawSource; +const WebpackMissingModule = require("./dependencies/WebpackMissingModule"); +const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); +const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); + +class DelegatedModule extends Module { + constructor(sourceRequest, data, type, userRequest, originalRequest) { + super(); + this.sourceRequest = sourceRequest; + this.request = data.id; + this.meta = data.meta; + this.type = type; + this.originalRequest = originalRequest; + this.userRequest = userRequest; + this.built = false; + this.delegated = true; + this.delegateData = data; + } + + libIdent(options) { + return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options); + } + + identifier() { + return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`; + } + + readableIdentifier() { + return `delegated ${this.userRequest} from ${this.sourceRequest}`; + } + + needRebuild() { + return false; + } + + build(options, compilation, resolver, fs, callback) { + this.built = true; + this.builtTime = Date.now(); + this.cacheable = true; + this.dependencies.length = 0; + this.addDependency(new DelegatedSourceDependency(this.sourceRequest)); + this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true)); + callback(); + } + + unbuild() { + this.built = false; + super.unbuild(); + } + + source() { + const sourceModule = this.dependencies[0].module; + let str; + + if(!sourceModule) { + str = WebpackMissingModule.moduleCode(this.sourceRequest); + } else { + str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`; + + switch(this.type) { + case "require": + str += `(${JSON.stringify(this.request)})`; + break; + case "object": + str += `[${JSON.stringify(this.request)}]`; + break; + } + + str += ";"; + } + + if(this.useSourceMap) { + return new OriginalSource(str, this.identifier()); + } else { + return new RawSource(str); + } + } + + size() { + return 42; + } + + updateHash(hash) { + hash.update(this.type); + hash.update(JSON.stringify(this.request)); + super.updateHash(hash); + } +} + +module.exports = DelegatedModule; diff --git a/node_modules/webpack/lib/ExternalModule.js b/node_modules/webpack/lib/ExternalModule.js index 2a8137ebc..45c183b1a 100644 --- a/node_modules/webpack/lib/ExternalModule.js +++ b/node_modules/webpack/lib/ExternalModule.js @@ -116,6 +116,13 @@ class ExternalModule extends Module { size() { return 42; } + + updateHash(hash) { + hash.update(this.type); + hash.update(JSON.stringify(this.request)); + hash.update(JSON.stringify(Boolean(this.optional))); + super.updateHash(hash); + } } module.exports = ExternalModule; diff --git a/node_modules/webpack/lib/FunctionModuleTemplatePlugin.js b/node_modules/webpack/lib/FunctionModuleTemplatePlugin.js index 72e214808..234a840f5 100644 --- a/node_modules/webpack/lib/FunctionModuleTemplatePlugin.js +++ b/node_modules/webpack/lib/FunctionModuleTemplatePlugin.js @@ -28,11 +28,15 @@ class FunctionModuleTemplatePlugin { source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n"); source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n"); source.add(" \\****" + req.replace(/./g, "*") + "****/\n"); - if(Array.isArray(module.providedExports)) + if(Array.isArray(module.providedExports) && module.providedExports.length === 0) + source.add("/*! no exports provided */\n"); + else if(Array.isArray(module.providedExports)) source.add("/*! exports provided: " + module.providedExports.join(", ") + " */\n"); else if(module.providedExports) - source.add("/*! no static exports found */\n"); - if(Array.isArray(module.usedExports)) + source.add("/*! dynamic exports provided */\n"); + if(Array.isArray(module.usedExports) && module.usedExports.length === 0) + source.add("/*! no exports used */\n"); + else if(Array.isArray(module.usedExports)) source.add("/*! exports used: " + module.usedExports.join(", ") + " */\n"); else if(module.usedExports) source.add("/*! all exports used */\n"); diff --git a/node_modules/webpack/lib/HotModuleReplacement.runtime.js b/node_modules/webpack/lib/HotModuleReplacement.runtime.js index f537bfdd7..6db89aa2d 100644 --- a/node_modules/webpack/lib/HotModuleReplacement.runtime.js +++ b/node_modules/webpack/lib/HotModuleReplacement.runtime.js @@ -561,7 +561,8 @@ module.exports = function() { type: "self-accept-error-handler-errored", moduleId: moduleId, error: err2, - orginalError: err + orginalError: err, // TODO remove in webpack 4 + originalError: err }); } if(!options.ignoreErrored) { diff --git a/node_modules/webpack/lib/JsonpMainTemplate.runtime.js b/node_modules/webpack/lib/JsonpMainTemplate.runtime.js index bd0e7ba3b..ed5fba098 100644 --- a/node_modules/webpack/lib/JsonpMainTemplate.runtime.js +++ b/node_modules/webpack/lib/JsonpMainTemplate.runtime.js @@ -2,7 +2,7 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */ +/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */ module.exports = function() { function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars hotAddUpdateChunk(chunkId, moreModules); @@ -15,6 +15,7 @@ module.exports = function() { script.type = "text/javascript"; script.charset = "utf-8"; script.src = $require$.p + $hotChunkFilename$; + $crossOriginLoading$; head.appendChild(script); } diff --git a/node_modules/webpack/lib/JsonpMainTemplatePlugin.js b/node_modules/webpack/lib/JsonpMainTemplatePlugin.js index 9a80e099d..20cecd919 100644 --- a/node_modules/webpack/lib/JsonpMainTemplatePlugin.js +++ b/node_modules/webpack/lib/JsonpMainTemplatePlugin.js @@ -171,6 +171,7 @@ class JsonpMainTemplatePlugin { mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) { const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename; const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename; + const crossOriginLoading = this.outputOptions.crossOriginLoading; const hotUpdateFunction = this.outputOptions.hotUpdateFunction; const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), { hash: `" + ${this.renderCurrentHashCode(hash)} + "`, @@ -186,6 +187,7 @@ class JsonpMainTemplatePlugin { const runtimeSource = Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js")) .replace(/\/\/\$semicolon/g, ";") .replace(/\$require\$/g, this.requireFn) + .replace(/\$crossOriginLoading\$/g, crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}` : "") .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename) .replace(/\$hash\$/g, JSON.stringify(hash)); diff --git a/node_modules/webpack/lib/Module.js b/node_modules/webpack/lib/Module.js index 26977e63f..fb259d863 100644 --- a/node_modules/webpack/lib/Module.js +++ b/node_modules/webpack/lib/Module.js @@ -58,6 +58,7 @@ class Module extends DependenciesBlock { this.providedExports = null; this._chunks.clear(); this._chunksDebugIdent = undefined; + this.optimizationBailout.length = 0; super.disconnect(); } @@ -73,6 +74,7 @@ class Module extends DependenciesBlock { setChunks(chunks) { this._chunks = new SortableSet(chunks, sortById); + this._chunksDebugIdent = undefined; } addChunk(chunk) { diff --git a/node_modules/webpack/lib/NormalModule.js b/node_modules/webpack/lib/NormalModule.js index d150fc767..c3288bf0d 100644 --- a/node_modules/webpack/lib/NormalModule.js +++ b/node_modules/webpack/lib/NormalModule.js @@ -34,12 +34,13 @@ function asString(buf) { function contextify(context, request) { return request.split("!").map(function(r) { - let rp = path.relative(context, r); + const splitPath = r.split("?"); + splitPath[0] = path.relative(context, splitPath[0]); if(path.sep === "\\") - rp = rp.replace(/\\/g, "/"); - if(rp.indexOf("../") !== 0) - rp = "./" + rp; - return rp; + splitPath[0] = splitPath[0].replace(/\\/g, "/"); + if(splitPath[0].indexOf("../") !== 0) + splitPath[0] = "./" + splitPath[0]; + return splitPath.join("?"); }).join("!"); } diff --git a/node_modules/webpack/lib/OptionsDefaulter.js b/node_modules/webpack/lib/OptionsDefaulter.js index f9bd0c00b..ee681b5a9 100644 --- a/node_modules/webpack/lib/OptionsDefaulter.js +++ b/node_modules/webpack/lib/OptionsDefaulter.js @@ -30,6 +30,7 @@ class OptionsDefaulter { } process(options) { + // TODO: change this for webpack 4: options = Object.assign({}, options); for(let name in this.defaults) { switch(this.config[name]) { case undefined: @@ -55,6 +56,7 @@ class OptionsDefaulter { throw new Error("OptionsDefaulter cannot process " + this.config[name]); } } + // TODO: change this for webpack 4: return options; } set(name, config, def) { diff --git a/node_modules/webpack/lib/Parser.js b/node_modules/webpack/lib/Parser.js index 88f9b65db..3150f847a 100644 --- a/node_modules/webpack/lib/Parser.js +++ b/node_modules/webpack/lib/Parser.js @@ -321,45 +321,76 @@ class Parser extends Tapable { } return new BasicEvaluatedExpression().setString(result).setRange(expr.range); }); + }); - /** - * @param {string} kind "cooked" | "raw" - * @param {any[]} quasis quasis - * @param {any[]} expressions expressions - * @return {BasicEvaluatedExpression[]} Simplified template - */ - function getSimplifiedTemplateResult(kind, quasis, expressions) { - const parts = []; - - for(let i = 0; i < quasis.length; i++) { - parts.push(new BasicEvaluatedExpression().setString(quasis[i].value[kind]).setRange(quasis[i].range)); - - if(i > 0) { - const prevExpr = parts[parts.length - 2], - lastExpr = parts[parts.length - 1]; - const expr = this.evaluateExpression(expressions[i - 1]); - if(!(expr.isString() || expr.isNumber())) continue; - - prevExpr.setString(prevExpr.string + (expr.isString() ? expr.string : expr.number) + lastExpr.string); - prevExpr.setRange([prevExpr.range[0], lastExpr.range[1]]); - parts.pop(); - } + /** + * @param {string} kind "cooked" | "raw" + * @param {any[]} quasis quasis + * @param {any[]} expressions expressions + * @return {BasicEvaluatedExpression[]} Simplified template + */ + function getSimplifiedTemplateResult(kind, quasis, expressions) { + const parts = []; + + for(let i = 0; i < quasis.length; i++) { + parts.push(new BasicEvaluatedExpression().setString(quasis[i].value[kind]).setRange(quasis[i].range)); + + if(i > 0) { + const prevExpr = parts[parts.length - 2], + lastExpr = parts[parts.length - 1]; + const expr = this.evaluateExpression(expressions[i - 1]); + if(!(expr.isString() || expr.isNumber())) continue; + + prevExpr.setString(prevExpr.string + (expr.isString() ? expr.string : expr.number) + lastExpr.string); + prevExpr.setRange([prevExpr.range[0], lastExpr.range[1]]); + parts.pop(); } - return parts; } + return parts; + } - this.plugin("evaluate TemplateLiteral", function(node) { - const parts = getSimplifiedTemplateResult.call(this, "cooked", node.quasis, node.expressions); - if(parts.length === 1) { - return parts[0].setRange(node.range); + this.plugin("evaluate TemplateLiteral", function(node) { + const parts = getSimplifiedTemplateResult.call(this, "cooked", node.quasis, node.expressions); + if(parts.length === 1) { + return parts[0].setRange(node.range); + } + return new BasicEvaluatedExpression().setTemplateString(parts).setRange(node.range); + }); + this.plugin("evaluate TaggedTemplateExpression", function(node) { + if(this.evaluateExpression(node.tag).identifier !== "String.raw") return; + const parts = getSimplifiedTemplateResult.call(this, "raw", node.quasi.quasis, node.quasi.expressions); + return new BasicEvaluatedExpression().setTemplateString(parts).setRange(node.range); + }); + + this.plugin("evaluate CallExpression .concat", function(expr, param) { + if(!param.isString() && !param.isWrapped()) return; + + let stringSuffix = null; + let hasUnknownParams = false; + for(let i = expr.arguments.length - 1; i >= 0; i--) { + const argExpr = this.evaluateExpression(expr.arguments[i]); + if(!argExpr.isString() && !argExpr.isNumber()) { + hasUnknownParams = true; + break; } - return new BasicEvaluatedExpression().setTemplateString(parts).setRange(node.range); - }); - this.plugin("evaluate TaggedTemplateExpression", function(node) { - if(this.evaluateExpression(node.tag).identifier !== "String.raw") return; - const parts = getSimplifiedTemplateResult.call(this, "raw", node.quasi.quasis, node.quasi.expressions); - return new BasicEvaluatedExpression().setTemplateString(parts).setRange(node.range); - }); + + const value = argExpr.isString() ? argExpr.string : "" + argExpr.number; + + const newString = value + (stringSuffix ? stringSuffix.string : ""); + const newRange = [argExpr.range[0], (stringSuffix || argExpr).range[1]]; + stringSuffix = new BasicEvaluatedExpression().setString(newString).setRange(newRange); + } + + if(hasUnknownParams) { + const prefix = param.isString() ? param : param.prefix; + return new BasicEvaluatedExpression().setWrapped(prefix, stringSuffix).setRange(expr.range); + } else if(param.isWrapped()) { + const postfix = stringSuffix || param.postfix; + return new BasicEvaluatedExpression().setWrapped(param.prefix, postfix).setRange(expr.range); + } else { + const newString = param.string + (stringSuffix ? stringSuffix.string : ""); + return new BasicEvaluatedExpression().setString(newString).setRange(expr.range); + } }); this.plugin("evaluate CallExpression .split", function(expr, param) { if(!param.isString()) return; diff --git a/node_modules/webpack/lib/SourceMapDevToolPlugin.js b/node_modules/webpack/lib/SourceMapDevToolPlugin.js index abd8d5ee3..7892cb8ac 100644 --- a/node_modules/webpack/lib/SourceMapDevToolPlugin.js +++ b/node_modules/webpack/lib/SourceMapDevToolPlugin.js @@ -96,7 +96,8 @@ class SourceMapDevToolPlugin { return module || source; }); - for(const module of modules) { + for(let idx = 0; idx < modules.length; idx++) { + const module = modules[idx]; if(!moduleToSourceNameMapping.get(module)) { moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener)); } @@ -121,7 +122,8 @@ class SourceMapDevToolPlugin { }); // find modules with conflicting source names - for(const module of allModules) { + for(let idx = 0; idx < allModules.length; idx++) { + const module = allModules[idx]; let sourceName = moduleToSourceNameMapping.get(module); let hasName = conflictDetectionSet.has(sourceName); if(!hasName) { diff --git a/node_modules/webpack/lib/Template.js b/node_modules/webpack/lib/Template.js index b3e17a823..57a8b9730 100644 --- a/node_modules/webpack/lib/Template.js +++ b/node_modules/webpack/lib/Template.js @@ -10,6 +10,12 @@ const ConcatSource = require("webpack-sources").ConcatSource; const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0); const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0); const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1; +const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\n?|\n?\}$/g; +const INDENT_MULTILINE_REGEX = /^\t/mg; +const IDENTIFIER_NAME_REPLACE_REGEX = /^[^a-zA-Z$_]/; +const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$_]/g; +const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g; +const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; module.exports = class Template extends Tapable { constructor(outputOptions) { @@ -18,17 +24,17 @@ module.exports = class Template extends Tapable { } static getFunctionContent(fn) { - return fn.toString().replace(/^function\s?\(\)\s?\{\n?|\n?\}$/g, "").replace(/^\t/mg, ""); + return fn.toString().replace(FUNCTION_CONTENT_REGEX, "").replace(INDENT_MULTILINE_REGEX, ""); } static toIdentifier(str) { if(typeof str !== "string") return ""; - return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_"); + return str.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_").replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_"); } static toPath(str) { if(typeof str !== "string") return ""; - return str.replace(/[^a-zA-Z0-9_!§$()=\-^°]+/g, "-").replace(/^-|-$/, ""); + return str.replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-").replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, ""); } // map number to a single character a-z, A-Z or <_ + number> if number is too big @@ -144,23 +150,27 @@ module.exports = class Template extends Tapable { } else { // Render an object source.add("{\n"); - allModules.sort(function(a, b) { - var aId = a.id + ""; - var bId = b.id + ""; - if(aId < bId) return -1; - if(aId > bId) return 1; - return 0; - }).forEach(function(module, idx) { - if(idx !== 0) source.add(",\n"); - source.add("\n/***/ " + JSON.stringify(module.id) + ":\n"); - source.add(module.source); - }); + allModules + .sort(stringifyIdSortPredicate) + .forEach(function(module, idx) { + if(idx !== 0) source.add(",\n"); + source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`); + source.add(module.source); + }); source.add("\n\n" + prefix + "}"); } return source; } }; +function stringifyIdSortPredicate(a, b) { + var aId = a.id + ""; + var bId = b.id + ""; + if(aId < bId) return -1; + if(aId > bId) return 1; + return 0; +} + function moduleIdIsNumber(module) { return typeof module.id === "number"; } diff --git a/node_modules/webpack/lib/UmdMainTemplatePlugin.js b/node_modules/webpack/lib/UmdMainTemplatePlugin.js index 3ddb98d23..6f44e892e 100644 --- a/node_modules/webpack/lib/UmdMainTemplatePlugin.js +++ b/node_modules/webpack/lib/UmdMainTemplatePlugin.js @@ -42,7 +42,7 @@ class UmdMainTemplatePlugin { apply(compilation) { const mainTemplate = compilation.mainTemplate; compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => { - let externals = chunk.getModules().filter(m => m.external); + let externals = chunk.getModules().filter(m => m.external && (m.type === "umd" || m.type === "umd2")); const optionalExternals = []; let requiredExternals = []; if(this.optionalAmdExternalAsGlobal) { diff --git a/node_modules/webpack/lib/WebpackOptionsDefaulter.js b/node_modules/webpack/lib/WebpackOptionsDefaulter.js index 24bb42321..ff0cc8072 100644 --- a/node_modules/webpack/lib/WebpackOptionsDefaulter.js +++ b/node_modules/webpack/lib/WebpackOptionsDefaulter.js @@ -1,115 +1,129 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -"use strict"; - -const OptionsDefaulter = require("./OptionsDefaulter"); -const Template = require("./Template"); - -class WebpackOptionsDefaulter extends OptionsDefaulter { - constructor() { - super(); - this.set("devtool", false); - this.set("cache", true); - - this.set("context", process.cwd()); - this.set("target", "web"); - - this.set("module.unknownContextRequest", "."); - this.set("module.unknownContextRegExp", false); - this.set("module.unknownContextRecursive", true); - this.set("module.unknownContextCritical", true); - this.set("module.exprContextRequest", "."); - this.set("module.exprContextRegExp", false); - this.set("module.exprContextRecursive", true); - this.set("module.exprContextCritical", true); - this.set("module.wrappedContextRegExp", /.*/); - this.set("module.wrappedContextRecursive", true); - this.set("module.wrappedContextCritical", false); - this.set("module.strictExportPresence", false); - this.set("module.strictThisContextOnImports", false); - - this.set("module.unsafeCache", true); - - this.set("output", "call", (value, options) => { - if(typeof value === "string") { - return { - filename: value - }; - } else if(typeof value !== "object") { - return {}; - } else { - return value; - } - }); - this.set("output.filename", "[name].js"); - this.set("output.chunkFilename", "make", (options) => { - const filename = options.output.filename; - return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename; - }); - this.set("output.library", ""); - this.set("output.hotUpdateFunction", "make", (options) => { - return Template.toIdentifier("webpackHotUpdate" + options.output.library); - }); - this.set("output.jsonpFunction", "make", (options) => { - return Template.toIdentifier("webpackJsonp" + options.output.library); - }); - this.set("output.libraryTarget", "var"); - this.set("output.path", process.cwd()); - this.set("output.sourceMapFilename", "[file].map[query]"); - this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js"); - this.set("output.hotUpdateMainFilename", "[hash].hot-update.json"); - this.set("output.crossOriginLoading", false); - this.set("output.chunkLoadTimeout", 120000); - this.set("output.hashFunction", "md5"); - this.set("output.hashDigest", "hex"); - this.set("output.hashDigestLength", 20); - this.set("output.devtoolLineToLine", false); - this.set("output.strictModuleExceptionHandling", false); - - this.set("node", {}); - this.set("node.console", false); - this.set("node.process", true); - this.set("node.global", true); - this.set("node.Buffer", true); - this.set("node.setImmediate", true); - this.set("node.__filename", "mock"); - this.set("node.__dirname", "mock"); - - this.set("performance.maxAssetSize", 250000); - this.set("performance.maxEntrypointSize", 250000); - this.set("performance.hints", false); - - this.set("resolve", {}); - this.set("resolve.unsafeCache", true); - this.set("resolve.modules", ["node_modules"]); - this.set("resolve.extensions", [".js", ".json"]); - this.set("resolve.mainFiles", ["index"]); - this.set("resolve.aliasFields", "make", (options) => { - if(options.target === "web" || options.target === "webworker") - return ["browser"]; - else - return []; - }); - this.set("resolve.mainFields", "make", (options) => { - if(options.target === "web" || options.target === "webworker") - return ["browser", "module", "main"]; - else - return ["module", "main"]; - }); - this.set("resolve.cacheWithContext", "make", (options) => { - return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0; - }); - this.set("resolveLoader", {}); - this.set("resolveLoader.unsafeCache", true); - this.set("resolveLoader.mainFields", ["loader", "main"]); - this.set("resolveLoader.extensions", [".js", ".json"]); - this.set("resolveLoader.mainFiles", ["index"]); - this.set("resolveLoader.cacheWithContext", "make", (options) => { - return Array.isArray(options.resolveLoader.plugins) && options.resolveLoader.plugins.length > 0; - }); - } -} - -module.exports = WebpackOptionsDefaulter; +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const OptionsDefaulter = require("./OptionsDefaulter"); +const Template = require("./Template"); + +class WebpackOptionsDefaulter extends OptionsDefaulter { + constructor() { + super(); + this.set("devtool", false); + this.set("cache", true); + + this.set("context", process.cwd()); + this.set("target", "web"); + + this.set("module", "call", value => Object.assign({}, value)); + this.set("module.unknownContextRequest", "."); + this.set("module.unknownContextRegExp", false); + this.set("module.unknownContextRecursive", true); + this.set("module.unknownContextCritical", true); + this.set("module.exprContextRequest", "."); + this.set("module.exprContextRegExp", false); + this.set("module.exprContextRecursive", true); + this.set("module.exprContextCritical", true); + this.set("module.wrappedContextRegExp", /.*/); + this.set("module.wrappedContextRecursive", true); + this.set("module.wrappedContextCritical", false); + this.set("module.strictExportPresence", false); + this.set("module.strictThisContextOnImports", false); + this.set("module.unsafeCache", true); + + this.set("output", "call", (value, options) => { + if(typeof value === "string") { + return { + filename: value + }; + } else if(typeof value !== "object") { + return {}; + } else { + return Object.assign({}, value); + } + }); + this.set("output.filename", "[name].js"); + this.set("output.chunkFilename", "make", (options) => { + const filename = options.output.filename; + return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename; + }); + this.set("output.library", ""); + this.set("output.hotUpdateFunction", "make", (options) => { + return Template.toIdentifier("webpackHotUpdate" + options.output.library); + }); + this.set("output.jsonpFunction", "make", (options) => { + return Template.toIdentifier("webpackJsonp" + options.output.library); + }); + this.set("output.libraryTarget", "var"); + this.set("output.path", process.cwd()); + this.set("output.sourceMapFilename", "[file].map[query]"); + this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js"); + this.set("output.hotUpdateMainFilename", "[hash].hot-update.json"); + this.set("output.crossOriginLoading", false); + this.set("output.chunkLoadTimeout", 120000); + this.set("output.hashFunction", "md5"); + this.set("output.hashDigest", "hex"); + this.set("output.hashDigestLength", 20); + this.set("output.devtoolLineToLine", false); + this.set("output.strictModuleExceptionHandling", false); + + this.set("node", "call", value => { + if(typeof value === "boolean") { + return value; + } else { + return Object.assign({}, value); + } + }); + this.set("node.console", false); + this.set("node.process", true); + this.set("node.global", true); + this.set("node.Buffer", true); + this.set("node.setImmediate", true); + this.set("node.__filename", "mock"); + this.set("node.__dirname", "mock"); + + this.set("performance", "call", value => { + if(typeof value === "boolean") { + return value; + } else { + return Object.assign({}, value); + } + }); + this.set("performance.maxAssetSize", 250000); + this.set("performance.maxEntrypointSize", 250000); + this.set("performance.hints", false); + + this.set("resolve", "call", value => Object.assign({}, value)); + this.set("resolve.unsafeCache", true); + this.set("resolve.modules", ["node_modules"]); + this.set("resolve.extensions", [".js", ".json"]); + this.set("resolve.mainFiles", ["index"]); + this.set("resolve.aliasFields", "make", (options) => { + if(options.target === "web" || options.target === "webworker") + return ["browser"]; + else + return []; + }); + this.set("resolve.mainFields", "make", (options) => { + if(options.target === "web" || options.target === "webworker") + return ["browser", "module", "main"]; + else + return ["module", "main"]; + }); + this.set("resolve.cacheWithContext", "make", (options) => { + return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0; + }); + + this.set("resolveLoader", "call", value => Object.assign({}, value)); + this.set("resolveLoader.unsafeCache", true); + this.set("resolveLoader.mainFields", ["loader", "main"]); + this.set("resolveLoader.extensions", [".js", ".json"]); + this.set("resolveLoader.mainFiles", ["index"]); + this.set("resolveLoader.cacheWithContext", "make", (options) => { + return Array.isArray(options.resolveLoader.plugins) && options.resolveLoader.plugins.length > 0; + }); + } +} + +module.exports = WebpackOptionsDefaulter; diff --git a/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js index 8590162c6..b8a4668df 100644 --- a/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js @@ -28,6 +28,10 @@ class AMDDefineDependencyParserPlugin { this.options = options; } + newDefineDependency(range, arrayRange, functionRange, objectRange, namedModule) { + return new AMDDefineDependency(range, arrayRange, functionRange, objectRange, namedModule); + } + apply(parser) { const options = this.options; parser.plugin("call define", (expr) => { @@ -156,7 +160,7 @@ class AMDDefineDependencyParserPlugin { parser.walkExpression(fn || obj); } - const dep = new AMDDefineDependency( + const dep = this.newDefineDependency( expr.range, array ? array.range : null, fn ? fn.range : null, diff --git a/node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js b/node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js index 666a887e3..ad77b0705 100644 --- a/node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js +++ b/node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js @@ -47,6 +47,8 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate { if(dep.module) { const stringifiedId = JSON.stringify(dep.module.id); return `__webpack_require__(${comment}${stringifiedId})`; + } else if(dep.localModule) { + return dep.localModule.variableName(); } return webpackMissingModuleModule(dep.request); diff --git a/node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js b/node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js index 9248927e1..5305288cf 100644 --- a/node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js +++ b/node_modules/webpack/lib/dependencies/AMDRequireContextDependency.js @@ -5,7 +5,6 @@ "use strict"; const ContextDependency = require("./ContextDependency"); -const CriticalDependencyWarning = require("./CriticalDependencyWarning"); class AMDRequireContextDependency extends ContextDependency { constructor(request, recursive, regExp, range, valueRange) { super(request, recursive, regExp); @@ -16,14 +15,6 @@ class AMDRequireContextDependency extends ContextDependency { get type() { return "amd require context"; } - - getWarnings() { - if(this.critical) { - return [ - new CriticalDependencyWarning(this.critical) - ]; - } - } } AMDRequireContextDependency.Template = require("./ContextDependencyTemplateAsRequireCall"); module.exports = AMDRequireContextDependency; diff --git a/node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js b/node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js index 74822aebd..6e8e33f08 100644 --- a/node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js +++ b/node_modules/webpack/lib/dependencies/CommonJsRequireContextDependency.js @@ -4,7 +4,6 @@ */ "use strict"; const ContextDependency = require("./ContextDependency"); -const CriticalDependencyWarning = require("./CriticalDependencyWarning"); const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall"); class CommonJsRequireContextDependency extends ContextDependency { @@ -18,15 +17,6 @@ class CommonJsRequireContextDependency extends ContextDependency { return "cjs require context"; } - getWarnings() { - if(!this.critical) { - return; - } - - return [ - new CriticalDependencyWarning(this.critical) - ]; - } } CommonJsRequireContextDependency.Template = ContextDependencyTemplateAsRequireCall; diff --git a/node_modules/webpack/lib/dependencies/ContextDependency.js b/node_modules/webpack/lib/dependencies/ContextDependency.js index 7f8772a55..55bc9823c 100644 --- a/node_modules/webpack/lib/dependencies/ContextDependency.js +++ b/node_modules/webpack/lib/dependencies/ContextDependency.js @@ -4,6 +4,7 @@ */ "use strict"; const Dependency = require("../Dependency"); +const CriticalDependencyWarning = require("./CriticalDependencyWarning"); class ContextDependency extends Dependency { constructor(request, recursive, regExp) { @@ -13,6 +14,13 @@ class ContextDependency extends Dependency { this.recursive = recursive; this.regExp = regExp; this.async = false; + + this.hadGlobalOrStickyRegExp = false; + if(this.regExp.global || this.regExp.sticky) { + this.regExp = null; + this.hadGlobalOrStickyRegExp = true; + } + } isEqualResource(other) { @@ -24,6 +32,18 @@ class ContextDependency extends Dependency { this.regExp === other.regExp && this.async === other.async; } + + getWarnings() { + let warnings = super.getWarnings() || []; + if(this.critical) { + warnings.push(new CriticalDependencyWarning(this.critical)); + } + if(this.hadGlobalOrStickyRegExp) { + warnings.push(new CriticalDependencyWarning("Contexts can't use RegExps with the 'g' or 'y' flags.")); + } + return warnings; + } + } module.exports = ContextDependency; diff --git a/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js index d6f37fce1..f7072ebac 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js @@ -39,9 +39,11 @@ module.exports = class HarmonyExportDependencyParserPlugin { parser.plugin("export specifier", (statement, id, name, idx) => { const rename = parser.scope.renames[`$${id}`]; let dep; + const harmonyNamedExports = parser.state.harmonyNamedExports = parser.state.harmonyNamedExports || new Set(); + harmonyNamedExports.add(name); if(rename === "imported var") { const settings = parser.state.harmonySpecifier[`$${id}`]; - dep = new HarmonyExportImportedSpecifierDependency(parser.state.module, settings[0], settings[1], settings[2], name); + dep = new HarmonyExportImportedSpecifierDependency(parser.state.module, settings[0], settings[1], settings[2], name, harmonyNamedExports, null); } else { const immutable = statement.declaration && isImmutableStatement(statement.declaration); const hoisted = statement.declaration && isHoistedStatement(statement.declaration); @@ -53,7 +55,17 @@ module.exports = class HarmonyExportDependencyParserPlugin { return true; }); parser.plugin("export import specifier", (statement, source, id, name, idx) => { - const dep = new HarmonyExportImportedSpecifierDependency(parser.state.module, parser.state.lastHarmonyImport, HarmonyModulesHelpers.getModuleVar(parser.state, source), id, name); + const harmonyNamedExports = parser.state.harmonyNamedExports = parser.state.harmonyNamedExports || new Set(); + let harmonyStarExports = null; + if(name) { + harmonyNamedExports.add(name); + } else { + harmonyStarExports = parser.state.harmonyStarExports = parser.state.harmonyStarExports || []; + } + const dep = new HarmonyExportImportedSpecifierDependency(parser.state.module, parser.state.lastHarmonyImport, HarmonyModulesHelpers.getModuleVar(parser.state, source), id, name, harmonyNamedExports, harmonyStarExports && harmonyStarExports.slice()); + if(harmonyStarExports) { + harmonyStarExports.push(dep); + } dep.loc = Object.create(statement.loc); dep.loc.index = idx; parser.state.current.addDependency(dep); diff --git a/node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js b/node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js index 17881438f..c2d90847b 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js +++ b/node_modules/webpack/lib/dependencies/HarmonyExportExpressionDependency.js @@ -22,13 +22,6 @@ class HarmonyExportExpressionDependency extends NullDependency { exports: ["default"] }; } - - describeHarmonyExport() { - return { - exportedName: "default", - precedence: 1, - }; - } } HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate { diff --git a/node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js b/node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js index 114bd455a..cb1b892d2 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +++ b/node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js @@ -4,16 +4,17 @@ */ "use strict"; const NullDependency = require("./NullDependency"); -const HarmonyModulesHelpers = require("./HarmonyModulesHelpers"); class HarmonyExportImportedSpecifierDependency extends NullDependency { - constructor(originModule, importDependency, importedVar, id, name) { + constructor(originModule, importDependency, importedVar, id, name, activeExports, otherStarExports) { super(); this.originModule = originModule; this.importDependency = importDependency; this.importedVar = importedVar; this.id = id; this.name = name; + this.activeExports = activeExports; + this.otherStarExports = otherStarExports; } get type() { @@ -23,14 +24,14 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency { getReference() { const name = this.name; const used = this.originModule.isUsed(name); - const active = HarmonyModulesHelpers.isActive(this.originModule, this); const importedModule = this.importDependency.module; - if(!importedModule || !used || !active) return null; - if(!this.originModule.usedExports) return null; + if(!importedModule || !used || !this.originModule.usedExports) return null; + + const hasUsedExports = Array.isArray(this.originModule.usedExports); if(name) { - const nameIsNotInUsedExports = Array.isArray(this.originModule.usedExports) && this.originModule.usedExports.indexOf(name) < 0; + const nameIsNotInUsedExports = hasUsedExports && this.originModule.usedExports.indexOf(name) < 0; if(nameIsNotInUsedExports) return null; // export { name as name } @@ -48,36 +49,37 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency { }; } + const hasProvidedExports = Array.isArray(importedModule.providedExports); + const activeFromOtherStarExports = this._discoverActiveExportsFromOtherStartExports(); + // export * - if(Array.isArray(this.originModule.usedExports)) { + if(hasUsedExports) { // reexport * with known used exports - var activeExports = HarmonyModulesHelpers.getActiveExports(this.originModule, this); - if(Array.isArray(importedModule.providedExports)) { - return { - module: importedModule, - importedNames: this.originModule.usedExports.filter((id) => { - const notInActiveExports = activeExports.indexOf(id) < 0; - const notDefault = id !== "default"; - const inProvidedExports = importedModule.providedExports.indexOf(id) >= 0; - return notInActiveExports && notDefault && inProvidedExports; - }), - }; - } + const importedNames = this.originModule.usedExports.filter(id => { + if(id === "default") return false; + if(this.activeExports.has(id)) return false; + if(activeFromOtherStarExports.has(id)) return false; + if(hasProvidedExports && importedModule.providedExports.indexOf(id) < 0) return false; + + return true; + }); return { module: importedModule, - importedNames: this.originModule.usedExports.filter(id => { - const notInActiveExports = activeExports.indexOf(id) < 0; - const notDefault = id !== "default"; - return notInActiveExports && notDefault; - }), + importedNames }; } - if(Array.isArray(importedModule.providedExports)) { + if(hasProvidedExports) { return { module: importedModule, - importedNames: importedModule.providedExports.filter(id => id !== "default"), + importedNames: importedModule.providedExports.filter(id => { + if(id === "default") return false; + if(this.activeExports.has(id)) return false; + if(activeFromOtherStarExports.has(id)) return false; + + return true; + }) }; } @@ -87,6 +89,21 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency { }; } + _discoverActiveExportsFromOtherStartExports() { + if(!this.otherStarExports) + return new Set(); + const result = new Set(); + // try to learn impossible exports from other star exports with provided exports + for(const otherStarExport of this.otherStarExports) { + const otherImportedModule = otherStarExport.importDependency.module; + if(otherImportedModule && Array.isArray(otherImportedModule.providedExports)) { + for(const exportName of otherImportedModule.providedExports) + result.add(exportName); + } + } + return result; + } + getExports() { if(this.name) { return { @@ -122,22 +139,6 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency { }; } - describeHarmonyExport() { - const importedModule = this.importDependency.module; - if(!this.name && importedModule && Array.isArray(importedModule.providedExports)) { - // for a star export and when we know which exports are provided, we can tell so - return { - exportedName: importedModule.providedExports, - precedence: 3 - }; - } - - return { - exportedName: this.name, - precedence: this.name ? 2 : 3 - }; - } - updateHash(hash) { super.updateHash(hash); const hashValue = this.getHashValue(this.importDependency.module); @@ -167,7 +168,6 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS const name = dep.importedVar; const used = dep.originModule.isUsed(dep.name); const importedModule = dep.importDependency.module; - const active = HarmonyModulesHelpers.isActive(dep.originModule, dep); const importsExportsUnknown = !importedModule || !Array.isArray(importedModule.providedExports); const getReexportStatement = this.reexportStatementCreator(dep.originModule, importsExportsUnknown, name); @@ -177,11 +177,6 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS return "/* unused harmony reexport " + dep.name + " */\n"; } - // we want to reexport something but another exports overrides this one - if(!active) { - return "/* inactive harmony reexport " + (dep.name || "namespace") + " */\n"; - } - // we want to reexport the default export from a non-hamory module const isNotAHarmonyModule = !(importedModule && (!importedModule.meta || importedModule.meta.harmonyModule)); if(dep.name && dep.id === "default" && isNotAHarmonyModule) { @@ -199,13 +194,17 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS return "/* harmony reexport (module object) */ " + getReexportStatement(JSON.stringify(used), ""); } + const hasProvidedExports = importedModule && Array.isArray(importedModule.providedExports); + + const activeFromOtherStarExports = dep._discoverActiveExportsFromOtherStartExports(); + // we know which exports are used if(Array.isArray(dep.originModule.usedExports)) { - const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep); - const items = dep.originModule.usedExports.map(function(id) { + const items = dep.originModule.usedExports.map(id => { if(id === "default") return; - if(activeExports.indexOf(id) >= 0) return; + if(dep.activeExports.has(id)) return; if(importedModule.isProvided(id) === false) return; + if(activeFromOtherStarExports.has(id)) return; var exportUsed = dep.originModule.isUsed(id); var idUsed = importedModule && importedModule.isUsed(id); return [exportUsed, idUsed]; @@ -221,11 +220,11 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS } // not sure which exports are used, but we know which are provided - if(dep.originModule.usedExports && importedModule && Array.isArray(importedModule.providedExports)) { - const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep); - const items = importedModule.providedExports.map(function(id) { + if(dep.originModule.usedExports && importedModule && hasProvidedExports) { + const items = importedModule.providedExports.map(id => { if(id === "default") return; - if(activeExports.indexOf(id) >= 0) return; + if(dep.activeExports.has(id)) return; + if(activeFromOtherStarExports.has(id)) return; var exportUsed = dep.originModule.isUsed(id); var idUsed = importedModule && importedModule.isUsed(id); return [exportUsed, idUsed]; @@ -242,7 +241,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS // not sure which exports are used and provided if(dep.originModule.usedExports) { - const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep); + const activeExports = Array.from(dep.activeExports).concat(Array.from(activeFromOtherStarExports)); let content = "/* harmony namespace reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in " + name + ") "; // Filter out exports which are defined by other exports diff --git a/node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js b/node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js index 024ceeb00..33c253f4b 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js +++ b/node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js @@ -4,7 +4,6 @@ */ "use strict"; const NullDependency = require("./NullDependency"); -const HarmonyModulesHelpers = require("./HarmonyModulesHelpers"); class HarmonyExportSpecifierDependency extends NullDependency { constructor(originModule, id, name, position, immutable) { @@ -25,13 +24,6 @@ class HarmonyExportSpecifierDependency extends NullDependency { exports: [this.name] }; } - - describeHarmonyExport() { - return { - exportedName: this.name, - precedence: 1 - }; - } } HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate { @@ -46,15 +38,10 @@ HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependen getContent(dep) { const used = dep.originModule.isUsed(dep.name); - const active = HarmonyModulesHelpers.isActive(dep.originModule, dep); if(!used) { return `/* unused harmony export ${(dep.name || "namespace")} */\n`; } - if(!active) { - return `/* inactive harmony export ${(dep.name || "namespace")} */\n`; - } - const exportsName = dep.originModule.exportsArgument || "exports"; if(dep.immutable) { return `/* harmony export (immutable) */ ${exportsName}[${JSON.stringify(used)}] = ${dep.id};\n`; diff --git a/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js index d756688d2..3b867f616 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js @@ -56,6 +56,8 @@ module.exports = class HarmonyImportDependencyParserPlugin { if(this.strictThisContextOnImports) { // only in case when we strictly follow the spec we need a special case here parser.plugin("call imported var.*", (expr) => { + if(expr.callee.type !== "MemberExpression") return; + if(expr.callee.object.type !== "Identifier") return; const name = expr.callee.object.name; const settings = parser.state.harmonySpecifier[`$${name}`]; if(settings[2] !== null) @@ -75,6 +77,7 @@ module.exports = class HarmonyImportDependencyParserPlugin { const args = expr.arguments; const fullExpr = expr; expr = expr.callee; + if(expr.type !== "Identifier") return; const name = expr.name; const settings = parser.state.harmonySpecifier[`$${name}`]; const dep = new HarmonyImportSpecifierDependency(settings[0], settings[1], settings[2], name, expr.range, this.strictExportPresence); diff --git a/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js b/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js index 1f3387fe1..10ee7e27e 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js +++ b/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js @@ -27,59 +27,6 @@ class HarmonyModulesHelpers { return null; return this.getModuleVar(state, request); } - - // checks if an harmony dependency is active in a module according to - // precedence rules. - static isActive(module, depInQuestion) { - const desc = depInQuestion.describeHarmonyExport(); - if(!desc.exportedName) return true; - let before = true; - for(const moduleDependency of module.dependencies) { - const dep = moduleDependency; - if(dep === depInQuestion) { - before = false; - continue; - } - if(!dep.describeHarmonyExport) continue; - const d = dep.describeHarmonyExport(); - if(!d || !d.exportedName) continue; - if(d.exportedName === desc.exportedName) { - if(d.precedence < desc.precedence) { - return false; - } - if(d.precedence === desc.precedence && !before) { - return false; - } - } - } - return true; - } - - // get a list of named exports defined in a module - // doesn't include * reexports. - static getActiveExports(module, currentDependency) { - const desc = currentDependency && currentDependency.describeHarmonyExport(); - var currentIndex = currentDependency ? module.dependencies.indexOf(currentDependency) : -1; - return module.dependencies.map((dep, idx) => { - return { - dep: dep, - idx: idx - }; - }).reduce((arr, data) => { - const dep = data.dep; - if(!dep.describeHarmonyExport) return arr; - const d = dep.describeHarmonyExport(); - if(!d) return arr; - if(!desc || (d.precedence < desc.precedence) || (d.precedence === desc.precedence && data.idx < currentIndex)) { - var names = [].concat(d.exportedName); - names.forEach(function(name) { - if(name && arr.indexOf(name) < 0) - arr.push(name); - }); - } - return arr; - }, []); - } } module.exports = HarmonyModulesHelpers; diff --git a/node_modules/webpack/lib/dependencies/ImportContextDependency.js b/node_modules/webpack/lib/dependencies/ImportContextDependency.js index 252bc75a0..d7f378c5c 100644 --- a/node_modules/webpack/lib/dependencies/ImportContextDependency.js +++ b/node_modules/webpack/lib/dependencies/ImportContextDependency.js @@ -4,7 +4,6 @@ */ "use strict"; const ContextDependency = require("./ContextDependency"); -const CriticalDependencyWarning = require("./CriticalDependencyWarning"); const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall"); class ImportContextDependency extends ContextDependency { @@ -19,15 +18,6 @@ class ImportContextDependency extends ContextDependency { return "import() context"; } - getWarnings() { - if(!this.critical) { - return; - } - - return [ - new CriticalDependencyWarning(this.critical) - ]; - } } ImportContextDependency.Template = ContextDependencyTemplateAsRequireCall; diff --git a/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js b/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js index 161319e82..f53e94768 100644 --- a/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js +++ b/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js @@ -4,7 +4,6 @@ */ "use strict"; const ContextDependency = require("./ContextDependency"); -const CriticalDependencyWarning = require("./CriticalDependencyWarning"); const ContextDependencyTemplateAsId = require("./ContextDependencyTemplateAsId"); class RequireResolveContextDependency extends ContextDependency { @@ -18,15 +17,6 @@ class RequireResolveContextDependency extends ContextDependency { return "amd require context"; } - getWarnings() { - if(!this.critical) { - return; - } - - return [ - new CriticalDependencyWarning(this.critical) - ]; - } } RequireResolveContextDependency.Template = ContextDependencyTemplateAsId; 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; }); diff --git a/node_modules/webpack/lib/webpack.js b/node_modules/webpack/lib/webpack.js index fb8c68b7f..81fc7d83f 100644 --- a/node_modules/webpack/lib/webpack.js +++ b/node_modules/webpack/lib/webpack.js @@ -22,6 +22,7 @@ function webpack(options, callback) { if(Array.isArray(options)) { compiler = new MultiCompiler(options.map(options => webpack(options))); } else if(typeof options === "object") { + // TODO webpack 4: process returns options new WebpackOptionsDefaulter().process(options); compiler = new Compiler(); @@ -72,6 +73,7 @@ exportPlugins(exports, { "DefinePlugin": () => require("./DefinePlugin"), "NormalModuleReplacementPlugin": () => require("./NormalModuleReplacementPlugin"), "ContextReplacementPlugin": () => require("./ContextReplacementPlugin"), + "ContextExclusionPlugin": () => require("./ContextExclusionPlugin"), "IgnorePlugin": () => require("./IgnorePlugin"), "WatchIgnorePlugin": () => require("./WatchIgnorePlugin"), "BannerPlugin": () => require("./BannerPlugin"), -- cgit v1.2.3