generated from dellevin/template
1
This commit is contained in:
120
node_modules/webpack/lib/node/CommonJsChunkLoadingPlugin.js
generated
vendored
Normal file
120
node_modules/webpack/lib/node/CommonJsChunkLoadingPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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 {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
||||
|
||||
/**
|
||||
* @typedef {object} CommonJsChunkLoadingPluginOptions
|
||||
* @property {boolean=} asyncChunkLoading enable async chunk loading
|
||||
*/
|
||||
|
||||
const PLUGIN_NAME = "CommonJsChunkLoadingPlugin";
|
||||
|
||||
class CommonJsChunkLoadingPlugin {
|
||||
/**
|
||||
* @param {CommonJsChunkLoadingPluginOptions=} options options
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
/** @type {CommonJsChunkLoadingPluginOptions} */
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const ChunkLoadingRuntimeModule = this.options.asyncChunkLoading
|
||||
? require("./ReadFileChunkLoadingRuntimeModule")
|
||||
: require("./RequireChunkLoadingRuntimeModule");
|
||||
const chunkLoadingValue = this.options.asyncChunkLoading
|
||||
? "async-node"
|
||||
: "require";
|
||||
new StartupChunkDependenciesPlugin({
|
||||
chunkLoading: chunkLoadingValue,
|
||||
asyncChunkLoading: this.options.asyncChunkLoading
|
||||
}).apply(compiler);
|
||||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (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;
|
||||
};
|
||||
/** @type {WeakSet<Chunk>} */
|
||||
const onceForChunkSet = new WeakSet();
|
||||
/**
|
||||
* @param {Chunk} chunk chunk
|
||||
* @param {RuntimeRequirements} 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(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadManifest)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.baseURI)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.externalInstallChunk)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.onChunksLoaded)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.ensureChunkHandlers)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
});
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
||||
.tap(PLUGIN_NAME, (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(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.getUpdateManifestFilename);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommonJsChunkLoadingPlugin;
|
||||
73
node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
generated
vendored
Normal file
73
node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @typedef {object} NodeEnvironmentPluginOptions
|
||||
* @property {InfrastructureLogging} infrastructureLogging infrastructure logging options
|
||||
*/
|
||||
|
||||
const PLUGIN_NAME = "NodeEnvironmentPlugin";
|
||||
|
||||
class NodeEnvironmentPlugin {
|
||||
/**
|
||||
* @param {NodeEnvironmentPluginOptions} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
/** @type {NodeEnvironmentPluginOptions} */
|
||||
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(PLUGIN_NAME, (compiler) => {
|
||||
if (
|
||||
compiler.inputFileSystem === inputFileSystem &&
|
||||
inputFileSystem.purge
|
||||
) {
|
||||
compiler.fsStartTime = Date.now();
|
||||
inputFileSystem.purge();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NodeEnvironmentPlugin;
|
||||
19
node_modules/webpack/lib/node/NodeSourcePlugin.js
generated
vendored
Normal file
19
node_modules/webpack/lib/node/NodeSourcePlugin.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
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;
|
||||
102
node_modules/webpack/lib/node/NodeTargetPlugin.js
generated
vendored
Normal file
102
node_modules/webpack/lib/node/NodeTargetPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const ExternalsPlugin = require("../ExternalsPlugin");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
||||
/** @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 {
|
||||
/**
|
||||
* @param {ExternalsType} type default external type
|
||||
*/
|
||||
constructor(type = "node-commonjs") {
|
||||
/** @type {ExternalsType} */
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
new ExternalsPlugin((dependency) => {
|
||||
// When `require` node.js built-in modules with module output
|
||||
// we should still emit `createRequire` for compatibility
|
||||
if (dependency.category === "commonjs") {
|
||||
return "node-commonjs";
|
||||
}
|
||||
|
||||
return this.type;
|
||||
}, builtins).apply(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NodeTargetPlugin;
|
||||
42
node_modules/webpack/lib/node/NodeTemplatePlugin.js
generated
vendored
Normal file
42
node_modules/webpack/lib/node/NodeTemplatePlugin.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 = {}) {
|
||||
/** @type {NodeTemplatePluginOptions} */
|
||||
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;
|
||||
198
node_modules/webpack/lib/node/NodeWatchFileSystem.js
generated
vendored
Normal file
198
node_modules/webpack/lib/node/NodeWatchFileSystem.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
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("watchpack").TimeInfoEntries} TimeInfoEntries */
|
||||
/** @typedef {import("watchpack").WatchOptions} WatchOptions */
|
||||
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
||||
/** @typedef {import("../util/fs").WatchMethod} WatchMethod */
|
||||
/** @typedef {import("../util/fs").Changes} Changes */
|
||||
/** @typedef {import("../util/fs").Removals} Removals */
|
||||
|
||||
class NodeWatchFileSystem {
|
||||
/**
|
||||
* @param {InputFileSystem} inputFileSystem input filesystem
|
||||
*/
|
||||
constructor(inputFileSystem) {
|
||||
/** @type {InputFileSystem} */
|
||||
this.inputFileSystem = inputFileSystem;
|
||||
/** @type {WatchOptions} */
|
||||
this.watcherOptions = {
|
||||
aggregateTimeout: 0
|
||||
};
|
||||
/** @type {Watchpack | null} */
|
||||
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 = () => {
|
||||
/** @type {TimeInfoEntries} */
|
||||
const fileTimeInfoEntries = new Map();
|
||||
/** @type {TimeInfoEntries} */
|
||||
const contextTimeInfoEntries = new Map();
|
||||
if (this.watcher) {
|
||||
this.watcher.collectTimeInfoEntries(
|
||||
fileTimeInfoEntries,
|
||||
contextTimeInfoEntries
|
||||
);
|
||||
}
|
||||
return { fileTimeInfoEntries, contextTimeInfoEntries };
|
||||
};
|
||||
this.watcher.once(
|
||||
"aggregated",
|
||||
/**
|
||||
* @param {Changes} changes changes
|
||||
* @param {Removals} removals removals
|
||||
*/
|
||||
(changes, removals) => {
|
||||
// pause emitting events (avoids clearing aggregated changes and removals on timeout)
|
||||
/** @type {Watchpack} */
|
||||
(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;
|
||||
286
node_modules/webpack/lib/node/ReadFileChunkLoadingRuntimeModule.js
generated
vendored
Normal file
286
node_modules/webpack/lib/node/ReadFileChunkLoadingRuntimeModule.js
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
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 {
|
||||
generateJavascriptHMR
|
||||
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
||||
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("../RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
||||
|
||||
class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
/**
|
||||
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
||||
*/
|
||||
constructor(runtimeRequirements) {
|
||||
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
|
||||
/** @type {ReadOnlyRuntimeRequirements} */
|
||||
this.runtimeRequirements = runtimeRequirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Chunk} chunk chunk
|
||||
* @param {string} rootOutputDir root output directory
|
||||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @returns {string} generated code
|
||||
*/
|
||||
_generateBaseUri(chunk, rootOutputDir, runtimeTemplate) {
|
||||
const options = chunk.getEntryOptions();
|
||||
if (options && options.baseUri) {
|
||||
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
||||
}
|
||||
|
||||
return `${RuntimeGlobals.baseURI} = require(${runtimeTemplate.renderNodePrefixForCoreModule("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,
|
||||
compilation.outputOptions.path,
|
||||
false
|
||||
);
|
||||
|
||||
const stateExpression = withHmr
|
||||
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`
|
||||
: undefined;
|
||||
|
||||
return Template.asString([
|
||||
withBaseURI
|
||||
? this._generateBaseUri(chunk, rootOutputDir, runtimeTemplate)
|
||||
: "// 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(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
||||
rootOutputDir
|
||||
)} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId));`,
|
||||
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
||||
Template.indent([
|
||||
"if(err) return reject(err);",
|
||||
"var chunk = {};",
|
||||
`require(${runtimeTemplate.renderNodePrefixForCoreModule("vm")}).runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)` +
|
||||
`(chunk, require, require(${runtimeTemplate.renderNodePrefixForCoreModule("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(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
||||
rootOutputDir
|
||||
)} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
||||
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
||||
Template.indent([
|
||||
"if(err) return reject(err);",
|
||||
"var update = {};",
|
||||
`require(${runtimeTemplate.renderNodePrefixForCoreModule("vm")}).runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)` +
|
||||
`(update, require, require(${runtimeTemplate.renderNodePrefixForCoreModule("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();"
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"}",
|
||||
"",
|
||||
generateJavascriptHMR("readFileVm")
|
||||
])
|
||||
: "// no HMR",
|
||||
"",
|
||||
withHmrManifest
|
||||
? Template.asString([
|
||||
`${RuntimeGlobals.hmrDownloadManifest} = function() {`,
|
||||
Template.indent([
|
||||
"return new Promise(function(resolve, reject) {",
|
||||
Template.indent([
|
||||
`var filename = require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
||||
rootOutputDir
|
||||
)} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
|
||||
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
||||
Template.indent([
|
||||
"if(err) {",
|
||||
Template.indent([
|
||||
'if(["MODULE_NOT_FOUND", "ENOENT"].includes(err.code)) return resolve();',
|
||||
"return reject(err);"
|
||||
]),
|
||||
"}",
|
||||
"try { resolve(JSON.parse(content)); }",
|
||||
"catch(e) { reject(e); }"
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"}"
|
||||
])
|
||||
: "// no HMR manifest"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReadFileChunkLoadingRuntimeModule;
|
||||
123
node_modules/webpack/lib/node/ReadFileCompileAsyncWasmPlugin.js
generated
vendored
Normal file
123
node_modules/webpack/lib/node/ReadFileCompileAsyncWasmPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @typedef {object} ReadFileCompileAsyncWasmPluginOptions
|
||||
* @property {boolean=} import use import?
|
||||
*/
|
||||
|
||||
const PLUGIN_NAME = "ReadFileCompileAsyncWasmPlugin";
|
||||
|
||||
class ReadFileCompileAsyncWasmPlugin {
|
||||
/**
|
||||
* @param {ReadFileCompileAsyncWasmPluginOptions=} options options object
|
||||
*/
|
||||
constructor({ import: useImport = false } = {}) {
|
||||
/** @type {boolean} */
|
||||
this._import = useImport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (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 === "async-node";
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(path: string) => string} callback to generate code to load the wasm file
|
||||
*/
|
||||
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}, ${compilation.outputOptions.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(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("fs")});`,
|
||||
`var { join } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("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(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
if (
|
||||
!chunkGraph.hasModuleInGraph(
|
||||
chunk,
|
||||
(m) => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
compilation.addRuntimeModule(
|
||||
chunk,
|
||||
new AsyncWasmLoadingRuntimeModule({
|
||||
generateLoadBinaryCode,
|
||||
supportsStreaming: false
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReadFileCompileAsyncWasmPlugin;
|
||||
127
node_modules/webpack/lib/node/ReadFileCompileWasmPlugin.js
generated
vendored
Normal file
127
node_modules/webpack/lib/node/ReadFileCompileWasmPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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
|
||||
* @property {boolean=} import use import?
|
||||
*/
|
||||
|
||||
const PLUGIN_NAME = "ReadFileCompileWasmPlugin";
|
||||
|
||||
class ReadFileCompileWasmPlugin {
|
||||
/**
|
||||
* @param {ReadFileCompileWasmPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
/** @type {ReadFileCompileWasmPluginOptions} */
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (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";
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(path: string) => string} callback to generate code to load the wasm file
|
||||
*/
|
||||
const generateLoadBinaryCode = this.options.import
|
||||
? (path) =>
|
||||
Template.asString([
|
||||
"Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
|
||||
Template.indent([
|
||||
`readFile(new URL(${path}, ${compilation.outputOptions.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([
|
||||
`var { readFile } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("fs")});`,
|
||||
`var { join } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("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(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
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;
|
||||
239
node_modules/webpack/lib/node/RequireChunkLoadingRuntimeModule.js
generated
vendored
Normal file
239
node_modules/webpack/lib/node/RequireChunkLoadingRuntimeModule.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
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 {
|
||||
generateJavascriptHMR
|
||||
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
||||
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("../RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
||||
|
||||
class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
/**
|
||||
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
||||
*/
|
||||
constructor(runtimeRequirements) {
|
||||
super("require chunk loading", RuntimeModule.STAGE_ATTACH);
|
||||
/** @type {ReadOnlyRuntimeRequirements} */
|
||||
this.runtimeRequirements = runtimeRequirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Chunk} chunk chunk
|
||||
* @param {string} rootOutputDir root output directory
|
||||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @returns {string} generated code
|
||||
*/
|
||||
_generateBaseUri(chunk, rootOutputDir, runtimeTemplate) {
|
||||
const options = chunk.getEntryOptions();
|
||||
if (options && options.baseUri) {
|
||||
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
||||
}
|
||||
|
||||
return `${RuntimeGlobals.baseURI} = require(${runtimeTemplate.renderNodePrefixForCoreModule("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,
|
||||
compilation.outputOptions.path,
|
||||
true
|
||||
);
|
||||
|
||||
const stateExpression = withHmr
|
||||
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_require`
|
||||
: undefined;
|
||||
|
||||
return Template.asString([
|
||||
withBaseURI
|
||||
? this._generateBaseUri(chunk, rootOutputDir, runtimeTemplate)
|
||||
: "// 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([
|
||||
// The require function loads and runs a chunk. When the chunk is being run,
|
||||
// it can call __webpack_require__.C to directly complete installed.
|
||||
`var installedChunk = require(${JSON.stringify(
|
||||
rootOutputDir
|
||||
)} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId));`,
|
||||
"if (!installedChunks[chunkId]) {",
|
||||
Template.indent(["installChunk(installedChunk);"]),
|
||||
"}"
|
||||
]),
|
||||
"} 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);"
|
||||
]),
|
||||
"}",
|
||||
"",
|
||||
generateJavascriptHMR("require")
|
||||
])
|
||||
: "// 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(${runtimeTemplate.basicFunction("err", [
|
||||
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(err.code)) return;",
|
||||
"throw err;"
|
||||
])});`
|
||||
]),
|
||||
"}"
|
||||
])
|
||||
: "// no HMR manifest"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RequireChunkLoadingRuntimeModule;
|
||||
185
node_modules/webpack/lib/node/nodeConsole.js
generated
vendored
Normal file
185
node_modules/webpack/lib/node/nodeConsole.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
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("../config/defaults").InfrastructureLoggingNormalizedWithDefaults} InfrastructureLoggingNormalizedWithDefaults */
|
||||
/** @typedef {import("../logging/createConsoleLogger").LoggerConsole} LoggerConsole */
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
/**
|
||||
* @param {object} options options
|
||||
* @param {boolean=} options.colors colors
|
||||
* @param {boolean=} options.appendOnly append only
|
||||
* @param {InfrastructureLoggingNormalizedWithDefaults["stream"]} 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 = 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} prefix prefix
|
||||
* @param {string} colorPrefix color prefix
|
||||
* @param {string} colorSuffix color suffix
|
||||
* @returns {(...args: T[]) => 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();
|
||||
};
|
||||
|
||||
/** @type {<T extends unknown[]>(...args: T) => void} */
|
||||
const writeGroupMessage = writeColored(
|
||||
"<-> ",
|
||||
"\u001B[1m\u001B[36m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
);
|
||||
|
||||
/** @type {<T extends unknown[]>(...args: T) => void} */
|
||||
const writeGroupCollapsedMessage = writeColored(
|
||||
"<+> ",
|
||||
"\u001B[1m\u001B[36m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
);
|
||||
|
||||
return {
|
||||
/** @type {LoggerConsole["log"]} */
|
||||
log: writeColored(" ", "\u001B[1m", "\u001B[22m"),
|
||||
/** @type {LoggerConsole["debug"]} */
|
||||
debug: writeColored(" ", "", ""),
|
||||
/** @type {LoggerConsole["trace"]} */
|
||||
trace: writeColored(" ", "", ""),
|
||||
/** @type {LoggerConsole["info"]} */
|
||||
info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"),
|
||||
/** @type {LoggerConsole["warn"]} */
|
||||
warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"),
|
||||
/** @type {LoggerConsole["error"]} */
|
||||
error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"),
|
||||
/** @type {LoggerConsole["logTime"]} */
|
||||
logTime: writeColored(
|
||||
"<t> ",
|
||||
"\u001B[1m\u001B[35m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
),
|
||||
/** @type {LoggerConsole["group"]} */
|
||||
group: (...args) => {
|
||||
writeGroupMessage(...args);
|
||||
if (currentCollapsed > 0) {
|
||||
currentCollapsed++;
|
||||
} else {
|
||||
currentIndent += " ";
|
||||
}
|
||||
},
|
||||
/** @type {LoggerConsole["groupCollapsed"]} */
|
||||
groupCollapsed: (...args) => {
|
||||
writeGroupCollapsedMessage(...args);
|
||||
currentCollapsed++;
|
||||
},
|
||||
/** @type {LoggerConsole["groupEnd"]} */
|
||||
groupEnd: () => {
|
||||
if (currentCollapsed > 0) {
|
||||
currentCollapsed--;
|
||||
} else if (currentIndent.length >= 2) {
|
||||
currentIndent = currentIndent.slice(0, -2);
|
||||
}
|
||||
},
|
||||
/** @type {LoggerConsole["profile"]} */
|
||||
profile: console.profile && ((name) => console.profile(name)),
|
||||
/** @type {LoggerConsole["profileEnd"]} */
|
||||
profileEnd: console.profileEnd && ((name) => console.profileEnd(name)),
|
||||
/** @type {LoggerConsole["clear"]} */
|
||||
clear:
|
||||
/** @type {() => void} */
|
||||
(
|
||||
!appendOnly &&
|
||||
console.clear &&
|
||||
(() => {
|
||||
clearStatusMessage();
|
||||
console.clear();
|
||||
writeStatusMessage();
|
||||
})
|
||||
),
|
||||
/** @type {LoggerConsole["status"]} */
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user