diff options
Diffstat (limited to 'node_modules/webpack/lib/node')
11 files changed, 0 insertions, 1458 deletions
diff --git a/node_modules/webpack/lib/node/CommonJsChunkLoadingPlugin.js b/node_modules/webpack/lib/node/CommonJsChunkLoadingPlugin.js deleted file mode 100644 index cd7f7872..00000000 --- a/node_modules/webpack/lib/node/CommonJsChunkLoadingPlugin.js +++ /dev/null @@ -1,121 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const RuntimeGlobals = require("../RuntimeGlobals"); -const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin"); - -/** @typedef {import("../Chunk")} Chunk */ -/** @typedef {import("../Compiler")} Compiler */ - -/** - * @typedef {object} CommonJsChunkLoadingPluginOptions - * @property {boolean} [asyncChunkLoading] enable async chunk loading - */ - -class CommonJsChunkLoadingPlugin { - /** - * @param {CommonJsChunkLoadingPluginOptions} [options] options - */ - constructor(options = {}) { - this._asyncChunkLoading = options.asyncChunkLoading; - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - const ChunkLoadingRuntimeModule = this._asyncChunkLoading - ? require("./ReadFileChunkLoadingRuntimeModule") - : require("./RequireChunkLoadingRuntimeModule"); - const chunkLoadingValue = this._asyncChunkLoading - ? "async-node" - : "require"; - new StartupChunkDependenciesPlugin({ - chunkLoading: chunkLoadingValue, - asyncChunkLoading: this._asyncChunkLoading - }).apply(compiler); - compiler.hooks.thisCompilation.tap( - "CommonJsChunkLoadingPlugin", - compilation => { - const globalChunkLoading = compilation.outputOptions.chunkLoading; - /** - * @param {Chunk} chunk chunk - * @returns {boolean} true, if wasm loading is enabled for the chunk - */ - const isEnabledForChunk = chunk => { - const options = chunk.getEntryOptions(); - const chunkLoading = - options && options.chunkLoading !== undefined - ? options.chunkLoading - : globalChunkLoading; - return chunkLoading === chunkLoadingValue; - }; - const onceForChunkSet = new WeakSet(); - /** - * @param {Chunk} chunk chunk - * @param {Set<string>} set runtime requirements - */ - const handler = (chunk, set) => { - if (onceForChunkSet.has(chunk)) return; - onceForChunkSet.add(chunk); - if (!isEnabledForChunk(chunk)) return; - set.add(RuntimeGlobals.moduleFactoriesAddOnly); - set.add(RuntimeGlobals.hasOwnProperty); - compilation.addRuntimeModule( - chunk, - new ChunkLoadingRuntimeModule(set) - ); - }; - - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.ensureChunkHandlers) - .tap("CommonJsChunkLoadingPlugin", handler); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.hmrDownloadUpdateHandlers) - .tap("CommonJsChunkLoadingPlugin", handler); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.hmrDownloadManifest) - .tap("CommonJsChunkLoadingPlugin", handler); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.baseURI) - .tap("CommonJsChunkLoadingPlugin", handler); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.externalInstallChunk) - .tap("CommonJsChunkLoadingPlugin", handler); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.onChunksLoaded) - .tap("CommonJsChunkLoadingPlugin", handler); - - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.ensureChunkHandlers) - .tap("CommonJsChunkLoadingPlugin", (chunk, set) => { - if (!isEnabledForChunk(chunk)) return; - set.add(RuntimeGlobals.getChunkScriptFilename); - }); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.hmrDownloadUpdateHandlers) - .tap("CommonJsChunkLoadingPlugin", (chunk, set) => { - if (!isEnabledForChunk(chunk)) return; - set.add(RuntimeGlobals.getChunkUpdateScriptFilename); - set.add(RuntimeGlobals.moduleCache); - set.add(RuntimeGlobals.hmrModuleData); - set.add(RuntimeGlobals.moduleFactoriesAddOnly); - }); - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.hmrDownloadManifest) - .tap("CommonJsChunkLoadingPlugin", (chunk, set) => { - if (!isEnabledForChunk(chunk)) return; - set.add(RuntimeGlobals.getUpdateManifestFilename); - }); - } - ); - } -} - -module.exports = CommonJsChunkLoadingPlugin; diff --git a/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js b/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js deleted file mode 100644 index 221b1af0..00000000 --- a/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const CachedInputFileSystem = require("enhanced-resolve").CachedInputFileSystem; -const fs = require("graceful-fs"); -const createConsoleLogger = require("../logging/createConsoleLogger"); -const NodeWatchFileSystem = require("./NodeWatchFileSystem"); -const nodeConsole = require("./nodeConsole"); - -/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */ -/** @typedef {import("../Compiler")} Compiler */ -/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ - -class NodeEnvironmentPlugin { - /** - * @param {object} options options - * @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options - */ - constructor(options) { - this.options = options; - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - const { infrastructureLogging } = this.options; - compiler.infrastructureLogger = createConsoleLogger({ - level: infrastructureLogging.level || "info", - debug: infrastructureLogging.debug || false, - console: - infrastructureLogging.console || - nodeConsole({ - colors: infrastructureLogging.colors, - appendOnly: infrastructureLogging.appendOnly, - stream: - /** @type {NodeJS.WritableStream} */ - (infrastructureLogging.stream) - }) - }); - compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000); - const inputFileSystem = - /** @type {InputFileSystem} */ - (compiler.inputFileSystem); - compiler.outputFileSystem = fs; - compiler.intermediateFileSystem = fs; - compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem); - compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => { - if ( - compiler.inputFileSystem === inputFileSystem && - inputFileSystem.purge - ) { - compiler.fsStartTime = Date.now(); - inputFileSystem.purge(); - } - }); - } -} - -module.exports = NodeEnvironmentPlugin; diff --git a/node_modules/webpack/lib/node/NodeSourcePlugin.js b/node_modules/webpack/lib/node/NodeSourcePlugin.js deleted file mode 100644 index fca1fc9c..00000000 --- a/node_modules/webpack/lib/node/NodeSourcePlugin.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -/** @typedef {import("../Compiler")} Compiler */ - -class NodeSourcePlugin { - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) {} -} - -module.exports = NodeSourcePlugin; diff --git a/node_modules/webpack/lib/node/NodeTargetPlugin.js b/node_modules/webpack/lib/node/NodeTargetPlugin.js deleted file mode 100644 index 1cc01810..00000000 --- a/node_modules/webpack/lib/node/NodeTargetPlugin.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const ExternalsPlugin = require("../ExternalsPlugin"); - -/** @typedef {import("../Compiler")} Compiler */ - -const builtins = [ - "assert", - "assert/strict", - "async_hooks", - "buffer", - "child_process", - "cluster", - "console", - "constants", - "crypto", - "dgram", - "diagnostics_channel", - "dns", - "dns/promises", - "domain", - "events", - "fs", - "fs/promises", - "http", - "http2", - "https", - "inspector", - "inspector/promises", - "module", - "net", - "os", - "path", - "path/posix", - "path/win32", - "perf_hooks", - "process", - "punycode", - "querystring", - "readline", - "readline/promises", - "repl", - "stream", - "stream/consumers", - "stream/promises", - "stream/web", - "string_decoder", - "sys", - "timers", - "timers/promises", - "tls", - "trace_events", - "tty", - "url", - "util", - "util/types", - "v8", - "vm", - "wasi", - "worker_threads", - "zlib", - /^node:/, - - // cspell:word pnpapi - // Yarn PnP adds pnpapi as "builtin" - "pnpapi" -]; - -class NodeTargetPlugin { - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - new ExternalsPlugin("node-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 deleted file mode 100644 index c784368e..00000000 --- a/node_modules/webpack/lib/node/NodeTemplatePlugin.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const CommonJsChunkFormatPlugin = require("../javascript/CommonJsChunkFormatPlugin"); -const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin"); - -/** @typedef {import("../Compiler")} Compiler */ - -/** - * @typedef {object} NodeTemplatePluginOptions - * @property {boolean} [asyncChunkLoading] enable async chunk loading - */ - -class NodeTemplatePlugin { - /** - * @param {NodeTemplatePluginOptions} [options] options object - */ - constructor(options = {}) { - this._options = options; - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - const chunkLoading = this._options.asyncChunkLoading - ? "async-node" - : "require"; - compiler.options.output.chunkLoading = chunkLoading; - new CommonJsChunkFormatPlugin().apply(compiler); - new EnableChunkLoadingPlugin(chunkLoading).apply(compiler); - } -} - -module.exports = NodeTemplatePlugin; diff --git a/node_modules/webpack/lib/node/NodeWatchFileSystem.js b/node_modules/webpack/lib/node/NodeWatchFileSystem.js deleted file mode 100644 index d7b59f2c..00000000 --- a/node_modules/webpack/lib/node/NodeWatchFileSystem.js +++ /dev/null @@ -1,190 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const util = require("util"); -const Watchpack = require("watchpack"); - -/** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */ -/** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */ -/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ -/** @typedef {import("../util/fs").WatchMethod} WatchMethod */ - -class NodeWatchFileSystem { - /** - * @param {InputFileSystem} inputFileSystem input filesystem - */ - constructor(inputFileSystem) { - this.inputFileSystem = inputFileSystem; - this.watcherOptions = { - aggregateTimeout: 0 - }; - this.watcher = new Watchpack(this.watcherOptions); - } - - /** @type {WatchMethod} */ - watch( - files, - directories, - missing, - startTime, - options, - callback, - callbackUndelayed - ) { - if (!files || typeof files[Symbol.iterator] !== "function") { - throw new Error("Invalid arguments: 'files'"); - } - if (!directories || typeof directories[Symbol.iterator] !== "function") { - throw new Error("Invalid arguments: 'directories'"); - } - if (!missing || typeof missing[Symbol.iterator] !== "function") { - 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 fetchTimeInfo = () => { - const fileTimeInfoEntries = new Map(); - const contextTimeInfoEntries = new Map(); - if (this.watcher) { - this.watcher.collectTimeInfoEntries( - fileTimeInfoEntries, - contextTimeInfoEntries - ); - } - return { fileTimeInfoEntries, contextTimeInfoEntries }; - }; - this.watcher.once( - "aggregated", - /** - * @param {Set<string>} changes changes - * @param {Set<string>} removals removals - */ - (changes, removals) => { - // pause emitting events (avoids clearing aggregated changes and removals on timeout) - this.watcher.pause(); - - const fs = this.inputFileSystem; - if (fs && fs.purge) { - for (const item of changes) { - fs.purge(item); - } - for (const item of removals) { - fs.purge(item); - } - } - const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo(); - callback( - null, - fileTimeInfoEntries, - contextTimeInfoEntries, - changes, - removals - ); - } - ); - - this.watcher.watch({ files, directories, missing, startTime }); - - if (oldWatcher) { - oldWatcher.close(); - } - return { - close: () => { - if (this.watcher) { - this.watcher.close(); - this.watcher = null; - } - }, - pause: () => { - if (this.watcher) { - this.watcher.pause(); - } - }, - getAggregatedRemovals: util.deprecate( - () => { - const items = this.watcher && this.watcher.aggregatedRemovals; - const fs = this.inputFileSystem; - if (items && fs && fs.purge) { - for (const item of items) { - fs.purge(item); - } - } - return items; - }, - "Watcher.getAggregatedRemovals is deprecated in favor of Watcher.getInfo since that's more performant.", - "DEP_WEBPACK_WATCHER_GET_AGGREGATED_REMOVALS" - ), - getAggregatedChanges: util.deprecate( - () => { - const items = this.watcher && this.watcher.aggregatedChanges; - const fs = this.inputFileSystem; - if (items && fs && fs.purge) { - for (const item of items) { - fs.purge(item); - } - } - return items; - }, - "Watcher.getAggregatedChanges is deprecated in favor of Watcher.getInfo since that's more performant.", - "DEP_WEBPACK_WATCHER_GET_AGGREGATED_CHANGES" - ), - getFileTimeInfoEntries: util.deprecate( - () => fetchTimeInfo().fileTimeInfoEntries, - "Watcher.getFileTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.", - "DEP_WEBPACK_WATCHER_FILE_TIME_INFO_ENTRIES" - ), - getContextTimeInfoEntries: util.deprecate( - () => fetchTimeInfo().contextTimeInfoEntries, - "Watcher.getContextTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.", - "DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES" - ), - getInfo: () => { - const removals = this.watcher && this.watcher.aggregatedRemovals; - const changes = this.watcher && this.watcher.aggregatedChanges; - const fs = this.inputFileSystem; - if (fs && fs.purge) { - if (removals) { - for (const item of removals) { - fs.purge(item); - } - } - if (changes) { - for (const item of changes) { - fs.purge(item); - } - } - } - const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo(); - return { - changes, - removals, - fileTimeInfoEntries, - contextTimeInfoEntries - }; - } - }; - } -} - -module.exports = NodeWatchFileSystem; diff --git a/node_modules/webpack/lib/node/ReadFileChunkLoadingRuntimeModule.js b/node_modules/webpack/lib/node/ReadFileChunkLoadingRuntimeModule.js deleted file mode 100644 index fd138b2e..00000000 --- a/node_modules/webpack/lib/node/ReadFileChunkLoadingRuntimeModule.js +++ /dev/null @@ -1,301 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php -*/ - -"use strict"; - -const RuntimeGlobals = require("../RuntimeGlobals"); -const RuntimeModule = require("../RuntimeModule"); -const Template = require("../Template"); -const { - chunkHasJs, - getChunkFilenameTemplate -} = require("../javascript/JavascriptModulesPlugin"); -const { getInitialChunkIds } = require("../javascript/StartupHelpers"); -const compileBooleanMatcher = require("../util/compileBooleanMatcher"); -const { getUndoPath } = require("../util/identifier"); - -/** @typedef {import("../Chunk")} Chunk */ -/** @typedef {import("../ChunkGraph")} ChunkGraph */ -/** @typedef {import("../Compilation")} Compilation */ -/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */ - -class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { - /** - * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements - */ - constructor(runtimeRequirements) { - super("readFile chunk loading", RuntimeModule.STAGE_ATTACH); - this.runtimeRequirements = runtimeRequirements; - } - - /** - * @private - * @param {Chunk} chunk chunk - * @param {string} rootOutputDir root output directory - * @returns {string} generated code - */ - _generateBaseUri(chunk, rootOutputDir) { - const options = chunk.getEntryOptions(); - if (options && options.baseUri) { - return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`; - } - - return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${ - rootOutputDir - ? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}` - : "__filename" - });`; - } - - /** - * @returns {string | null} runtime code - */ - generate() { - const compilation = /** @type {Compilation} */ (this.compilation); - const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph); - const chunk = /** @type {Chunk} */ (this.chunk); - const { runtimeTemplate } = compilation; - const fn = RuntimeGlobals.ensureChunkHandlers; - const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI); - const withExternalInstallChunk = this.runtimeRequirements.has( - RuntimeGlobals.externalInstallChunk - ); - const withOnChunkLoad = this.runtimeRequirements.has( - RuntimeGlobals.onChunksLoaded - ); - const withLoading = this.runtimeRequirements.has( - RuntimeGlobals.ensureChunkHandlers - ); - const withHmr = this.runtimeRequirements.has( - RuntimeGlobals.hmrDownloadUpdateHandlers - ); - const withHmrManifest = this.runtimeRequirements.has( - RuntimeGlobals.hmrDownloadManifest - ); - const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs); - const hasJsMatcher = compileBooleanMatcher(conditionMap); - const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs); - - const outputName = compilation.getPath( - getChunkFilenameTemplate(chunk, compilation.outputOptions), - { - chunk, - contentHashType: "javascript" - } - ); - const rootOutputDir = getUndoPath( - outputName, - /** @type {string} */ (compilation.outputOptions.path), - false - ); - - const stateExpression = withHmr - ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm` - : undefined; - - return Template.asString([ - withBaseURI - ? this._generateBaseUri(chunk, rootOutputDir) - : "// no baseURI", - "", - "// object to store loaded chunks", - '// "0" means "already loaded", Promise means loading', - `var installedChunks = ${ - stateExpression ? `${stateExpression} = ${stateExpression} || ` : "" - }{`, - Template.indent( - Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join( - ",\n" - ) - ), - "};", - "", - withOnChunkLoad - ? `${ - RuntimeGlobals.onChunksLoaded - }.readFileVm = ${runtimeTemplate.returningFunction( - "installedChunks[chunkId] === 0", - "chunkId" - )};` - : "// no on chunks loaded", - "", - withLoading || withExternalInstallChunk - ? `var installChunk = ${runtimeTemplate.basicFunction("chunk", [ - "var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;", - "for(var moduleId in moreModules) {", - Template.indent([ - `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`, - Template.indent([ - `${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];` - ]), - "}" - ]), - "}", - `if(runtime) runtime(${RuntimeGlobals.require});`, - "for(var i = 0; i < chunkIds.length; i++) {", - Template.indent([ - "if(installedChunks[chunkIds[i]]) {", - Template.indent(["installedChunks[chunkIds[i]][0]();"]), - "}", - "installedChunks[chunkIds[i]] = 0;" - ]), - "}", - withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : "" - ])};` - : "// no chunk install function needed", - "", - withLoading - ? Template.asString([ - "// ReadFile + VM.run chunk loading for javascript", - `${fn}.readFileVm = function(chunkId, promises) {`, - hasJsMatcher !== false - ? Template.indent([ - "", - "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([ - hasJsMatcher === true - ? "if(true) { // all chunks have JS" - : `if(${hasJsMatcher("chunkId")}) {`, - 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, ${JSON.stringify( - rootOutputDir - )} + ${ - RuntimeGlobals.getChunkScriptFilename - }(chunkId));`, - "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);", - "installChunk(chunk);" - ]), - "});" - ]), - "});", - "promises.push(installedChunkData[2] = promise);" - ]), - hasJsMatcher === true - ? "}" - : "} else installedChunks[chunkId] = 0;" - ]), - "}" - ]), - "}" - ]) - : Template.indent(["installedChunks[chunkId] = 0;"]), - "};" - ]) - : "// no chunk loading", - "", - withExternalInstallChunk - ? Template.asString([ - `module.exports = ${RuntimeGlobals.require};`, - `${RuntimeGlobals.externalInstallChunk} = installChunk;` - ]) - : "// no external install chunk", - "", - withHmr - ? Template.asString([ - "function loadUpdateChunk(chunkId, updatedModulesList) {", - Template.indent([ - "return new Promise(function(resolve, reject) {", - Template.indent([ - `var filename = require('path').join(__dirname, ${JSON.stringify( - rootOutputDir - )} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`, - "require('fs').readFile(filename, 'utf-8', function(err, content) {", - Template.indent([ - "if(err) return reject(err);", - "var update = {};", - "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" + - "(update, require, require('path').dirname(filename), filename);", - "var updatedModules = update.modules;", - "var runtime = update.runtime;", - "for(var moduleId in updatedModules) {", - Template.indent([ - `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`, - Template.indent([ - "currentUpdate[moduleId] = updatedModules[moduleId];", - "if(updatedModulesList) updatedModulesList.push(moduleId);" - ]), - "}" - ]), - "}", - "if(runtime) currentUpdateRuntime.push(runtime);", - "resolve();" - ]), - "});" - ]), - "});" - ]), - "}", - "", - Template.getFunctionContent( - require("../hmr/JavascriptHotModuleReplacement.runtime.js") - ) - .replace(/\$key\$/g, "readFileVm") - .replace(/\$installedChunks\$/g, "installedChunks") - .replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk") - .replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache) - .replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories) - .replace( - /\$ensureChunkHandlers\$/g, - RuntimeGlobals.ensureChunkHandlers - ) - .replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty) - .replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData) - .replace( - /\$hmrDownloadUpdateHandlers\$/g, - RuntimeGlobals.hmrDownloadUpdateHandlers - ) - .replace( - /\$hmrInvalidateModuleHandlers\$/g, - RuntimeGlobals.hmrInvalidateModuleHandlers - ) - ]) - : "// no HMR", - "", - withHmrManifest - ? Template.asString([ - `${RuntimeGlobals.hmrDownloadManifest} = function() {`, - Template.indent([ - "return new Promise(function(resolve, reject) {", - Template.indent([ - `var filename = require('path').join(__dirname, ${JSON.stringify( - rootOutputDir - )} + ${RuntimeGlobals.getUpdateManifestFilename}());`, - "require('fs').readFile(filename, 'utf-8', function(err, content) {", - Template.indent([ - "if(err) {", - Template.indent([ - 'if(err.code === "ENOENT") return resolve();', - "return reject(err);" - ]), - "}", - "try { resolve(JSON.parse(content)); }", - "catch(e) { reject(e); }" - ]), - "});" - ]), - "});" - ]), - "}" - ]) - : "// no HMR manifest" - ]); - } -} - -module.exports = ReadFileChunkLoadingRuntimeModule; diff --git a/node_modules/webpack/lib/node/ReadFileCompileAsyncWasmPlugin.js b/node_modules/webpack/lib/node/ReadFileCompileAsyncWasmPlugin.js deleted file mode 100644 index 61ab8ff0..00000000 --- a/node_modules/webpack/lib/node/ReadFileCompileAsyncWasmPlugin.js +++ /dev/null @@ -1,118 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants"); -const RuntimeGlobals = require("../RuntimeGlobals"); -const Template = require("../Template"); -const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule"); - -/** @typedef {import("../Chunk")} Chunk */ -/** @typedef {import("../Compiler")} Compiler */ - -class ReadFileCompileAsyncWasmPlugin { - constructor({ type = "async-node", import: useImport = false } = {}) { - this._type = type; - this._import = useImport; - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - compiler.hooks.thisCompilation.tap( - "ReadFileCompileAsyncWasmPlugin", - compilation => { - const globalWasmLoading = compilation.outputOptions.wasmLoading; - /** - * @param {Chunk} chunk chunk - * @returns {boolean} true, if wasm loading is enabled for the chunk - */ - const isEnabledForChunk = chunk => { - const options = chunk.getEntryOptions(); - const wasmLoading = - options && options.wasmLoading !== undefined - ? options.wasmLoading - : globalWasmLoading; - return wasmLoading === this._type; - }; - const { importMetaName } = compilation.outputOptions; - /** - * @type {(path: string) => string} - */ - const generateLoadBinaryCode = this._import - ? path => - Template.asString([ - "Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {", - Template.indent([ - `readFile(new URL(${path}, ${importMetaName}.url), (err, buffer) => {`, - Template.indent([ - "if (err) return reject(err);", - "", - "// Fake fetch response", - "resolve({", - Template.indent(["arrayBuffer() { return buffer; }"]), - "});" - ]), - "});" - ]), - "}))" - ]) - : path => - Template.asString([ - "new Promise(function (resolve, reject) {", - Template.indent([ - "try {", - Template.indent([ - "var { readFile } = require('fs');", - "var { join } = require('path');", - "", - `readFile(join(__dirname, ${path}), function(err, buffer){`, - Template.indent([ - "if (err) return reject(err);", - "", - "// Fake fetch response", - "resolve({", - Template.indent(["arrayBuffer() { return buffer; }"]), - "});" - ]), - "});" - ]), - "} catch (err) { reject(err); }" - ]), - "})" - ]); - - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.instantiateWasm) - .tap("ReadFileCompileAsyncWasmPlugin", (chunk, set) => { - if (!isEnabledForChunk(chunk)) return; - const chunkGraph = compilation.chunkGraph; - if ( - !chunkGraph.hasModuleInGraph( - chunk, - m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC - ) - ) { - return; - } - set.add(RuntimeGlobals.publicPath); - compilation.addRuntimeModule( - chunk, - new AsyncWasmLoadingRuntimeModule({ - generateLoadBinaryCode, - supportsStreaming: false - }) - ); - }); - } - ); - } -} - -module.exports = ReadFileCompileAsyncWasmPlugin; diff --git a/node_modules/webpack/lib/node/ReadFileCompileWasmPlugin.js b/node_modules/webpack/lib/node/ReadFileCompileWasmPlugin.js deleted file mode 100644 index 0a463994..00000000 --- a/node_modules/webpack/lib/node/ReadFileCompileWasmPlugin.js +++ /dev/null @@ -1,111 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants"); -const RuntimeGlobals = require("../RuntimeGlobals"); -const Template = require("../Template"); -const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule"); - -/** @typedef {import("../Chunk")} Chunk */ -/** @typedef {import("../Compiler")} Compiler */ - -/** - * @typedef {object} ReadFileCompileWasmPluginOptions - * @property {boolean} [mangleImports] mangle imports - */ - -// TODO webpack 6 remove - -class ReadFileCompileWasmPlugin { - /** - * @param {ReadFileCompileWasmPluginOptions} [options] options object - */ - constructor(options = {}) { - this.options = options; - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - compiler.hooks.thisCompilation.tap( - "ReadFileCompileWasmPlugin", - compilation => { - const globalWasmLoading = compilation.outputOptions.wasmLoading; - /** - * @param {Chunk} chunk chunk - * @returns {boolean} true, when wasm loading is enabled for the chunk - */ - const isEnabledForChunk = chunk => { - const options = chunk.getEntryOptions(); - const wasmLoading = - options && options.wasmLoading !== undefined - ? options.wasmLoading - : globalWasmLoading; - return wasmLoading === "async-node"; - }; - /** - * @param {string} path path to wasm file - * @returns {string} generated code to load the wasm file - */ - 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 buffer; }"]), - "});" - ]), - "});" - ]), - "} catch (err) { reject(err); }" - ]), - "})" - ]); - - compilation.hooks.runtimeRequirementInTree - .for(RuntimeGlobals.ensureChunkHandlers) - .tap("ReadFileCompileWasmPlugin", (chunk, set) => { - if (!isEnabledForChunk(chunk)) return; - const chunkGraph = compilation.chunkGraph; - if ( - !chunkGraph.hasModuleInGraph( - chunk, - m => m.type === WEBASSEMBLY_MODULE_TYPE_SYNC - ) - ) { - return; - } - set.add(RuntimeGlobals.moduleCache); - compilation.addRuntimeModule( - chunk, - new WasmChunkLoadingRuntimeModule({ - generateLoadBinaryCode, - supportsStreaming: false, - mangleImports: this.options.mangleImports, - runtimeRequirements: set - }) - ); - }); - } - ); - } -} - -module.exports = ReadFileCompileWasmPlugin; diff --git a/node_modules/webpack/lib/node/RequireChunkLoadingRuntimeModule.js b/node_modules/webpack/lib/node/RequireChunkLoadingRuntimeModule.js deleted file mode 100644 index 1d495945..00000000 --- a/node_modules/webpack/lib/node/RequireChunkLoadingRuntimeModule.js +++ /dev/null @@ -1,246 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php -*/ - -"use strict"; - -const RuntimeGlobals = require("../RuntimeGlobals"); -const RuntimeModule = require("../RuntimeModule"); -const Template = require("../Template"); -const { - chunkHasJs, - getChunkFilenameTemplate -} = require("../javascript/JavascriptModulesPlugin"); -const { getInitialChunkIds } = require("../javascript/StartupHelpers"); -const compileBooleanMatcher = require("../util/compileBooleanMatcher"); -const { getUndoPath } = require("../util/identifier"); - -/** @typedef {import("../Chunk")} Chunk */ -/** @typedef {import("../ChunkGraph")} ChunkGraph */ -/** @typedef {import("../Compilation")} Compilation */ -/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */ - -class RequireChunkLoadingRuntimeModule extends RuntimeModule { - /** - * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements - */ - constructor(runtimeRequirements) { - super("require chunk loading", RuntimeModule.STAGE_ATTACH); - this.runtimeRequirements = runtimeRequirements; - } - - /** - * @private - * @param {Chunk} chunk chunk - * @param {string} rootOutputDir root output directory - * @returns {string} generated code - */ - _generateBaseUri(chunk, rootOutputDir) { - const options = chunk.getEntryOptions(); - if (options && options.baseUri) { - return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`; - } - - return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${ - rootOutputDir !== "./" - ? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}` - : "__filename" - });`; - } - - /** - * @returns {string | null} runtime code - */ - generate() { - const compilation = /** @type {Compilation} */ (this.compilation); - const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph); - const chunk = /** @type {Chunk} */ (this.chunk); - const { runtimeTemplate } = compilation; - const fn = RuntimeGlobals.ensureChunkHandlers; - const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI); - const withExternalInstallChunk = this.runtimeRequirements.has( - RuntimeGlobals.externalInstallChunk - ); - const withOnChunkLoad = this.runtimeRequirements.has( - RuntimeGlobals.onChunksLoaded - ); - const withLoading = this.runtimeRequirements.has( - RuntimeGlobals.ensureChunkHandlers - ); - const withHmr = this.runtimeRequirements.has( - RuntimeGlobals.hmrDownloadUpdateHandlers - ); - const withHmrManifest = this.runtimeRequirements.has( - RuntimeGlobals.hmrDownloadManifest - ); - const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs); - const hasJsMatcher = compileBooleanMatcher(conditionMap); - const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs); - - const outputName = compilation.getPath( - getChunkFilenameTemplate(chunk, compilation.outputOptions), - { - chunk, - contentHashType: "javascript" - } - ); - const rootOutputDir = getUndoPath( - outputName, - /** @type {string} */ (compilation.outputOptions.path), - true - ); - - const stateExpression = withHmr - ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_require` - : undefined; - - return Template.asString([ - withBaseURI - ? this._generateBaseUri(chunk, rootOutputDir) - : "// no baseURI", - "", - "// object to store loaded chunks", - '// "1" means "loaded", otherwise not loaded yet', - `var installedChunks = ${ - stateExpression ? `${stateExpression} = ${stateExpression} || ` : "" - }{`, - Template.indent( - Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 1`).join( - ",\n" - ) - ), - "};", - "", - withOnChunkLoad - ? `${ - RuntimeGlobals.onChunksLoaded - }.require = ${runtimeTemplate.returningFunction( - "installedChunks[chunkId]", - "chunkId" - )};` - : "// no on chunks loaded", - "", - withLoading || withExternalInstallChunk - ? `var installChunk = ${runtimeTemplate.basicFunction("chunk", [ - "var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;", - "for(var moduleId in moreModules) {", - Template.indent([ - `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`, - Template.indent([ - `${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];` - ]), - "}" - ]), - "}", - `if(runtime) runtime(${RuntimeGlobals.require});`, - "for(var i = 0; i < chunkIds.length; i++)", - Template.indent("installedChunks[chunkIds[i]] = 1;"), - withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : "" - ])};` - : "// no chunk install function needed", - "", - withLoading - ? Template.asString([ - "// require() chunk loading for javascript", - `${fn}.require = ${runtimeTemplate.basicFunction( - "chunkId, promises", - hasJsMatcher !== false - ? [ - '// "1" is the signal for "already loaded"', - "if(!installedChunks[chunkId]) {", - Template.indent([ - hasJsMatcher === true - ? "if(true) { // all chunks have JS" - : `if(${hasJsMatcher("chunkId")}) {`, - Template.indent([ - `installChunk(require(${JSON.stringify( - rootOutputDir - )} + ${ - RuntimeGlobals.getChunkScriptFilename - }(chunkId)));` - ]), - "} else installedChunks[chunkId] = 1;", - "" - ]), - "}" - ] - : "installedChunks[chunkId] = 1;" - )};` - ]) - : "// no chunk loading", - "", - withExternalInstallChunk - ? Template.asString([ - `module.exports = ${RuntimeGlobals.require};`, - `${RuntimeGlobals.externalInstallChunk} = installChunk;` - ]) - : "// no external install chunk", - "", - withHmr - ? Template.asString([ - "function loadUpdateChunk(chunkId, updatedModulesList) {", - Template.indent([ - `var update = require(${JSON.stringify(rootOutputDir)} + ${ - RuntimeGlobals.getChunkUpdateScriptFilename - }(chunkId));`, - "var updatedModules = update.modules;", - "var runtime = update.runtime;", - "for(var moduleId in updatedModules) {", - Template.indent([ - `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`, - Template.indent([ - "currentUpdate[moduleId] = updatedModules[moduleId];", - "if(updatedModulesList) updatedModulesList.push(moduleId);" - ]), - "}" - ]), - "}", - "if(runtime) currentUpdateRuntime.push(runtime);" - ]), - "}", - "", - Template.getFunctionContent( - require("../hmr/JavascriptHotModuleReplacement.runtime.js") - ) - .replace(/\$key\$/g, "require") - .replace(/\$installedChunks\$/g, "installedChunks") - .replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk") - .replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache) - .replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories) - .replace( - /\$ensureChunkHandlers\$/g, - RuntimeGlobals.ensureChunkHandlers - ) - .replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty) - .replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData) - .replace( - /\$hmrDownloadUpdateHandlers\$/g, - RuntimeGlobals.hmrDownloadUpdateHandlers - ) - .replace( - /\$hmrInvalidateModuleHandlers\$/g, - RuntimeGlobals.hmrInvalidateModuleHandlers - ) - ]) - : "// no HMR", - "", - withHmrManifest - ? Template.asString([ - `${RuntimeGlobals.hmrDownloadManifest} = function() {`, - Template.indent([ - "return Promise.resolve().then(function() {", - Template.indent([ - `return require(${JSON.stringify(rootOutputDir)} + ${ - RuntimeGlobals.getUpdateManifestFilename - }());` - ]), - "})['catch'](function(err) { if(err.code !== 'MODULE_NOT_FOUND') throw err; });" - ]), - "}" - ]) - : "// no HMR manifest" - ]); - } -} - -module.exports = RequireChunkLoadingRuntimeModule; diff --git a/node_modules/webpack/lib/node/nodeConsole.js b/node_modules/webpack/lib/node/nodeConsole.js deleted file mode 100644 index 5f3a1627..00000000 --- a/node_modules/webpack/lib/node/nodeConsole.js +++ /dev/null @@ -1,160 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const util = require("util"); -const truncateArgs = require("../logging/truncateArgs"); - -/** @typedef {import("../logging/createConsoleLogger").LoggerConsole} LoggerConsole */ - -/** - * @param {object} options options - * @param {boolean=} options.colors colors - * @param {boolean=} options.appendOnly append only - * @param {NodeJS.WritableStream} options.stream stream - * @returns {LoggerConsole} logger function - */ -module.exports = ({ colors, appendOnly, stream }) => { - /** @type {string[] | undefined} */ - let currentStatusMessage; - let hasStatusMessage = false; - let currentIndent = ""; - let currentCollapsed = 0; - - /** - * @param {string} str string - * @param {string} prefix prefix - * @param {string} colorPrefix color prefix - * @param {string} colorSuffix color suffix - * @returns {string} indented string - */ - const indent = (str, prefix, colorPrefix, colorSuffix) => { - if (str === "") return str; - prefix = currentIndent + prefix; - if (colors) { - return ( - prefix + - colorPrefix + - str.replace(/\n/g, `${colorSuffix}\n${prefix}${colorPrefix}`) + - colorSuffix - ); - } - - return prefix + str.replace(/\n/g, `\n${prefix}`); - }; - - const clearStatusMessage = () => { - if (hasStatusMessage) { - stream.write("\u001B[2K\r"); - hasStatusMessage = false; - } - }; - - const writeStatusMessage = () => { - if (!currentStatusMessage) return; - const l = /** @type {TODO} */ (stream).columns || 40; - const args = truncateArgs(currentStatusMessage, l - 1); - const str = args.join(" "); - const coloredStr = `\u001B[1m${str}\u001B[39m\u001B[22m`; - stream.write(`\u001B[2K\r${coloredStr}`); - hasStatusMessage = true; - }; - - /** - * @param {string} prefix prefix - * @param {string} colorPrefix color prefix - * @param {string} colorSuffix color suffix - * @returns {(function(...any[]): void)} function to write with colors - */ - const writeColored = - (prefix, colorPrefix, colorSuffix) => - (...args) => { - if (currentCollapsed > 0) return; - clearStatusMessage(); - const str = indent( - util.format(...args), - prefix, - colorPrefix, - colorSuffix - ); - stream.write(`${str}\n`); - writeStatusMessage(); - }; - - const writeGroupMessage = writeColored( - "<-> ", - "\u001B[1m\u001B[36m", - "\u001B[39m\u001B[22m" - ); - - const writeGroupCollapsedMessage = writeColored( - "<+> ", - "\u001B[1m\u001B[36m", - "\u001B[39m\u001B[22m" - ); - - return { - log: writeColored(" ", "\u001B[1m", "\u001B[22m"), - debug: writeColored(" ", "", ""), - trace: writeColored(" ", "", ""), - info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"), - warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"), - error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"), - logTime: writeColored( - "<t> ", - "\u001B[1m\u001B[35m", - "\u001B[39m\u001B[22m" - ), - group: (...args) => { - writeGroupMessage(...args); - if (currentCollapsed > 0) { - currentCollapsed++; - } else { - currentIndent += " "; - } - }, - groupCollapsed: (...args) => { - writeGroupCollapsedMessage(...args); - currentCollapsed++; - }, - groupEnd: () => { - if (currentCollapsed > 0) currentCollapsed--; - else if (currentIndent.length >= 2) - currentIndent = currentIndent.slice(0, -2); - }, - profile: console.profile && (name => console.profile(name)), - profileEnd: console.profileEnd && (name => console.profileEnd(name)), - clear: - !appendOnly && - console.clear && - (() => { - clearStatusMessage(); - console.clear(); - writeStatusMessage(); - }), - status: appendOnly - ? writeColored("<s> ", "", "") - : (name, ...args) => { - args = args.filter(Boolean); - if (name === undefined && args.length === 0) { - clearStatusMessage(); - currentStatusMessage = undefined; - } else if ( - typeof name === "string" && - name.startsWith("[webpack.Progress] ") - ) { - currentStatusMessage = [name.slice(19), ...args]; - writeStatusMessage(); - } else if (name === "[webpack.Progress]") { - currentStatusMessage = [...args]; - writeStatusMessage(); - } else { - currentStatusMessage = [name, ...args]; - writeStatusMessage(); - } - } - }; -}; |
