From 0469abd4a9c9270a1fdc962969e36e63699af8b4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 10 Dec 2017 21:51:33 +0100 Subject: upgrade dependencies --- .../lib/AsyncDependencyToInitialChunkWarning.js | 21 + node_modules/webpack/lib/Chunk.js | 3 + node_modules/webpack/lib/Compilation.js | 32 +- node_modules/webpack/lib/Compiler.js | 1042 ++++++++++---------- node_modules/webpack/lib/ContextModuleFactory.js | 10 +- node_modules/webpack/lib/DelegatedModule.js | 196 ++-- node_modules/webpack/lib/DllModuleFactory.js | 4 +- node_modules/webpack/lib/DllReferencePlugin.js | 2 +- .../EvalSourceMapDevToolModuleTemplatePlugin.js | 2 +- node_modules/webpack/lib/ExternalsPlugin.js | 2 +- .../webpack/lib/FlagDependencyUsagePlugin.js | 2 +- .../webpack/lib/HotModuleReplacementPlugin.js | 10 +- .../webpack/lib/JsonpMainTemplatePlugin.js | 4 +- node_modules/webpack/lib/ModuleParseError.js | 2 +- node_modules/webpack/lib/OptionsDefaulter.js | 4 +- node_modules/webpack/lib/SourceMapDevToolPlugin.js | 6 +- node_modules/webpack/lib/Stats.js | 35 +- node_modules/webpack/lib/UmdMainTemplatePlugin.js | 2 +- .../webpack/lib/WebpackOptionsDefaulter.js | 258 ++--- .../webpack/lib/WebpackOptionsValidationError.js | 45 +- .../lib/dependencies/AMDDefineDependency.js | 6 +- .../AMDDefineDependencyParserPlugin.js | 24 +- .../lib/dependencies/AMDRequireDependency.js | 8 +- .../dependencies/HarmonyDetectionParserPlugin.js | 4 +- .../lib/dependencies/HarmonyImportDependency.js | 2 +- .../lib/dependencies/LocalModulesHelpers.js | 8 +- .../lib/dependencies/RequireIncludeDependency.js | 8 + .../webpack/lib/optimize/CommonsChunkPlugin.js | 20 +- .../webpack/lib/optimize/ConcatenatedModule.js | 22 +- node_modules/webpack/lib/util/Queue.js | 42 + .../lib/webworker/WebWorkerMainTemplatePlugin.js | 4 +- 31 files changed, 991 insertions(+), 839 deletions(-) create mode 100644 node_modules/webpack/lib/AsyncDependencyToInitialChunkWarning.js create mode 100644 node_modules/webpack/lib/util/Queue.js (limited to 'node_modules/webpack/lib') diff --git a/node_modules/webpack/lib/AsyncDependencyToInitialChunkWarning.js b/node_modules/webpack/lib/AsyncDependencyToInitialChunkWarning.js new file mode 100644 index 000000000..b917b4f60 --- /dev/null +++ b/node_modules/webpack/lib/AsyncDependencyToInitialChunkWarning.js @@ -0,0 +1,21 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Sean Larkin @thelarkinn +*/ +"use strict"; + +const WebpackError = require("./WebpackError"); + +module.exports = class AsyncDependencyToInitialChunkWarning extends WebpackError { + constructor(chunkName, module, loc) { + super(); + + this.name = "AsyncDependencyToInitialChunkWarning"; + this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`; + this.module = module; + this.origin = module; + this.originLoc = loc; + + Error.captureStackTrace(this, this.constructor); + } +}; diff --git a/node_modules/webpack/lib/Chunk.js b/node_modules/webpack/lib/Chunk.js index 8e7cef13c..48ca2d1a3 100644 --- a/node_modules/webpack/lib/Chunk.js +++ b/node_modules/webpack/lib/Chunk.js @@ -308,6 +308,9 @@ class Chunk { otherChunk.origins.forEach(origin => { this.origins.push(origin); }); + this.blocks.forEach(b => { + b.chunkReason = reason; + }); this.origins.forEach(origin => { if(!origin.reasons) { origin.reasons = [reason]; diff --git a/node_modules/webpack/lib/Compilation.js b/node_modules/webpack/lib/Compilation.js index 72b195745..05f5be60d 100644 --- a/node_modules/webpack/lib/Compilation.js +++ b/node_modules/webpack/lib/Compilation.js @@ -20,9 +20,11 @@ const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate"); const ModuleTemplate = require("./ModuleTemplate"); const Dependency = require("./Dependency"); const ChunkRenderError = require("./ChunkRenderError"); +const AsyncDependencyToInitialChunkWarning = require("./AsyncDependencyToInitialChunkWarning"); const CachedSource = require("webpack-sources").CachedSource; const Stats = require("./Stats"); const Semaphore = require("./util/Semaphore"); +const Queue = require("./util/Queue"); function byId(a, b) { if(a.id < b.id) return -1; @@ -884,12 +886,19 @@ class Compilation extends Tapable { // but only once (blockChunks map) let c = blockChunks.get(b); if(c === undefined) { - c = this.addChunk(b.chunkName, b.module, b.loc); - blockChunks.set(b, c); - allCreatedChunks.add(c); - // We initialize the chunks property - // this is later filled with the chunk when needed - b.chunks = []; + c = this.namedChunks[b.chunkName]; + if(c && c.isInitial()) { + // TODO webpack 4: convert this to an error + this.warnings.push(new AsyncDependencyToInitialChunkWarning(b.chunkName, b.module, b.loc)); + c = chunk; + } else { + c = this.addChunk(b.chunkName, b.module, b.loc); + 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 @@ -954,10 +963,10 @@ class Compilation extends Tapable { let availableModules; let newAvailableModules; - const queue2 = inputChunks.map(chunk => ({ + const queue2 = new Queue(inputChunks.map(chunk => ({ chunk, availableModules: new Set() - })); + }))); // Helper function to check if all modules of a chunk are available const areModulesAvailable = (chunk, availableModules) => { @@ -982,7 +991,7 @@ class Compilation extends Tapable { // Iterative traversing of the basic chunk graph while(queue2.length) { - const queueItem = queue2.pop(); + const queueItem = queue2.dequeue(); chunk = queueItem.chunk; availableModules = queueItem.availableModules; @@ -1003,6 +1012,7 @@ class Compilation extends Tapable { } if(!deletedModules) continue; + availableModules = minAvailableModules; } // 2. Get the edges at this point of the graph @@ -1040,7 +1050,7 @@ class Compilation extends Tapable { // 8. Enqueue further traversal for(const nextChunk of nextChunks) { - queue2.push({ + queue2.enqueue({ chunk: nextChunk, availableModules: newAvailableModules }); @@ -1415,7 +1425,7 @@ class Compilation extends Tapable { } createChildCompiler(name, outputOptions, plugins) { - var idx = (this.childrenCounters[name] || 0); + const idx = (this.childrenCounters[name] || 0); this.childrenCounters[name] = idx + 1; return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins); } diff --git a/node_modules/webpack/lib/Compiler.js b/node_modules/webpack/lib/Compiler.js index 943ae48a6..4c7e02b4e 100644 --- a/node_modules/webpack/lib/Compiler.js +++ b/node_modules/webpack/lib/Compiler.js @@ -1,523 +1,519 @@ -/* - 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; +/* + 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 util = require("util"); + +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 + }; + this.parser = { + plugin: util.deprecate( + (hook, fn) => { + this.plugin("compilation", (compilation, data) => { + data.normalModuleFactory.plugin("parser", parser => { + parser.plugin(hook, fn); + }); + }); + }, + "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. " + ), + apply: util.deprecate( + () => { + const args = arguments; + this.plugin("compilation", (compilation, data) => { + data.normalModuleFactory.plugin("parser", parser => { + parser.apply.apply(parser, args); + }); + }); + }, + "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. " + ) + }; + + 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/ContextModuleFactory.js b/node_modules/webpack/lib/ContextModuleFactory.js index db4ba1022..a3bc34e7e 100644 --- a/node_modules/webpack/lib/ContextModuleFactory.js +++ b/node_modules/webpack/lib/ContextModuleFactory.js @@ -114,7 +114,15 @@ module.exports = class ContextModuleFactory extends Tapable { const subResource = path.join(directory, seqment); fs.stat(subResource, (err, stat) => { - if(err) return callback(err); + if(err) { + if(err.code === "ENOENT") { + // ENOENT is ok here because the file may have been deleted between + // the readdir and stat calls. + return callback(); + } else { + return callback(err); + } + } if(stat.isDirectory()) { diff --git a/node_modules/webpack/lib/DelegatedModule.js b/node_modules/webpack/lib/DelegatedModule.js index 223d2c2a2..4046d03d5 100644 --- a/node_modules/webpack/lib/DelegatedModule.js +++ b/node_modules/webpack/lib/DelegatedModule.js @@ -1,98 +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; - } - - updateHash(hash) { - hash.update(this.type); - hash.update(JSON.stringify(this.request)); - super.updateHash(hash); - } -} - -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/DllModuleFactory.js b/node_modules/webpack/lib/DllModuleFactory.js index aae5c5747..7fba3126f 100644 --- a/node_modules/webpack/lib/DllModuleFactory.js +++ b/node_modules/webpack/lib/DllModuleFactory.js @@ -4,8 +4,8 @@ */ "use strict"; -var Tapable = require("tapable"); -var DllModule = require("./DllModule"); +const Tapable = require("tapable"); +const DllModule = require("./DllModule"); class DllModuleFactory extends Tapable { constructor() { diff --git a/node_modules/webpack/lib/DllReferencePlugin.js b/node_modules/webpack/lib/DllReferencePlugin.js index cd2ef28a6..b0e386792 100644 --- a/node_modules/webpack/lib/DllReferencePlugin.js +++ b/node_modules/webpack/lib/DllReferencePlugin.js @@ -42,7 +42,7 @@ class DllReferencePlugin { manifest = params["dll reference " + manifest]; } const name = this.options.name || manifest.name; - const sourceType = this.options.sourceType || "var"; + const sourceType = this.options.sourceType || (manifest && manifest.type) || "var"; const externals = {}; const source = "dll-reference " + name; externals[source] = name; diff --git a/node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js b/node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js index 85aece2f7..944266b8f 100644 --- a/node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +++ b/node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js @@ -55,7 +55,7 @@ class EvalSourceMapDevToolModuleTemplatePlugin { sourceMap.sources = moduleFilenames; if(sourceMap.sourcesContent) { sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) { - return `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}`; + return typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}` : null; }, this); } sourceMap.sourceRoot = options.sourceRoot || ""; diff --git a/node_modules/webpack/lib/ExternalsPlugin.js b/node_modules/webpack/lib/ExternalsPlugin.js index 751b6e13e..24cc3ad3a 100644 --- a/node_modules/webpack/lib/ExternalsPlugin.js +++ b/node_modules/webpack/lib/ExternalsPlugin.js @@ -4,7 +4,7 @@ */ "use strict"; -var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin"); +const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin"); class ExternalsPlugin { constructor(type, externals) { diff --git a/node_modules/webpack/lib/FlagDependencyUsagePlugin.js b/node_modules/webpack/lib/FlagDependencyUsagePlugin.js index 0be9d54b2..40e1769b1 100644 --- a/node_modules/webpack/lib/FlagDependencyUsagePlugin.js +++ b/node_modules/webpack/lib/FlagDependencyUsagePlugin.js @@ -30,7 +30,7 @@ class FlagDependencyUsagePlugin { else if(usedExports === true) module.usedExports = true; else if(Array.isArray(usedExports)) { - var old = module.usedExports ? module.usedExports.length : -1; + const old = module.usedExports ? module.usedExports.length : -1; module.usedExports = addToSet(module.usedExports || [], usedExports); if(module.usedExports.length === old) return; diff --git a/node_modules/webpack/lib/HotModuleReplacementPlugin.js b/node_modules/webpack/lib/HotModuleReplacementPlugin.js index b6dbdd7f7..f3cc63b94 100644 --- a/node_modules/webpack/lib/HotModuleReplacementPlugin.js +++ b/node_modules/webpack/lib/HotModuleReplacementPlugin.js @@ -25,6 +25,11 @@ module.exports = class HotModuleReplacementPlugin { const requestTimeout = this.requestTimeout; const hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename; const hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename; + compiler.plugin("additional-pass", callback => { + if(multiStep) + return setTimeout(callback, fullBuildTimeout); + return callback(); + }); compiler.plugin("compilation", (compilation, params) => { const hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate; if(!hotUpdateChunkTemplate) return; @@ -88,11 +93,6 @@ module.exports = class HotModuleReplacementPlugin { if(multiStep && !recompilation && !initialPass) return true; }); - compiler.plugin("additional-pass", callback => { - if(multiStep) - return setTimeout(callback, fullBuildTimeout); - return callback(); - }); compilation.plugin("additional-chunk-assets", function() { const records = this.records; if(records.hash === this.hash) return; diff --git a/node_modules/webpack/lib/JsonpMainTemplatePlugin.js b/node_modules/webpack/lib/JsonpMainTemplatePlugin.js index 20cecd919..e713f3879 100644 --- a/node_modules/webpack/lib/JsonpMainTemplatePlugin.js +++ b/node_modules/webpack/lib/JsonpMainTemplatePlugin.js @@ -195,8 +195,8 @@ class JsonpMainTemplatePlugin { function hotDisposeChunk(chunkId) { delete installedChunks[chunkId]; } -var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}]; -this[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`; +var parentHotUpdateCallback = window[${JSON.stringify(hotUpdateFunction)}]; +window[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`; }); mainTemplate.plugin("hash", function(hash) { hash.update("jsonp"); diff --git a/node_modules/webpack/lib/ModuleParseError.js b/node_modules/webpack/lib/ModuleParseError.js index 3b17889ea..3431d477b 100644 --- a/node_modules/webpack/lib/ModuleParseError.js +++ b/node_modules/webpack/lib/ModuleParseError.js @@ -11,7 +11,7 @@ class ModuleParseError extends WebpackError { super(); this.name = "ModuleParseError"; - this.message = "Module parse failed: " + module.request + " " + err.message; + this.message = "Module parse failed: " + err.message; this.message += "\nYou may need an appropriate loader to handle this file type."; if(err.loc && typeof err.loc === "object" && typeof err.loc.line === "number") { var lineNumber = err.loc.line; diff --git a/node_modules/webpack/lib/OptionsDefaulter.js b/node_modules/webpack/lib/OptionsDefaulter.js index ee681b5a9..42120689d 100644 --- a/node_modules/webpack/lib/OptionsDefaulter.js +++ b/node_modules/webpack/lib/OptionsDefaulter.js @@ -6,7 +6,7 @@ function getProperty(obj, name) { name = name.split("."); - for(var i = 0; i < name.length - 1; i++) { + for(let i = 0; i < name.length - 1; i++) { obj = obj[name[i]]; if(typeof obj !== "object" || !obj) return; } @@ -15,7 +15,7 @@ function getProperty(obj, name) { function setProperty(obj, name, value) { name = name.split("."); - for(var i = 0; i < name.length - 1; i++) { + for(let i = 0; i < name.length - 1; i++) { if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return; if(!obj[name[i]]) obj[name[i]] = {}; obj = obj[name[i]]; diff --git a/node_modules/webpack/lib/SourceMapDevToolPlugin.js b/node_modules/webpack/lib/SourceMapDevToolPlugin.js index 7892cb8ac..e63f34afb 100644 --- a/node_modules/webpack/lib/SourceMapDevToolPlugin.js +++ b/node_modules/webpack/lib/SourceMapDevToolPlugin.js @@ -158,7 +158,7 @@ class SourceMapDevToolPlugin { const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m)); sourceMap.sources = moduleFilenames; if(sourceMap.sourcesContent && !options.noSources) { - sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`); + sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}` : null); } else { sourceMap.sourcesContent = undefined; } @@ -181,14 +181,14 @@ class SourceMapDevToolPlugin { } let sourceMapFile = compilation.getPath(sourceMapFilename, { chunk, - filename, + filename: options.fileContext ? path.relative(options.fileContext, filename) : filename, query, basename: basename(filename) }); if(sourceMapFile.indexOf("[contenthash]") !== -1) { sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex")); } - const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/"); + const sourceMapUrl = options.publicPath ? options.publicPath + sourceMapFile.replace(/\\/g, "/") : path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/"); if(currentSourceMappingURLComment !== false) { asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl)); } diff --git a/node_modules/webpack/lib/Stats.js b/node_modules/webpack/lib/Stats.js index 16c191714..6aa3d1ac9 100644 --- a/node_modules/webpack/lib/Stats.js +++ b/node_modules/webpack/lib/Stats.js @@ -100,6 +100,7 @@ class Stats { const requestShortener = new RequestShortener(context); const showPerformance = optionOrLocalFallback(options.performance, true); const showHash = optionOrLocalFallback(options.hash, true); + const showEnv = optionOrLocalFallback(options.env, false); const showVersion = optionOrLocalFallback(options.version, true); const showTimings = optionOrLocalFallback(options.timings, true); const showAssets = optionOrLocalFallback(options.assets, true); @@ -198,15 +199,22 @@ class Stats { text += e.message; if(showErrorDetails && e.details) text += `\n${e.details}`; if(showErrorDetails && e.missing) text += e.missing.map(item => `\n[${item}]`).join(""); - if(showModuleTrace && e.dependencies && e.origin) { + if(showModuleTrace && e.origin) { text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`; - e.dependencies.forEach(dep => { - if(!dep.loc) return; - if(typeof dep.loc === "string") return; - const locInfo = formatLocation(dep.loc); - if(!locInfo) return; - text += ` ${locInfo}`; - }); + if(typeof e.originLoc === "object") { + const locInfo = formatLocation(e.originLoc); + if(locInfo) + text += ` ${locInfo}`; + } + if(e.dependencies) { + e.dependencies.forEach(dep => { + if(!dep.loc) return; + if(typeof dep.loc === "string") return; + const locInfo = formatLocation(dep.loc); + if(!locInfo) return; + text += ` ${locInfo}`; + }); + } let current = e.origin; while(current.issuer) { current = current.issuer; @@ -240,6 +248,11 @@ class Stats { if(showTimings && this.startTime && this.endTime) { obj.time = this.endTime - this.startTime; } + + if(showEnv && options._env) { + obj.env = options._env; + } + if(compilation.needAdditionalPass) { obj.needAdditionalPass = true; } @@ -546,6 +559,11 @@ class Stats { colors.normal("ms"); newline(); } + if(obj.env) { + colors.normal("Environment (--env): "); + colors.bold(JSON.stringify(obj.env, null, 2)); + newline(); + } if(obj.publicPath) { colors.normal("PublicPath: "); colors.bold(obj.publicPath); @@ -900,6 +918,7 @@ class Stats { chunkModules: true, chunkOrigins: true, depth: true, + env: true, reasons: true, usedExports: true, providedExports: true, diff --git a/node_modules/webpack/lib/UmdMainTemplatePlugin.js b/node_modules/webpack/lib/UmdMainTemplatePlugin.js index 6f44e892e..cc5179692 100644 --- a/node_modules/webpack/lib/UmdMainTemplatePlugin.js +++ b/node_modules/webpack/lib/UmdMainTemplatePlugin.js @@ -171,7 +171,7 @@ class UmdMainTemplatePlugin { " for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" + " }\n" ) + - "})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})"); + "})(typeof self !== 'undefined' ? self : this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})"); }); mainTemplate.plugin("global-hash-paths", (paths) => { if(this.names.root) paths = paths.concat(this.names.root); diff --git a/node_modules/webpack/lib/WebpackOptionsDefaulter.js b/node_modules/webpack/lib/WebpackOptionsDefaulter.js index ff0cc8072..385578f50 100644 --- a/node_modules/webpack/lib/WebpackOptionsDefaulter.js +++ b/node_modules/webpack/lib/WebpackOptionsDefaulter.js @@ -1,129 +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", "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; +/* + 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/WebpackOptionsValidationError.js b/node_modules/webpack/lib/WebpackOptionsValidationError.js index 61cb99bd7..4fa72d19b 100644 --- a/node_modules/webpack/lib/WebpackOptionsValidationError.js +++ b/node_modules/webpack/lib/WebpackOptionsValidationError.js @@ -35,10 +35,21 @@ const getSchemaPartText = (schemaPart, additionalPath) => { while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref); let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart); if(schemaPart.description) - schemaText += `\n${schemaPart.description}`; + schemaText += `\n-> ${schemaPart.description}`; return schemaText; }; +const getSchemaPartDescription = schemaPart => { + while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref); + if(schemaPart.description) + return `\n-> ${schemaPart.description}`; + return ""; +}; + +const filterChildren = children => { + return children.filter(err => err.keyword !== "anyOf" && err.keyword !== "allOf" && err.keyword !== "oneOf"); +}; + const indent = (str, prefix, firstLine) => { if(firstLine) { return prefix + str.replace(/\n(?!$)/g, "\n" + prefix); @@ -143,8 +154,16 @@ class WebpackOptionsValidationError extends WebpackError { return baseMessage; } else if(err.keyword === "oneOf" || err.keyword === "anyOf") { if(err.children && err.children.length > 0) { + if(err.schema.length === 1) { + const lastChild = err.children[err.children.length - 1]; + const remainingChildren = err.children.slice(0, err.children.length - 1); + return WebpackOptionsValidationError.formatValidationError(Object.assign({}, lastChild, { + children: remainingChildren, + parentSchema: Object.assign({}, err.parentSchema, lastChild.parentSchema) + })); + } return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` + - `Details:\n${err.children.map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`; + `Details:\n${filterChildren(err.children).map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`; } return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; @@ -158,29 +177,33 @@ class WebpackOptionsValidationError extends WebpackError { } else if(err.keyword === "type") { switch(err.params.type) { case "object": - return `${dataPath} should be an object.`; + return `${dataPath} should be an object.${getSchemaPartDescription(err.parentSchema)}`; case "string": - return `${dataPath} should be a string.`; + return `${dataPath} should be a string.${getSchemaPartDescription(err.parentSchema)}`; case "boolean": - return `${dataPath} should be a boolean.`; + return `${dataPath} should be a boolean.${getSchemaPartDescription(err.parentSchema)}`; case "number": - return `${dataPath} should be a number.`; + return `${dataPath} should be a number.${getSchemaPartDescription(err.parentSchema)}`; case "array": return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`; } return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`; } else if(err.keyword === "instanceof") { - return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`; + return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}`; } else if(err.keyword === "required") { const missingProperty = err.params.missingProperty.replace(/^\./, ""); return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ["properties", missingProperty])}`; - } else if(err.keyword === "minLength" || err.keyword === "minItems") { + } else if(err.keyword === "minimum") { + return `${dataPath} ${err.message}.${getSchemaPartDescription(err.parentSchema)}`; + } else if(err.keyword === "uniqueItems") { + return `${dataPath} should not contain the item '${err.data[err.params.i]}' twice.${getSchemaPartDescription(err.parentSchema)}`; + } else if(err.keyword === "minLength" || err.keyword === "minItems" || err.keyword === "minProperties") { if(err.params.limit === 1) - return `${dataPath} should not be empty.`; + return `${dataPath} should not be empty.${getSchemaPartDescription(err.parentSchema)}`; else - return `${dataPath} ${err.message}`; + return `${dataPath} ${err.message}${getSchemaPartDescription(err.parentSchema)}`; } else if(err.keyword === "absolutePath") { - const baseMessage = `${dataPath}: ${err.message}`; + const baseMessage = `${dataPath}: ${err.message}${getSchemaPartDescription(err.parentSchema)}`; if(dataPath === "configuration.output.filename") { return `${baseMessage}\n` + "Please use output.path to specify absolute path and output.filename for the file name."; diff --git a/node_modules/webpack/lib/dependencies/AMDDefineDependency.js b/node_modules/webpack/lib/dependencies/AMDDefineDependency.js index 7d81ec123..f290326e9 100644 --- a/node_modules/webpack/lib/dependencies/AMDDefineDependency.js +++ b/node_modules/webpack/lib/dependencies/AMDDefineDependency.js @@ -25,7 +25,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate { return { f: [ "var __WEBPACK_AMD_DEFINE_RESULT__;", - `!(__WEBPACK_AMD_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module), + `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))` ], o: [ @@ -42,7 +42,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate { ], af: [ "var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;", - `!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), + `!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = (#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))` ], ao: [ @@ -70,7 +70,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate { ], laf: [ "var __WEBPACK_AMD_DEFINE_ARRAY__, XXX;", - "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = (#.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))" + "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = ((#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))" ], lao: [ "var XXX;", diff --git a/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js index b8a4668df..227f68d36 100644 --- a/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/AMDDefineDependencyParserPlugin.js @@ -23,6 +23,18 @@ function isBoundFunctionExpression(expr) { return true; } +function isUnboundFunctionExpression(expr) { + if(expr.type === "FunctionExpression") return true; + if(expr.type === "ArrowFunctionExpression") return true; + return false; +} + +function isCallable(expr) { + if(isUnboundFunctionExpression(expr)) return true; + if(isBoundFunctionExpression(expr)) return true; + return false; +} + class AMDDefineDependencyParserPlugin { constructor(options) { this.options = options; @@ -38,7 +50,7 @@ class AMDDefineDependencyParserPlugin { let array, fn, obj, namedModule; switch(expr.arguments.length) { case 1: - if(expr.arguments[0].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[0])) { + if(isCallable(expr.arguments[0])) { // define(f() {...}) fn = expr.arguments[0]; } else if(expr.arguments[0].type === "ObjectExpression") { @@ -54,7 +66,7 @@ class AMDDefineDependencyParserPlugin { if(expr.arguments[0].type === "Literal") { namedModule = expr.arguments[0].value; // define("...", ...) - if(expr.arguments[1].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[1])) { + if(isCallable(expr.arguments[1])) { // define("...", f() {...}) fn = expr.arguments[1]; } else if(expr.arguments[1].type === "ObjectExpression") { @@ -67,7 +79,7 @@ class AMDDefineDependencyParserPlugin { } } else { array = expr.arguments[0]; - if(expr.arguments[1].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[1])) { + if(isCallable(expr.arguments[1])) { // define([...], f() {}) fn = expr.arguments[1]; } else if(expr.arguments[1].type === "ObjectExpression") { @@ -84,7 +96,7 @@ class AMDDefineDependencyParserPlugin { // define("...", [...], f() {...}) namedModule = expr.arguments[0].value; array = expr.arguments[1]; - if(expr.arguments[2].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[2])) { + if(isCallable(expr.arguments[2])) { // define("...", [...], f() {}) fn = expr.arguments[2]; } else if(expr.arguments[2].type === "ObjectExpression") { @@ -102,7 +114,7 @@ class AMDDefineDependencyParserPlugin { let fnParams = null; let fnParamsOffset = 0; if(fn) { - if(fn.type === "FunctionExpression") fnParams = fn.params; + if(isUnboundFunctionExpression(fn)) fnParams = fn.params; else if(isBoundFunctionExpression(fn)) { fnParams = fn.callee.object.params; fnParamsOffset = fn.arguments.length - 1; @@ -134,7 +146,7 @@ class AMDDefineDependencyParserPlugin { }); } let inTry; - if(fn && fn.type === "FunctionExpression") { + if(fn && isUnboundFunctionExpression(fn)) { inTry = parser.scope.inTry; parser.inScope(fnParams, () => { parser.scope.renames = fnRenames; diff --git a/node_modules/webpack/lib/dependencies/AMDRequireDependency.js b/node_modules/webpack/lib/dependencies/AMDRequireDependency.js index 6cfaa2de2..aa5b04a32 100644 --- a/node_modules/webpack/lib/dependencies/AMDRequireDependency.js +++ b/node_modules/webpack/lib/dependencies/AMDRequireDependency.js @@ -44,8 +44,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate { source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock); source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = "); - source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ("); - source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));"); + source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (("); + source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));"); source.replace(depBlock.functionRange[1], depBlock.errorCallbackRange[0] - 1, errorRangeBlock); source.replace(depBlock.errorCallbackRange[1], depBlock.outerRange[1] - 1, endBlock); return; @@ -57,8 +57,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate { const endBlock = `}${depBlock.functionBindThis ? ".bind(this)" : ""}${wrapper[1]}__webpack_require__.oe${wrapper[2]}`; source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock); source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = "); - source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ("); - source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));"); + source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (("); + source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));"); source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, endBlock); } } diff --git a/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js b/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js index 59eceecd8..4de7afb58 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/HarmonyDetectionParserPlugin.js @@ -9,7 +9,7 @@ const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency module.exports = class HarmonyDetectionParserPlugin { apply(parser) { parser.plugin("program", (ast) => { - var isHarmony = ast.body.some(statement => { + const isHarmony = ast.body.some(statement => { return /^(Import|Export).*Declaration$/.test(statement.type); }); if(isHarmony) { @@ -32,7 +32,7 @@ module.exports = class HarmonyDetectionParserPlugin { module.exportsArgument = "__webpack_exports__"; } }); - var nonHarmonyIdentifiers = ["define", "exports"]; + const nonHarmonyIdentifiers = ["define", "exports"]; nonHarmonyIdentifiers.forEach(identifer => { parser.plugin(`evaluate typeof ${identifer}`, nullInHarmony); parser.plugin(`typeof ${identifer}`, skipInHarmony); diff --git a/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js b/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js index f20b3cee2..d31ef2dc8 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js +++ b/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js @@ -3,7 +3,7 @@ Author Tobias Koppers @sokra */ "use strict"; -var ModuleDependency = require("./ModuleDependency"); +const ModuleDependency = require("./ModuleDependency"); class HarmonyImportDependency extends ModuleDependency { constructor(request, importedVar, range) { diff --git a/node_modules/webpack/lib/dependencies/LocalModulesHelpers.js b/node_modules/webpack/lib/dependencies/LocalModulesHelpers.js index 4e2301e16..0742f6cd4 100644 --- a/node_modules/webpack/lib/dependencies/LocalModulesHelpers.js +++ b/node_modules/webpack/lib/dependencies/LocalModulesHelpers.js @@ -14,8 +14,8 @@ const lookup = (parent, mod) => { segs = mod.split("/"); path.pop(); - for(var i = 0; i < segs.length; i++) { - var seg = segs[i]; + for(let i = 0; i < segs.length; i++) { + const seg = segs[i]; if(seg === "..") path.pop(); else if(seg !== ".") path.push(seg); } @@ -25,7 +25,7 @@ const lookup = (parent, mod) => { LocalModulesHelpers.addLocalModule = (state, name) => { if(!state.localModules) state.localModules = []; - var m = new LocalModule(state.module, name, state.localModules.length); + const m = new LocalModule(state.module, name, state.localModules.length); state.localModules.push(m); return m; }; @@ -36,7 +36,7 @@ LocalModulesHelpers.getLocalModule = (state, name, namedModule) => { // resolve dependency name relative to the defining named module name = lookup(namedModule, name); } - for(var i = 0; i < state.localModules.length; i++) { + for(let i = 0; i < state.localModules.length; i++) { if(state.localModules[i].name === name) return state.localModules[i]; } diff --git a/node_modules/webpack/lib/dependencies/RequireIncludeDependency.js b/node_modules/webpack/lib/dependencies/RequireIncludeDependency.js index 474e3696f..1c7829990 100644 --- a/node_modules/webpack/lib/dependencies/RequireIncludeDependency.js +++ b/node_modules/webpack/lib/dependencies/RequireIncludeDependency.js @@ -11,6 +11,14 @@ class RequireIncludeDependency extends ModuleDependency { this.range = range; } + getReference() { + if(!this.module) return null; + return { + module: this.module, + importedNames: [] // This doesn't use any export + }; + } + get type() { return "require.include"; } diff --git a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js index ab7b69f4a..c0e438a40 100644 --- a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js +++ b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js @@ -107,7 +107,7 @@ You can however specify the name of the async chunk by passing the desired strin /** * These chunks are subject to get "common" modules extracted and moved to the common chunk */ - const affectedChunks = this.getAffectedChunks(compilation, chunks, targetChunk, targetChunks, idx, this.selectedChunks, this.async, this.children); + const affectedChunks = this.getAffectedChunks(compilation, chunks, targetChunk, targetChunks, idx, this.selectedChunks, this.async, this.children, this.deepChildren); // bail if no chunk is affected if(!affectedChunks) { @@ -214,7 +214,7 @@ 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) { + getAffectedUnnamedChunks(affectedChunks, targetChunk, rootChunk, asyncOption, deepChildrenOption) { let chunks = targetChunk.chunks; chunks && chunks.forEach((chunk) => { if(chunk.isInitial()) { @@ -225,11 +225,11 @@ Take a look at the "name"/"names" or async/children option.`); // 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))) { + if(asyncOption || chunk.parents.every((parentChunk) => parentChunk === rootChunk || 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) { + if(!affectedChunks.has(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 + // have the information of this chunk being affected for their assertion if a chunk should // not be affected affectedChunks.add(chunk); @@ -237,16 +237,16 @@ Take a look at the "name"/"names" or async/children option.`); // 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); + if(deepChildrenOption === true) { + this.getAffectedUnnamedChunks(affectedChunks, chunk, rootChunk, asyncOption, deepChildrenOption); } } } }); } - getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, children) { - const asyncOrNoSelectedChunk = children || asyncOption; + getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, childrenOption, deepChildrenOption) { + const asyncOrNoSelectedChunk = childrenOption || asyncOption; if(Array.isArray(selectedChunks)) { return allChunks.filter(chunk => { @@ -258,7 +258,7 @@ Take a look at the "name"/"names" or async/children option.`); if(asyncOrNoSelectedChunk) { let affectedChunks = new Set(); - this.getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption); + this.getAffectedUnnamedChunks(affectedChunks, targetChunk, targetChunk, asyncOption, deepChildrenOption); return Array.from(affectedChunks); } diff --git a/node_modules/webpack/lib/optimize/ConcatenatedModule.js b/node_modules/webpack/lib/optimize/ConcatenatedModule.js index 8b201009a..bfb772496 100644 --- a/node_modules/webpack/lib/optimize/ConcatenatedModule.js +++ b/node_modules/webpack/lib/optimize/ConcatenatedModule.js @@ -7,6 +7,7 @@ const Module = require("../Module"); const Template = require("../Template"); const Parser = require("../Parser"); +const crypto = require("crypto"); const acorn = require("acorn"); const escope = require("escope"); const ReplaceSource = require("webpack-sources/lib/ReplaceSource"); @@ -210,6 +211,7 @@ class ConcatenatedModule extends Module { Object.assign(this.assets, m.assets); } } + this._identifier = this._createIdentifier(); } get modules() { @@ -219,12 +221,7 @@ class ConcatenatedModule extends Module { } identifier() { - return this._orderedConcatenationList.map(info => { - switch(info.type) { - case "concatenated": - return info.module.identifier(); - } - }).filter(Boolean).join(" "); + return this._identifier; } readableIdentifier(requestShortener) { @@ -297,6 +294,19 @@ class ConcatenatedModule extends Module { return list; } + _createIdentifier() { + let orderedConcatenationListIdentifiers = ""; + for(let i = 0; i < this._orderedConcatenationList.length; i++) { + if(this._orderedConcatenationList[i].type === "concatenated") { + orderedConcatenationListIdentifiers += this._orderedConcatenationList[i].module.identifier(); + orderedConcatenationListIdentifiers += " "; + } + } + const hash = crypto.createHash("md5"); + hash.update(orderedConcatenationListIdentifiers); + return this.rootModule.identifier() + " " + hash.digest("hex"); + } + source(dependencyTemplates, outputOptions, requestShortener) { // Metainfo for each module const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => { diff --git a/node_modules/webpack/lib/util/Queue.js b/node_modules/webpack/lib/util/Queue.js new file mode 100644 index 000000000..ef3ffdc80 --- /dev/null +++ b/node_modules/webpack/lib/util/Queue.js @@ -0,0 +1,42 @@ +"use strict"; + +module.exports = class Queue { + constructor(items) { + this.first = null; + this.last = null; + this.length = 0; + if(items) { + for(const item of items) { + this.enqueue(item); + } + } + } + + enqueue(item) { + const first = this.first; + const node = { + item, + next: null + }; + if(first === null) { + this.last = node; + } else { + first.next = node; + } + this.first = node; + this.length++; + } + + dequeue() { + const last = this.last; + if(last === null) + return undefined; + const next = last.next; + if(next === null) { + this.first = null; + } + this.last = next; + this.length--; + return last.item; + } +}; diff --git a/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js b/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js index cc7615497..ff2d6c2f5 100644 --- a/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js +++ b/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js @@ -82,8 +82,8 @@ class WebWorkerMainTemplatePlugin { }); return source + "\n" + - `var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];\n` + - `this[${JSON.stringify(hotUpdateFunction)}] = ` + + `var parentHotUpdateCallback = self[${JSON.stringify(hotUpdateFunction)}];\n` + + `self[${JSON.stringify(hotUpdateFunction)}] = ` + Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js")) .replace(/\/\/\$semicolon/g, ";") .replace(/\$require\$/g, this.requireFn) -- cgit v1.2.3