aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/node
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/webpack/lib/node
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/webpack/lib/node')
-rw-r--r--node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js58
-rw-r--r--node_modules/webpack/lib/node/NodeEnvironmentPlugin.js53
-rw-r--r--node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js63
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplate.runtime.js51
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js84
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplatePlugin.js504
-rw-r--r--node_modules/webpack/lib/node/NodeOutputFileSystem.js44
-rw-r--r--node_modules/webpack/lib/node/NodeSourcePlugin.js232
-rw-r--r--node_modules/webpack/lib/node/NodeTargetPlugin.js34
-rw-r--r--node_modules/webpack/lib/node/NodeTemplatePlugin.js58
-rw-r--r--node_modules/webpack/lib/node/NodeWatchFileSystem.js171
11 files changed, 802 insertions, 550 deletions
diff --git a/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js b/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js
index dd5e0e354..292182a97 100644
--- a/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js
+++ b/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js
@@ -1,27 +1,31 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-
-"use strict";
-
-const ConcatSource = require("webpack-sources").ConcatSource;
-
-class NodeChunkTemplatePlugin {
-
- apply(chunkTemplate) {
- chunkTemplate.plugin("render", function(modules, chunk) {
- const source = new ConcatSource();
- source.add(`exports.ids = ${JSON.stringify(chunk.ids)};\nexports.modules = `);
- source.add(modules);
- source.add(";");
- return source;
- });
- chunkTemplate.plugin("hash", function(hash) {
- hash.update("node");
- hash.update("3");
- });
- }
-}
-
-module.exports = NodeChunkTemplatePlugin;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const { ConcatSource } = require("webpack-sources");
+
+class NodeChunkTemplatePlugin {
+ apply(chunkTemplate) {
+ chunkTemplate.hooks.render.tap(
+ "NodeChunkTemplatePlugin",
+ (modules, chunk) => {
+ const source = new ConcatSource();
+ source.add(
+ `exports.ids = ${JSON.stringify(chunk.ids)};\nexports.modules = `
+ );
+ source.add(modules);
+ source.add(";");
+ return source;
+ }
+ );
+ chunkTemplate.hooks.hash.tap("NodeChunkTemplatePlugin", hash => {
+ hash.update("node");
+ hash.update("3");
+ });
+ }
+}
+
+module.exports = NodeChunkTemplatePlugin;
diff --git a/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js b/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
index b8200a3ca..3f76bffa5 100644
--- a/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
+++ b/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
@@ -1,25 +1,28 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const NodeWatchFileSystem = require("./NodeWatchFileSystem");
-const NodeOutputFileSystem = require("./NodeOutputFileSystem");
-const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
-const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
-
-class NodeEnvironmentPlugin {
- apply(compiler) {
- compiler.inputFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 60000);
- const inputFileSystem = compiler.inputFileSystem;
- compiler.outputFileSystem = new NodeOutputFileSystem();
- compiler.watchFileSystem = new NodeWatchFileSystem(compiler.inputFileSystem);
- compiler.plugin("before-run", (compiler, callback) => {
- if(compiler.inputFileSystem === inputFileSystem)
- inputFileSystem.purge();
- callback();
- });
- }
-}
-module.exports = NodeEnvironmentPlugin;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const NodeWatchFileSystem = require("./NodeWatchFileSystem");
+const NodeOutputFileSystem = require("./NodeOutputFileSystem");
+const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
+const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
+
+class NodeEnvironmentPlugin {
+ apply(compiler) {
+ compiler.inputFileSystem = new CachedInputFileSystem(
+ new NodeJsInputFileSystem(),
+ 60000
+ );
+ const inputFileSystem = compiler.inputFileSystem;
+ compiler.outputFileSystem = new NodeOutputFileSystem();
+ compiler.watchFileSystem = new NodeWatchFileSystem(
+ compiler.inputFileSystem
+ );
+ compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
+ if (compiler.inputFileSystem === inputFileSystem) inputFileSystem.purge();
+ });
+ }
+}
+module.exports = NodeEnvironmentPlugin;
diff --git a/node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js b/node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js
index 52239f7b6..bbd2e12a6 100644
--- a/node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js
+++ b/node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js
@@ -1,27 +1,36 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const ConcatSource = require("webpack-sources").ConcatSource;
-
-class NodeHotUpdateChunkTemplatePlugin {
-
- apply(hotUpdateChunkTemplate) {
- hotUpdateChunkTemplate.plugin("render", (modulesSource, modules, removedModules, hash, id) => {
- const source = new ConcatSource();
- source.add("exports.id = " + JSON.stringify(id) + ";\nexports.modules = ");
- source.add(modulesSource);
- source.add(";");
- return source;
- });
- hotUpdateChunkTemplate.plugin("hash", function(hash) {
- hash.update("NodeHotUpdateChunkTemplatePlugin");
- hash.update("3");
- hash.update(this.outputOptions.hotUpdateFunction + "");
- hash.update(this.outputOptions.library + "");
- });
- }
-}
-module.exports = NodeHotUpdateChunkTemplatePlugin;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const { ConcatSource } = require("webpack-sources");
+
+class NodeHotUpdateChunkTemplatePlugin {
+ apply(hotUpdateChunkTemplate) {
+ hotUpdateChunkTemplate.hooks.render.tap(
+ "NodeHotUpdateChunkTemplatePlugin",
+ (modulesSource, modules, removedModules, hash, id) => {
+ const source = new ConcatSource();
+ source.add(
+ "exports.id = " + JSON.stringify(id) + ";\nexports.modules = "
+ );
+ source.add(modulesSource);
+ source.add(";");
+ return source;
+ }
+ );
+ hotUpdateChunkTemplate.hooks.hash.tap(
+ "NodeHotUpdateChunkTemplatePlugin",
+ hash => {
+ hash.update("NodeHotUpdateChunkTemplatePlugin");
+ hash.update("3");
+ hash.update(
+ hotUpdateChunkTemplate.outputOptions.hotUpdateFunction + ""
+ );
+ hash.update(hotUpdateChunkTemplate.outputOptions.library + "");
+ }
+ );
+ }
+}
+module.exports = NodeHotUpdateChunkTemplatePlugin;
diff --git a/node_modules/webpack/lib/node/NodeMainTemplate.runtime.js b/node_modules/webpack/lib/node/NodeMainTemplate.runtime.js
index 2725e2e79..d34388bf7 100644
--- a/node_modules/webpack/lib/node/NodeMainTemplate.runtime.js
+++ b/node_modules/webpack/lib/node/NodeMainTemplate.runtime.js
@@ -1,24 +1,27 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-/*global installedChunks $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
-module.exports = function() {
- function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
- var chunk = require("./" + $hotChunkFilename$);
- hotAddUpdateChunk(chunk.id, chunk.modules);
- }
-
- function hotDownloadManifest() { // eslint-disable-line no-unused-vars
- try {
- var update = require("./" + $hotMainFilename$);
- } catch(e) {
- return Promise.resolve();
- }
- return Promise.resolve(update);
- }
-
- function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars
- delete installedChunks[chunkId];
- }
-};
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+/*global installedChunks $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
+module.exports = function() {
+ // eslint-disable-next-line no-unused-vars
+ function hotDownloadUpdateChunk(chunkId) {
+ var chunk = require("./" + $hotChunkFilename$);
+ hotAddUpdateChunk(chunk.id, chunk.modules);
+ }
+
+ // eslint-disable-next-line no-unused-vars
+ function hotDownloadManifest() {
+ try {
+ var update = require("./" + $hotMainFilename$);
+ } catch (e) {
+ return Promise.resolve();
+ }
+ return Promise.resolve(update);
+ }
+
+ //eslint-disable-next-line no-unused-vars
+ function hotDisposeChunk(chunkId) {
+ delete installedChunks[chunkId];
+ }
+};
diff --git a/node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js b/node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js
index 673cfafd0..35eb47b66 100644
--- a/node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js
+++ b/node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js
@@ -1,40 +1,44 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-/*global installedChunks $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
-module.exports = function() {
- function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
- var filename = require("path").join(__dirname, $hotChunkFilename$);
- require("fs").readFile(filename, "utf-8", function(err, content) {
- if(err) {
- if($require$.onError)
- return $require$.oe(err);
- else
- throw err;
- }
- var chunk = {};
- require("vm").runInThisContext("(function(exports) {" + content + "\n})", filename)(chunk);
- hotAddUpdateChunk(chunk.id, chunk.modules);
- });
- }
-
- function hotDownloadManifest() { // eslint-disable-line no-unused-vars
- var filename = require("path").join(__dirname, $hotMainFilename$);
- return new Promise(function(resolve, reject) {
- require("fs").readFile(filename, "utf-8", function(err, content) {
- if(err) return resolve();
- try {
- var update = JSON.parse(content);
- } catch(e) {
- return reject(e);
- }
- resolve(update);
- });
- });
- }
-
- function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars
- delete installedChunks[chunkId];
- }
-};
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+/*global installedChunks $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
+module.exports = function() {
+ // eslint-disable-next-line no-unused-vars
+ function hotDownloadUpdateChunk(chunkId) {
+ var filename = require("path").join(__dirname, $hotChunkFilename$);
+ require("fs").readFile(filename, "utf-8", function(err, content) {
+ if (err) {
+ if ($require$.onError) return $require$.oe(err);
+ throw err;
+ }
+ var chunk = {};
+ require("vm").runInThisContext(
+ "(function(exports) {" + content + "\n})",
+ { filename: filename }
+ )(chunk);
+ hotAddUpdateChunk(chunk.id, chunk.modules);
+ });
+ }
+
+ // eslint-disable-next-line no-unused-vars
+ function hotDownloadManifest() {
+ var filename = require("path").join(__dirname, $hotMainFilename$);
+ return new Promise(function(resolve, reject) {
+ require("fs").readFile(filename, "utf-8", function(err, content) {
+ if (err) return resolve();
+ try {
+ var update = JSON.parse(content);
+ } catch (e) {
+ return reject(e);
+ }
+ resolve(update);
+ });
+ });
+ }
+
+ // eslint-disable-next-line no-unused-vars
+ function hotDisposeChunk(chunkId) {
+ delete installedChunks[chunkId];
+ }
+};
diff --git a/node_modules/webpack/lib/node/NodeMainTemplatePlugin.js b/node_modules/webpack/lib/node/NodeMainTemplatePlugin.js
index 9a64b57b5..a27029699 100644
--- a/node_modules/webpack/lib/node/NodeMainTemplatePlugin.js
+++ b/node_modules/webpack/lib/node/NodeMainTemplatePlugin.js
@@ -1,183 +1,321 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const Template = require("../Template");
-
-module.exports = class NodeMainTemplatePlugin {
- constructor(asyncChunkLoading) {
- this.asyncChunkLoading = asyncChunkLoading;
- }
-
- apply(mainTemplate) {
- const asyncChunkLoading = this.asyncChunkLoading;
- mainTemplate.plugin("local-vars", function(source, chunk) {
- if(chunk.chunks.length > 0) {
- return this.asString([
- source,
- "",
- "// object to store loaded chunks",
- "// \"0\" means \"already loaded\"",
- "var installedChunks = {",
- this.indent(chunk.ids.map((id) => `${id}: 0`).join(",\n")),
- "};"
- ]);
- }
- return source;
- });
- mainTemplate.plugin("require-extensions", function(source, chunk) {
- if(chunk.chunks.length > 0) {
- return this.asString([
- source,
- "",
- "// uncatched error handler for webpack runtime",
- `${this.requireFn}.oe = function(err) {`,
- this.indent([
- "process.nextTick(function() {",
- this.indent("throw err; // catch this error by using System.import().catch()"),
- "});"
- ]),
- "};"
- ]);
- }
- return source;
- });
- mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
- const chunkFilename = this.outputOptions.chunkFilename;
- const chunkMaps = chunk.getChunkMaps();
- const insertMoreModules = [
- "var moreModules = chunk.modules, chunkIds = chunk.ids;",
- "for(var moduleId in moreModules) {",
- this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
- "}"
- ];
- if(asyncChunkLoading) {
- return this.asString([
- "// \"0\" is the signal for \"already loaded\"",
- "if(installedChunks[chunkId] === 0)",
- this.indent([
- "return Promise.resolve();"
- ]),
- "// array of [resolve, reject, promise] means \"currently loading\"",
- "if(installedChunks[chunkId])",
- this.indent([
- "return installedChunks[chunkId][2];"
- ]),
- "// load the chunk and return promise to it",
- "var promise = new Promise(function(resolve, reject) {",
- this.indent([
- "installedChunks[chunkId] = [resolve, reject];",
- "var filename = __dirname + " + this.applyPluginsWaterfall("asset-path", JSON.stringify(`/${chunkFilename}`), {
- hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
- hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
- chunk: {
- id: "\" + chunkId + \"",
- hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
- hashWithLength: (length) => {
- const shortChunkHashMap = {};
- Object.keys(chunkMaps.hash).forEach((chunkId) => {
- if(typeof chunkMaps.hash[chunkId] === "string")
- shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
- });
- return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
- },
- name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
- }
- }) + ";",
- "require('fs').readFile(filename, 'utf-8', function(err, content) {",
- this.indent([
- "if(err) return reject(err);",
- "var chunk = {};",
- "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
- "(chunk, require, require('path').dirname(filename), filename);"
- ].concat(insertMoreModules).concat([
- "var callbacks = [];",
- "for(var i = 0; i < chunkIds.length; i++) {",
- this.indent([
- "if(installedChunks[chunkIds[i]])",
- this.indent([
- "callbacks = callbacks.concat(installedChunks[chunkIds[i]][0]);"
- ]),
- "installedChunks[chunkIds[i]] = 0;"
- ]),
- "}",
- "for(i = 0; i < callbacks.length; i++)",
- this.indent("callbacks[i]();")
- ])),
- "});"
- ]),
- "});",
- "return installedChunks[chunkId][2] = promise;"
- ]);
- } else {
- const request = this.applyPluginsWaterfall("asset-path", JSON.stringify(`./${chunkFilename}`), {
- hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
- hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
- chunk: {
- id: "\" + chunkId + \"",
- hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
- hashWithLength: (length) => {
- const shortChunkHashMap = {};
- Object.keys(chunkMaps.hash).forEach((chunkId) => {
- if(typeof chunkMaps.hash[chunkId] === "string")
- shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
- });
- return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
- },
- name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
- }
- });
- return this.asString([
- "// \"0\" is the signal for \"already loaded\"",
- "if(installedChunks[chunkId] !== 0) {",
- this.indent([
- `var chunk = require(${request});`
- ].concat(insertMoreModules).concat([
- "for(var i = 0; i < chunkIds.length; i++)",
- this.indent("installedChunks[chunkIds[i]] = 0;")
- ])),
- "}",
- "return Promise.resolve();"
- ]);
- }
- });
- mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) {
- const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
- const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
- const chunkMaps = chunk.getChunkMaps();
- const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
- hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
- hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
- chunk: {
- id: "\" + chunkId + \"",
- hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
- hashWithLength: (length) => {
- const shortChunkHashMap = {};
- Object.keys(chunkMaps.hash).forEach((chunkId) => {
- if(typeof chunkMaps.hash[chunkId] === "string")
- shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
- });
- return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
- },
- name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
- }
- });
- const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
- hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
- hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`
- });
- return Template.getFunctionContent(asyncChunkLoading ? require("./NodeMainTemplateAsync.runtime.js") : require("./NodeMainTemplate.runtime.js"))
- .replace(/\$require\$/g, this.requireFn)
- .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
- .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename);
- });
- mainTemplate.plugin("hash", function(hash) {
- hash.update("node");
- hash.update("3");
- hash.update(this.outputOptions.filename + "");
- hash.update(this.outputOptions.chunkFilename + "");
- });
- }
-};
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const Template = require("../Template");
+
+module.exports = class NodeMainTemplatePlugin {
+ constructor(asyncChunkLoading) {
+ this.asyncChunkLoading = asyncChunkLoading;
+ }
+
+ apply(mainTemplate) {
+ const needChunkOnDemandLoadingCode = chunk => {
+ for (const chunkGroup of chunk.groupsIterable) {
+ if (chunkGroup.getNumberOfChildren() > 0) return true;
+ }
+ return false;
+ };
+ const asyncChunkLoading = this.asyncChunkLoading;
+ mainTemplate.hooks.localVars.tap(
+ "NodeMainTemplatePlugin",
+ (source, chunk) => {
+ if (needChunkOnDemandLoadingCode(chunk)) {
+ return Template.asString([
+ source,
+ "",
+ "// object to store loaded chunks",
+ '// "0" means "already loaded"',
+ "var installedChunks = {",
+ Template.indent(
+ chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
+ ),
+ "};"
+ ]);
+ }
+ return source;
+ }
+ );
+ mainTemplate.hooks.requireExtensions.tap(
+ "NodeMainTemplatePlugin",
+ (source, chunk) => {
+ if (needChunkOnDemandLoadingCode(chunk)) {
+ return Template.asString([
+ source,
+ "",
+ "// uncaught error handler for webpack runtime",
+ `${mainTemplate.requireFn}.oe = function(err) {`,
+ Template.indent([
+ "process.nextTick(function() {",
+ Template.indent(
+ "throw err; // catch this error by using import().catch()"
+ ),
+ "});"
+ ]),
+ "};"
+ ]);
+ }
+ return source;
+ }
+ );
+ mainTemplate.hooks.requireEnsure.tap(
+ "NodeMainTemplatePlugin",
+ (source, chunk, hash) => {
+ const chunkFilename = mainTemplate.outputOptions.chunkFilename;
+ const chunkMaps = chunk.getChunkMaps();
+ const insertMoreModules = [
+ "var moreModules = chunk.modules, chunkIds = chunk.ids;",
+ "for(var moduleId in moreModules) {",
+ Template.indent(
+ mainTemplate.renderAddModule(
+ hash,
+ chunk,
+ "moduleId",
+ "moreModules[moduleId]"
+ )
+ ),
+ "}"
+ ];
+ if (asyncChunkLoading) {
+ return Template.asString([
+ source,
+ "",
+ "// ReadFile + VM.run chunk loading for javascript",
+ "",
+ "var installedChunkData = installedChunks[chunkId];",
+ 'if(installedChunkData !== 0) { // 0 means "already installed".',
+ Template.indent([
+ '// array of [resolve, reject, promise] means "currently loading"',
+ "if(installedChunkData) {",
+ Template.indent(["promises.push(installedChunkData[2]);"]),
+ "} else {",
+ Template.indent([
+ "// load the chunk and return promise to it",
+ "var promise = new Promise(function(resolve, reject) {",
+ Template.indent([
+ "installedChunkData = installedChunks[chunkId] = [resolve, reject];",
+ "var filename = require('path').join(__dirname, " +
+ mainTemplate.getAssetPath(
+ JSON.stringify(`/${chunkFilename}`),
+ {
+ hash: `" + ${mainTemplate.renderCurrentHashCode(
+ hash
+ )} + "`,
+ hashWithLength: length =>
+ `" + ${mainTemplate.renderCurrentHashCode(
+ hash,
+ length
+ )} + "`,
+ chunk: {
+ id: '" + chunkId + "',
+ hash: `" + ${JSON.stringify(
+ chunkMaps.hash
+ )}[chunkId] + "`,
+ hashWithLength: length => {
+ const shortChunkHashMap = {};
+ for (const chunkId of Object.keys(chunkMaps.hash)) {
+ if (typeof chunkMaps.hash[chunkId] === "string") {
+ shortChunkHashMap[chunkId] = chunkMaps.hash[
+ chunkId
+ ].substr(0, length);
+ }
+ }
+ return `" + ${JSON.stringify(
+ shortChunkHashMap
+ )}[chunkId] + "`;
+ },
+ contentHash: {
+ javascript: `" + ${JSON.stringify(
+ chunkMaps.contentHash.javascript
+ )}[chunkId] + "`
+ },
+ contentHashWithLength: {
+ javascript: length => {
+ const shortContentHashMap = {};
+ const contentHash =
+ chunkMaps.contentHash.javascript;
+ for (const chunkId of Object.keys(contentHash)) {
+ if (typeof contentHash[chunkId] === "string") {
+ shortContentHashMap[chunkId] = contentHash[
+ chunkId
+ ].substr(0, length);
+ }
+ }
+ return `" + ${JSON.stringify(
+ shortContentHashMap
+ )}[chunkId] + "`;
+ }
+ },
+ name: `" + (${JSON.stringify(
+ chunkMaps.name
+ )}[chunkId]||chunkId) + "`
+ },
+ contentHashType: "javascript"
+ }
+ ) +
+ ");",
+ "require('fs').readFile(filename, 'utf-8', function(err, content) {",
+ Template.indent(
+ [
+ "if(err) return reject(err);",
+ "var chunk = {};",
+ "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
+ "(chunk, require, require('path').dirname(filename), filename);"
+ ]
+ .concat(insertMoreModules)
+ .concat([
+ "var callbacks = [];",
+ "for(var i = 0; i < chunkIds.length; i++) {",
+ Template.indent([
+ "if(installedChunks[chunkIds[i]])",
+ Template.indent([
+ "callbacks = callbacks.concat(installedChunks[chunkIds[i]][0]);"
+ ]),
+ "installedChunks[chunkIds[i]] = 0;"
+ ]),
+ "}",
+ "for(i = 0; i < callbacks.length; i++)",
+ Template.indent("callbacks[i]();")
+ ])
+ ),
+ "});"
+ ]),
+ "});",
+ "promises.push(installedChunkData[2] = promise);"
+ ]),
+ "}"
+ ]),
+ "}"
+ ]);
+ } else {
+ const request = mainTemplate.getAssetPath(
+ JSON.stringify(`./${chunkFilename}`),
+ {
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
+ hashWithLength: length =>
+ `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
+ chunk: {
+ id: '" + chunkId + "',
+ hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
+ hashWithLength: length => {
+ const shortChunkHashMap = {};
+ for (const chunkId of Object.keys(chunkMaps.hash)) {
+ if (typeof chunkMaps.hash[chunkId] === "string") {
+ shortChunkHashMap[chunkId] = chunkMaps.hash[
+ chunkId
+ ].substr(0, length);
+ }
+ }
+ return `" + ${JSON.stringify(
+ shortChunkHashMap
+ )}[chunkId] + "`;
+ },
+ contentHash: {
+ javascript: `" + ${JSON.stringify(
+ chunkMaps.contentHash.javascript
+ )}[chunkId] + "`
+ },
+ contentHashWithLength: {
+ javascript: length => {
+ const shortContentHashMap = {};
+ const contentHash = chunkMaps.contentHash.javascript;
+ for (const chunkId of Object.keys(contentHash)) {
+ if (typeof contentHash[chunkId] === "string") {
+ shortContentHashMap[chunkId] = contentHash[
+ chunkId
+ ].substr(0, length);
+ }
+ }
+ return `" + ${JSON.stringify(
+ shortContentHashMap
+ )}[chunkId] + "`;
+ }
+ },
+ name: `" + (${JSON.stringify(
+ chunkMaps.name
+ )}[chunkId]||chunkId) + "`
+ },
+ contentHashType: "javascript"
+ }
+ );
+ return Template.asString([
+ source,
+ "",
+ "// require() chunk loading for javascript",
+ "",
+ '// "0" is the signal for "already loaded"',
+ "if(installedChunks[chunkId] !== 0) {",
+ Template.indent(
+ [`var chunk = require(${request});`]
+ .concat(insertMoreModules)
+ .concat([
+ "for(var i = 0; i < chunkIds.length; i++)",
+ Template.indent("installedChunks[chunkIds[i]] = 0;")
+ ])
+ ),
+ "}"
+ ]);
+ }
+ }
+ );
+ mainTemplate.hooks.hotBootstrap.tap(
+ "NodeMainTemplatePlugin",
+ (source, chunk, hash) => {
+ const hotUpdateChunkFilename =
+ mainTemplate.outputOptions.hotUpdateChunkFilename;
+ const hotUpdateMainFilename =
+ mainTemplate.outputOptions.hotUpdateMainFilename;
+ const chunkMaps = chunk.getChunkMaps();
+ const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(
+ JSON.stringify(hotUpdateChunkFilename),
+ {
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
+ hashWithLength: length =>
+ `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
+ chunk: {
+ id: '" + chunkId + "',
+ hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
+ hashWithLength: length => {
+ const shortChunkHashMap = {};
+ for (const chunkId of Object.keys(chunkMaps.hash)) {
+ if (typeof chunkMaps.hash[chunkId] === "string") {
+ shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
+ 0,
+ length
+ );
+ }
+ }
+ return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
+ },
+ name: `" + (${JSON.stringify(
+ chunkMaps.name
+ )}[chunkId]||chunkId) + "`
+ }
+ }
+ );
+ const currentHotUpdateMainFilename = mainTemplate.getAssetPath(
+ JSON.stringify(hotUpdateMainFilename),
+ {
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
+ hashWithLength: length =>
+ `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
+ }
+ );
+ return Template.getFunctionContent(
+ asyncChunkLoading
+ ? require("./NodeMainTemplateAsync.runtime")
+ : require("./NodeMainTemplate.runtime")
+ )
+ .replace(/\$require\$/g, mainTemplate.requireFn)
+ .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
+ .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename);
+ }
+ );
+ mainTemplate.hooks.hash.tap("NodeMainTemplatePlugin", hash => {
+ hash.update("node");
+ hash.update("4");
+ });
+ }
+};
diff --git a/node_modules/webpack/lib/node/NodeOutputFileSystem.js b/node_modules/webpack/lib/node/NodeOutputFileSystem.js
index 5a6e328e1..2789b576a 100644
--- a/node_modules/webpack/lib/node/NodeOutputFileSystem.js
+++ b/node_modules/webpack/lib/node/NodeOutputFileSystem.js
@@ -1,22 +1,22 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const fs = require("fs");
-const path = require("path");
-const mkdirp = require("mkdirp");
-
-class NodeOutputFileSystem {
- constructor() {
- this.mkdirp = mkdirp;
- this.mkdir = fs.mkdir.bind(fs);
- this.rmdir = fs.rmdir.bind(fs);
- this.unlink = fs.unlink.bind(fs);
- this.writeFile = fs.writeFile.bind(fs);
- this.join = path.join.bind(path);
- }
-}
-
-module.exports = NodeOutputFileSystem;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const fs = require("fs");
+const path = require("path");
+const mkdirp = require("mkdirp");
+
+class NodeOutputFileSystem {
+ constructor() {
+ this.mkdirp = mkdirp;
+ this.mkdir = fs.mkdir.bind(fs);
+ this.rmdir = fs.rmdir.bind(fs);
+ this.unlink = fs.unlink.bind(fs);
+ this.writeFile = fs.writeFile.bind(fs);
+ this.join = path.join.bind(path);
+ }
+}
+
+module.exports = NodeOutputFileSystem;
diff --git a/node_modules/webpack/lib/node/NodeSourcePlugin.js b/node_modules/webpack/lib/node/NodeSourcePlugin.js
index 986160028..d5505f6f5 100644
--- a/node_modules/webpack/lib/node/NodeSourcePlugin.js
+++ b/node_modules/webpack/lib/node/NodeSourcePlugin.js
@@ -1,88 +1,144 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
-const ParserHelpers = require("../ParserHelpers");
-const nodeLibsBrowser = require("node-libs-browser");
-
-module.exports = class NodeSourcePlugin {
- constructor(options) {
- this.options = options;
- }
- apply(compiler) {
- const options = this.options;
- if(options === false) // allow single kill switch to turn off this plugin
- return;
-
- function getPathToModule(module, type) {
- if(type === true || (type === undefined && nodeLibsBrowser[module])) {
- if(!nodeLibsBrowser[module]) throw new Error(`No browser version for node.js core module ${module} available`);
- return nodeLibsBrowser[module];
- } else if(type === "mock") {
- return require.resolve(`node-libs-browser/mock/${module}`);
- } else if(type === "empty") {
- return require.resolve("node-libs-browser/mock/empty");
- } else return module;
- }
-
- function addExpression(parser, name, module, type, suffix) {
- suffix = suffix || "";
- parser.plugin(`expression ${name}`, function() {
- if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
- const mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));
- return ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);
- });
- }
-
- compiler.plugin("compilation", function(compilation, params) {
- params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
-
- if(parserOptions.node === false)
- return;
-
- let localOptions = options;
- if(parserOptions.node)
- localOptions = Object.assign({}, localOptions, parserOptions.node);
-
- if(localOptions.global) {
- parser.plugin("expression global", function() {
- const retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));
- return ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);
- });
- }
- if(localOptions.process) {
- const processType = localOptions.process;
- addExpression(parser, "process", "process", processType);
- }
- if(localOptions.console) {
- const consoleType = localOptions.console;
- addExpression(parser, "console", "console", consoleType);
- }
- const bufferType = localOptions.Buffer;
- if(bufferType) {
- addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
- }
- if(localOptions.setImmediate) {
- const setImmediateType = localOptions.setImmediate;
- addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
- addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
- }
- });
- });
- compiler.plugin("after-resolvers", (compiler) => {
- Object.keys(nodeLibsBrowser).forEach((lib) => {
- if(options[lib] !== false) {
- compiler.resolvers.normal.apply(
- new AliasPlugin("described-resolve", {
- name: lib,
- onlyModule: true,
- alias: getPathToModule(lib, options[lib])
- }, "resolve")
- );
- }
- });
- });
- }
-};
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
+const ParserHelpers = require("../ParserHelpers");
+const nodeLibsBrowser = require("node-libs-browser");
+
+module.exports = class NodeSourcePlugin {
+ constructor(options) {
+ this.options = options;
+ }
+ apply(compiler) {
+ const options = this.options;
+ if (options === false) {
+ // allow single kill switch to turn off this plugin
+ return;
+ }
+
+ const getPathToModule = (module, type) => {
+ if (type === true || (type === undefined && nodeLibsBrowser[module])) {
+ if (!nodeLibsBrowser[module]) {
+ throw new Error(
+ `No browser version for node.js core module ${module} available`
+ );
+ }
+ return nodeLibsBrowser[module];
+ } else if (type === "mock") {
+ return require.resolve(`node-libs-browser/mock/${module}`);
+ } else if (type === "empty") {
+ return require.resolve("node-libs-browser/mock/empty");
+ } else {
+ return module;
+ }
+ };
+
+ const addExpression = (parser, name, module, type, suffix) => {
+ suffix = suffix || "";
+ parser.hooks.expression.for(name).tap("NodeSourcePlugin", () => {
+ if (
+ parser.state.module &&
+ parser.state.module.resource === getPathToModule(module, type)
+ )
+ return;
+ const mockModule = ParserHelpers.requireFileAsExpression(
+ parser.state.module.context,
+ getPathToModule(module, type)
+ );
+ return ParserHelpers.addParsedVariableToModule(
+ parser,
+ name,
+ mockModule + suffix
+ );
+ });
+ };
+
+ compiler.hooks.compilation.tap(
+ "NodeSourcePlugin",
+ (compilation, { normalModuleFactory }) => {
+ const handler = (parser, parserOptions) => {
+ if (parserOptions.node === false) return;
+
+ let localOptions = options;
+ if (parserOptions.node) {
+ localOptions = Object.assign({}, localOptions, parserOptions.node);
+ }
+ if (localOptions.global) {
+ parser.hooks.expression
+ .for("global")
+ .tap("NodeSourcePlugin", () => {
+ const retrieveGlobalModule = ParserHelpers.requireFileAsExpression(
+ parser.state.module.context,
+ require.resolve("../../buildin/global")
+ );
+ return ParserHelpers.addParsedVariableToModule(
+ parser,
+ "global",
+ retrieveGlobalModule
+ );
+ });
+ }
+ if (localOptions.process) {
+ const processType = localOptions.process;
+ addExpression(parser, "process", "process", processType);
+ }
+ if (localOptions.console) {
+ const consoleType = localOptions.console;
+ addExpression(parser, "console", "console", consoleType);
+ }
+ const bufferType = localOptions.Buffer;
+ if (bufferType) {
+ addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
+ }
+ if (localOptions.setImmediate) {
+ const setImmediateType = localOptions.setImmediate;
+ addExpression(
+ parser,
+ "setImmediate",
+ "timers",
+ setImmediateType,
+ ".setImmediate"
+ );
+ addExpression(
+ parser,
+ "clearImmediate",
+ "timers",
+ setImmediateType,
+ ".clearImmediate"
+ );
+ }
+ };
+ normalModuleFactory.hooks.parser
+ .for("javascript/auto")
+ .tap("NodeSourcePlugin", handler);
+ normalModuleFactory.hooks.parser
+ .for("javascript/dynamic")
+ .tap("NodeSourcePlugin", handler);
+ normalModuleFactory.hooks.parser
+ .for("javascript/esm")
+ .tap("NodeSourcePlugin", handler);
+ }
+ );
+ compiler.hooks.afterResolvers.tap("NodeSourcePlugin", compiler => {
+ for (const lib of Object.keys(nodeLibsBrowser)) {
+ if (options[lib] !== false) {
+ compiler.resolverFactory.hooks.resolver
+ .for("normal")
+ .tap("NodeSourcePlugin", resolver => {
+ new AliasPlugin(
+ "described-resolve",
+ {
+ name: lib,
+ onlyModule: true,
+ alias: getPathToModule(lib, options[lib])
+ },
+ "resolve"
+ ).apply(resolver);
+ });
+ }
+ }
+ });
+ }
+};
diff --git a/node_modules/webpack/lib/node/NodeTargetPlugin.js b/node_modules/webpack/lib/node/NodeTargetPlugin.js
index 528a28570..b76b70690 100644
--- a/node_modules/webpack/lib/node/NodeTargetPlugin.js
+++ b/node_modules/webpack/lib/node/NodeTargetPlugin.js
@@ -1,15 +1,19 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const ExternalsPlugin = require("../ExternalsPlugin");
-
-class NodeTargetPlugin {
- apply(compiler) {
- new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
- }
-}
-
-module.exports = NodeTargetPlugin;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const ExternalsPlugin = require("../ExternalsPlugin");
+
+const builtins =
+ // eslint-disable-next-line node/no-unsupported-features/node-builtins
+ require("module").builtinModules || Object.keys(process.binding("natives"));
+
+class NodeTargetPlugin {
+ apply(compiler) {
+ new ExternalsPlugin("commonjs", builtins).apply(compiler);
+ }
+}
+
+module.exports = NodeTargetPlugin;
diff --git a/node_modules/webpack/lib/node/NodeTemplatePlugin.js b/node_modules/webpack/lib/node/NodeTemplatePlugin.js
index ed17d1937..cdb1076b9 100644
--- a/node_modules/webpack/lib/node/NodeTemplatePlugin.js
+++ b/node_modules/webpack/lib/node/NodeTemplatePlugin.js
@@ -1,27 +1,31 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-
-"use strict";
-
-const NodeMainTemplatePlugin = require("./NodeMainTemplatePlugin");
-const NodeChunkTemplatePlugin = require("./NodeChunkTemplatePlugin");
-const NodeHotUpdateChunkTemplatePlugin = require("./NodeHotUpdateChunkTemplatePlugin");
-
-class NodeTemplatePlugin {
- constructor(options) {
- options = options || {};
- this.asyncChunkLoading = options.asyncChunkLoading;
- }
-
- apply(compiler) {
- compiler.plugin("this-compilation", (compilation) => {
- compilation.mainTemplate.apply(new NodeMainTemplatePlugin(this.asyncChunkLoading));
- compilation.chunkTemplate.apply(new NodeChunkTemplatePlugin());
- compilation.hotUpdateChunkTemplate.apply(new NodeHotUpdateChunkTemplatePlugin());
- });
- }
-}
-
-module.exports = NodeTemplatePlugin;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const NodeMainTemplatePlugin = require("./NodeMainTemplatePlugin");
+const NodeChunkTemplatePlugin = require("./NodeChunkTemplatePlugin");
+const NodeHotUpdateChunkTemplatePlugin = require("./NodeHotUpdateChunkTemplatePlugin");
+
+class NodeTemplatePlugin {
+ constructor(options) {
+ options = options || {};
+ this.asyncChunkLoading = options.asyncChunkLoading;
+ }
+
+ apply(compiler) {
+ compiler.hooks.thisCompilation.tap("NodeTemplatePlugin", compilation => {
+ new NodeMainTemplatePlugin(this.asyncChunkLoading).apply(
+ compilation.mainTemplate
+ );
+ new NodeChunkTemplatePlugin().apply(compilation.chunkTemplate);
+ new NodeHotUpdateChunkTemplatePlugin().apply(
+ compilation.hotUpdateChunkTemplate
+ );
+ });
+ }
+}
+
+module.exports = NodeTemplatePlugin;
diff --git a/node_modules/webpack/lib/node/NodeWatchFileSystem.js b/node_modules/webpack/lib/node/NodeWatchFileSystem.js
index 1c13a9b29..62d8532cd 100644
--- a/node_modules/webpack/lib/node/NodeWatchFileSystem.js
+++ b/node_modules/webpack/lib/node/NodeWatchFileSystem.js
@@ -1,72 +1,99 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const Watchpack = require("watchpack");
-
-class NodeWatchFileSystem {
- constructor(inputFileSystem) {
- this.inputFileSystem = inputFileSystem;
- this.watcherOptions = {
- aggregateTimeout: 0
- };
- this.watcher = new Watchpack(this.watcherOptions);
- }
-
- watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
- if(!Array.isArray(files))
- throw new Error("Invalid arguments: 'files'");
- if(!Array.isArray(dirs))
- throw new Error("Invalid arguments: 'dirs'");
- if(!Array.isArray(missing))
- throw new Error("Invalid arguments: 'missing'");
- if(typeof callback !== "function")
- throw new Error("Invalid arguments: 'callback'");
- if(typeof startTime !== "number" && startTime)
- throw new Error("Invalid arguments: 'startTime'");
- if(typeof options !== "object")
- throw new Error("Invalid arguments: 'options'");
- if(typeof callbackUndelayed !== "function" && callbackUndelayed)
- throw new Error("Invalid arguments: 'callbackUndelayed'");
- const oldWatcher = this.watcher;
- this.watcher = new Watchpack(options);
-
- if(callbackUndelayed)
- this.watcher.once("change", callbackUndelayed);
-
- this.watcher.once("aggregated", (changes, removals) => {
- changes = changes.concat(removals);
- if(this.inputFileSystem && this.inputFileSystem.purge) {
- this.inputFileSystem.purge(changes);
- }
- const times = this.watcher.getTimes();
- callback(null,
- changes.filter(file => files.indexOf(file) >= 0).sort(),
- changes.filter(file => dirs.indexOf(file) >= 0).sort(),
- changes.filter(file => missing.indexOf(file) >= 0).sort(), times, times);
- });
-
- this.watcher.watch(files.concat(missing), dirs.concat(missing), startTime);
-
- if(oldWatcher) {
- oldWatcher.close();
- }
- return {
- close: () => {
- if(this.watcher) {
- this.watcher.close();
- this.watcher = null;
- }
- },
- pause: () => {
- if(this.watcher) {
- this.watcher.pause();
- }
- }
- };
- }
-}
-
-module.exports = NodeWatchFileSystem;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const Watchpack = require("watchpack");
+const objectToMap = require("../util/objectToMap");
+
+class NodeWatchFileSystem {
+ constructor(inputFileSystem) {
+ this.inputFileSystem = inputFileSystem;
+ this.watcherOptions = {
+ aggregateTimeout: 0
+ };
+ this.watcher = new Watchpack(this.watcherOptions);
+ }
+
+ watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
+ if (!Array.isArray(files)) {
+ throw new Error("Invalid arguments: 'files'");
+ }
+ if (!Array.isArray(dirs)) {
+ throw new Error("Invalid arguments: 'dirs'");
+ }
+ if (!Array.isArray(missing)) {
+ throw new Error("Invalid arguments: 'missing'");
+ }
+ if (typeof callback !== "function") {
+ throw new Error("Invalid arguments: 'callback'");
+ }
+ if (typeof startTime !== "number" && startTime) {
+ throw new Error("Invalid arguments: 'startTime'");
+ }
+ if (typeof options !== "object") {
+ throw new Error("Invalid arguments: 'options'");
+ }
+ if (typeof callbackUndelayed !== "function" && callbackUndelayed) {
+ throw new Error("Invalid arguments: 'callbackUndelayed'");
+ }
+ const oldWatcher = this.watcher;
+ this.watcher = new Watchpack(options);
+
+ if (callbackUndelayed) {
+ this.watcher.once("change", callbackUndelayed);
+ }
+
+ this.watcher.once("aggregated", (changes, removals) => {
+ changes = changes.concat(removals);
+ if (this.inputFileSystem && this.inputFileSystem.purge) {
+ this.inputFileSystem.purge(changes);
+ }
+ const times = objectToMap(this.watcher.getTimes());
+ callback(
+ null,
+ changes.filter(file => files.includes(file)).sort(),
+ changes.filter(file => dirs.includes(file)).sort(),
+ changes.filter(file => missing.includes(file)).sort(),
+ times,
+ times
+ );
+ });
+
+ this.watcher.watch(files.concat(missing), dirs.concat(missing), startTime);
+
+ if (oldWatcher) {
+ oldWatcher.close();
+ }
+ return {
+ close: () => {
+ if (this.watcher) {
+ this.watcher.close();
+ this.watcher = null;
+ }
+ },
+ pause: () => {
+ if (this.watcher) {
+ this.watcher.pause();
+ }
+ },
+ getFileTimestamps: () => {
+ if (this.watcher) {
+ return objectToMap(this.watcher.getTimes());
+ } else {
+ return new Map();
+ }
+ },
+ getContextTimestamps: () => {
+ if (this.watcher) {
+ return objectToMap(this.watcher.getTimes());
+ } else {
+ return new Map();
+ }
+ }
+ };
+ }
+}
+
+module.exports = NodeWatchFileSystem;