aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/node
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/webpack/lib/node
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/webpack/lib/node')
-rw-r--r--node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js31
-rw-r--r--node_modules/webpack/lib/node/NodeEnvironmentPlugin.js28
-rw-r--r--node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js36
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplate.runtime.js27
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js44
-rw-r--r--node_modules/webpack/lib/node/NodeMainTemplatePlugin.js321
-rw-r--r--node_modules/webpack/lib/node/NodeOutputFileSystem.js22
-rw-r--r--node_modules/webpack/lib/node/NodeSourcePlugin.js144
-rw-r--r--node_modules/webpack/lib/node/NodeTargetPlugin.js19
-rw-r--r--node_modules/webpack/lib/node/NodeTemplatePlugin.js31
-rw-r--r--node_modules/webpack/lib/node/NodeWatchFileSystem.js109
-rw-r--r--node_modules/webpack/lib/node/ReadFileCompileWasmTemplatePlugin.js61
12 files changed, 873 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js b/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js
new file mode 100644
index 00000000..292182a9
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeChunkTemplatePlugin.js
@@ -0,0 +1,31 @@
+/*
+ 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
new file mode 100644
index 00000000..3f76bffa
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
@@ -0,0 +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.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
new file mode 100644
index 00000000..bbd2e12a
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeHotUpdateChunkTemplatePlugin.js
@@ -0,0 +1,36 @@
+/*
+ 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
new file mode 100644
index 00000000..d34388bf
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeMainTemplate.runtime.js
@@ -0,0 +1,27 @@
+/*
+ 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
new file mode 100644
index 00000000..35eb47b6
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeMainTemplateAsync.runtime.js
@@ -0,0 +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() {
+ // 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
new file mode 100644
index 00000000..a2702969
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeMainTemplatePlugin.js
@@ -0,0 +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 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
new file mode 100644
index 00000000..2789b576
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeOutputFileSystem.js
@@ -0,0 +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;
diff --git a/node_modules/webpack/lib/node/NodeSourcePlugin.js b/node_modules/webpack/lib/node/NodeSourcePlugin.js
new file mode 100644
index 00000000..d5505f6f
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeSourcePlugin.js
@@ -0,0 +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;
+ }
+
+ 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
new file mode 100644
index 00000000..1ac5d8a5
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeTargetPlugin.js
@@ -0,0 +1,19 @@
+/*
+ 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,node/no-deprecated-api
+ 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
new file mode 100644
index 00000000..cdb1076b
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeTemplatePlugin.js
@@ -0,0 +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.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
new file mode 100644
index 00000000..235e0f06
--- /dev/null
+++ b/node_modules/webpack/lib/node/NodeWatchFileSystem.js
@@ -0,0 +1,109 @@
+/*
+ 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);
+ }
+ const cachedFiles = files;
+ const cachedDirs = dirs;
+ 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());
+ files = new Set(files);
+ dirs = new Set(dirs);
+ missing = new Set(missing);
+ removals = new Set(removals.filter(file => files.has(file)));
+ callback(
+ null,
+ changes.filter(file => files.has(file)).sort(),
+ changes.filter(file => dirs.has(file)).sort(),
+ changes.filter(file => missing.has(file)).sort(),
+ times,
+ times,
+ removals
+ );
+ });
+
+ this.watcher.watch(
+ cachedFiles.concat(missing),
+ cachedDirs.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;
diff --git a/node_modules/webpack/lib/node/ReadFileCompileWasmTemplatePlugin.js b/node_modules/webpack/lib/node/ReadFileCompileWasmTemplatePlugin.js
new file mode 100644
index 00000000..a7566b81
--- /dev/null
+++ b/node_modules/webpack/lib/node/ReadFileCompileWasmTemplatePlugin.js
@@ -0,0 +1,61 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const Template = require("../Template");
+const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
+
+class ReadFileCompileWasmTemplatePlugin {
+ constructor(options) {
+ this.options = options || {};
+ }
+
+ apply(compiler) {
+ compiler.hooks.thisCompilation.tap(
+ "ReadFileCompileWasmTemplatePlugin",
+ compilation => {
+ const generateLoadBinaryCode = path =>
+ Template.asString([
+ "new Promise(function (resolve, reject) {",
+ Template.indent([
+ "var { readFile } = require('fs');",
+ "var { join } = require('path');",
+ "",
+ "try {",
+ Template.indent([
+ `readFile(join(__dirname, ${path}), function(err, buffer){`,
+ Template.indent([
+ "if (err) return reject(err);",
+ "",
+ "// Fake fetch response",
+ "resolve({",
+ Template.indent([
+ "arrayBuffer() { return Promise.resolve(buffer); }"
+ ]),
+ "});"
+ ]),
+ "});"
+ ]),
+ "} catch (err) { reject(err); }"
+ ]),
+ "})"
+ ]);
+
+ const plugin = new WasmMainTemplatePlugin(
+ Object.assign(
+ {
+ generateLoadBinaryCode,
+ supportsStreaming: false
+ },
+ this.options
+ )
+ );
+ plugin.apply(compilation.mainTemplate);
+ }
+ );
+ }
+}
+
+module.exports = ReadFileCompileWasmTemplatePlugin;