Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
97
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
97
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
@@ -56,6 +56,7 @@ const JavascriptParser = require("./JavascriptParser");
|
||||
/** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
||||
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
||||
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
||||
/** @typedef {import("../Compilation").ExecuteModuleObject} ExecuteModuleObject */
|
||||
@@ -75,37 +76,75 @@ const JavascriptParser = require("./JavascriptParser");
|
||||
/** @typedef {import("../util/concatenate").ScopeSet} ScopeSet */
|
||||
/** @typedef {import("../util/concatenate").UsedNamesInScopeInfo} UsedNamesInScopeInfo */
|
||||
|
||||
/** @type {WeakMap<ChunkGraph, WeakMap<Chunk, boolean>>} */
|
||||
const chunkHasJsCache = new WeakMap();
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk a chunk
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @returns {boolean} true, when a JS file is needed for this chunk
|
||||
*/
|
||||
const chunkHasJs = (chunk, chunkGraph) => {
|
||||
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
|
||||
const _chunkHasJs = (chunk, chunkGraph) => {
|
||||
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
||||
for (const module of chunkGraph.getChunkEntryModulesIterable(chunk)) {
|
||||
if (chunkGraph.getModuleSourceTypes(module).has(JAVASCRIPT_TYPE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean(
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk a chunk
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @returns {boolean} true, when a JS file is needed for this chunk
|
||||
*/
|
||||
const chunkHasJs = (chunk, chunkGraph) => {
|
||||
let innerCache = chunkHasJsCache.get(chunkGraph);
|
||||
if (innerCache === undefined) {
|
||||
innerCache = new WeakMap();
|
||||
chunkHasJsCache.set(chunkGraph, innerCache);
|
||||
}
|
||||
|
||||
const cachedResult = innerCache.get(chunk);
|
||||
if (cachedResult !== undefined) {
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
const result = _chunkHasJs(chunk, chunkGraph);
|
||||
innerCache.set(chunk, result);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk a chunk
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @returns {boolean} true, when a JS file is needed for this chunk
|
||||
*/
|
||||
const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
|
||||
if (chunkHasJs(chunk, chunkGraph)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
chunkGraph.getChunkModulesIterableBySourceType(
|
||||
chunk,
|
||||
WEBPACK_MODULE_TYPE_RUNTIME
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
for (const chunkGroup of chunk.groupsIterable) {
|
||||
for (const c of chunkGroup.chunks) {
|
||||
if (chunkHasJs(c, chunkGraph)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return Boolean(
|
||||
chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
|
||||
);
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1312,17 +1351,22 @@ class JavascriptModulesPlugin {
|
||||
const runtimeRequirements =
|
||||
chunkGraph.getTreeRuntimeRequirements(chunk);
|
||||
buf2.push("// Load entry module and return exports");
|
||||
let i = chunkGraph.getNumberOfEntryModules(chunk);
|
||||
|
||||
/** @type {EntryModuleWithChunkGroup[]} */
|
||||
const jsEntries = [];
|
||||
for (const [
|
||||
entryModule,
|
||||
entrypoint
|
||||
] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
|
||||
if (
|
||||
!chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
|
||||
chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
|
||||
) {
|
||||
i--;
|
||||
jsEntries.push([entryModule, entrypoint]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let i = jsEntries.length;
|
||||
for (const [entryModule, entrypoint] of jsEntries) {
|
||||
const chunks =
|
||||
/** @type {Entrypoint} */
|
||||
(entrypoint).chunks.filter((c) => c !== chunk);
|
||||
@@ -1546,20 +1590,42 @@ class JavascriptModulesPlugin {
|
||||
runtimeTemplate: { outputOptions }
|
||||
} = renderContext;
|
||||
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
||||
|
||||
/**
|
||||
* @param {string} condition guard expression
|
||||
* @returns {string[]} source
|
||||
*/
|
||||
const renderMissingModuleError = (condition) =>
|
||||
outputOptions.pathinfo
|
||||
? [
|
||||
`if (${condition}) {`,
|
||||
Template.indent([
|
||||
"delete __webpack_module_cache__[moduleId];",
|
||||
'var e = new Error("Cannot find module \'" + moduleId + "\'");',
|
||||
"e.code = 'MODULE_NOT_FOUND';",
|
||||
"throw e;"
|
||||
]),
|
||||
"}"
|
||||
]
|
||||
: [];
|
||||
|
||||
const moduleExecution = runtimeRequirements.has(
|
||||
RuntimeGlobals.interceptModuleExecution
|
||||
)
|
||||
? Template.asString([
|
||||
`var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
|
||||
`${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
|
||||
...renderMissingModuleError("!execOptions.factory"),
|
||||
"module = execOptions.module;",
|
||||
"execOptions.factory.call(module.exports, module, module.exports, execOptions.require);"
|
||||
])
|
||||
: runtimeRequirements.has(RuntimeGlobals.thisAsExports)
|
||||
? Template.asString([
|
||||
...renderMissingModuleError("!(moduleId in __webpack_modules__)"),
|
||||
`__webpack_modules__[moduleId].call(module.exports, module, module.exports, ${RuntimeGlobals.require});`
|
||||
])
|
||||
: Template.asString([
|
||||
...renderMissingModuleError("!(moduleId in __webpack_modules__)"),
|
||||
`__webpack_modules__[moduleId](module, module.exports, ${RuntimeGlobals.require});`
|
||||
]);
|
||||
const needModuleId = runtimeRequirements.has(RuntimeGlobals.moduleId);
|
||||
@@ -1580,19 +1646,6 @@ class JavascriptModulesPlugin {
|
||||
])
|
||||
: Template.indent("return cachedModule.exports;"),
|
||||
"}",
|
||||
// Add helpful error message in development mode when module is not found
|
||||
...(outputOptions.pathinfo
|
||||
? [
|
||||
"// Check if module exists (development only)",
|
||||
"if (__webpack_modules__[moduleId] === undefined) {",
|
||||
Template.indent([
|
||||
'var e = new Error("Cannot find module \'" + moduleId + "\'");',
|
||||
"e.code = 'MODULE_NOT_FOUND';",
|
||||
"throw e;"
|
||||
]),
|
||||
"}"
|
||||
]
|
||||
: []),
|
||||
"// Create a new module (and put it into the cache)",
|
||||
"var module = __webpack_module_cache__[moduleId] = {",
|
||||
Template.indent([
|
||||
|
||||
Reference in New Issue
Block a user