From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送
---
node_modules/webpack/lib/ModuleGraph.js | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 103 insertions(+), 16 deletions(-)
diff --git a/node_modules/webpack/lib/ModuleGraph.js b/node_modules/webpack/lib/ModuleGraph.js
index 9cefb58..e1e5ba9 100644
--- a/node_modules/webpack/lib/ModuleGraph.js
+++ b/node_modules/webpack/lib/ModuleGraph.js
@@ -28,20 +28,24 @@
/** @typedef {import("./util/comparators").DependencySourceOrder} DependencySourceOrder */
/**
+ * Defines the optimization bailout function callback.
* @callback OptimizationBailoutFunction
* @param {RequestShortener} requestShortener
* @returns {string}
*/
+/** @type {Iterable<ModuleGraphConnection>} */
const EMPTY_SET = new Set();
/**
+ * Gets connections by key.
* @template {Module | null | undefined} T
* @param {SortableSet<ModuleGraphConnection>} set input
* @param {(connection: ModuleGraphConnection) => T} getKey function to extract key from connection
* @returns {ReadonlyMap<T, ReadonlyArray<ModuleGraphConnection>>} mapped by key
*/
const getConnectionsByKey = (set, getKey) => {
+ /** @type {Map<T, ModuleGraphConnection[]>} */
const map = new Map();
/** @type {T | 0} */
let lastKey = 0;
@@ -69,6 +73,7 @@
};
/**
+ * Gets connections by origin module.
* @param {SortableSet<ModuleGraphConnection>} set input
* @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} mapped by origin module
*/
@@ -76,6 +81,7 @@
getConnectionsByKey(set, (connection) => connection.originModule);
/**
+ * Gets connections by module.
* @param {SortableSet<ModuleGraphConnection>} set input
* @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>>} mapped by module
*/
@@ -123,6 +129,7 @@
/** @typedef {import("./dependencies/HarmonyExportImportedSpecifierDependency").idsSymbol} HarmonyExportImportedSpecifierDependencyIDsSymbol */
/**
+ * Defines the known meta type used by this module.
* @typedef {object} KnownMeta
* @property {Map<Module, string>=} importVarMap
* @property {Map<Module, string>=} deferredImportVarMap
@@ -169,9 +176,16 @@
* @private
*/
this._dependencySourceOrderMap = new WeakMap();
+
+ /**
+ * @type {Set<Module>}
+ * @private
+ */
+ this._modulesNeedingSort = new Set();
}
/**
+ * Get module graph module.
* @param {Module} module the module
* @returns {ModuleGraphModule} the internal module
*/
@@ -185,6 +199,7 @@
}
/**
+ * Updates parents using the provided dependency.
* @param {Dependency} dependency the dependency
* @param {DependenciesBlock} block parent block
* @param {Module} module parent module
@@ -198,6 +213,7 @@
}
/**
+ * Sets parent dependencies block index.
* @param {Dependency} dependency the dependency
* @param {number} index the index
* @returns {void}
@@ -207,6 +223,7 @@
}
/**
+ * Gets parent module.
* @param {Dependency} dependency the dependency
* @returns {Module | undefined} parent module
*/
@@ -215,6 +232,7 @@
}
/**
+ * Returns parent block.
* @param {Dependency} dependency the dependency
* @returns {DependenciesBlock | undefined} parent block
*/
@@ -223,6 +241,7 @@
}
/**
+ * Gets parent block index.
* @param {Dependency} dependency the dependency
* @returns {number} index
*/
@@ -231,6 +250,7 @@
}
/**
+ * Sets resolved module.
* @param {Module | null} originModule the referencing module
* @param {Dependency} dependency the referencing dependency
* @param {Module} module the referenced module
@@ -263,6 +283,7 @@
}
/**
+ * Updates module using the provided dependency.
* @param {Dependency} dependency the referencing dependency
* @param {Module} module the referenced module
* @returns {void}
@@ -286,6 +307,7 @@
}
/**
+ * Updates parent using the provided dependency.
* @param {Dependency} dependency the need update dependency
* @param {ModuleGraphConnection=} connection the target connection
* @param {Module=} parentModule the parent module
@@ -305,17 +327,15 @@
// import { a, b } from "lib" -> a and b have the same source order -> a = b = 1
// import { d } from "lib/d" -> d = 2
const currentSourceOrder =
- /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ (
- dependency
- ).sourceOrder;
+ /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
+ (dependency).sourceOrder;
// lib/index.js (reexport)
// import { a } from "lib/a" -> a = 0
// import { b } from "lib/b" -> b = 1
const originSourceOrder =
- /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ (
- originDependency
- ).sourceOrder;
+ /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
+ (originDependency).sourceOrder;
if (
typeof currentSourceOrder === "number" &&
typeof originSourceOrder === "number"
@@ -330,20 +350,33 @@
sub: originSourceOrder
});
- // If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder,
- // we sort based on it; otherwise, we preserve the original order.
- sortWithSourceOrder(
- parentModule.dependencies,
- this._dependencySourceOrderMap
- );
-
- for (const [index, dep] of parentModule.dependencies.entries()) {
- this.setParentDependenciesBlockIndex(dep, index);
- }
+ // Save for later batch sorting
+ this._modulesNeedingSort.add(parentModule);
}
}
/**
+ * Finish update parent.
+ * @returns {void}
+ */
+ finishUpdateParent() {
+ if (this._modulesNeedingSort.size === 0) {
+ return;
+ }
+ for (const mod of this._modulesNeedingSort) {
+ // If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder,
+ // we sort based on it; otherwise, we preserve the original order.
+ sortWithSourceOrder(
+ mod.dependencies,
+ this._dependencySourceOrderMap,
+ (dep, index) => this.setParentDependenciesBlockIndex(dep, index)
+ );
+ }
+ this._modulesNeedingSort.clear();
+ }
+
+ /**
+ * Removes connection.
* @param {Dependency} dependency the referencing dependency
* @returns {void}
*/
@@ -362,6 +395,7 @@
}
/**
+ * Adds the provided dependency to the module graph.
* @param {Dependency} dependency the referencing dependency
* @param {string} explanation an explanation
* @returns {void}
@@ -374,6 +408,7 @@
}
/**
+ * Clones module attributes.
* @param {Module} sourceModule the source module
* @param {Module} targetModule the target module
* @returns {void}
@@ -389,6 +424,7 @@
}
/**
+ * Removes module attributes.
* @param {Module} module the module
* @returns {void}
*/
@@ -401,6 +437,7 @@
}
/**
+ * Removes all module attributes.
* @returns {void}
*/
removeAllModuleAttributes() {
@@ -413,6 +450,7 @@
}
/**
+ * Move module connections.
* @param {Module} oldModule the old referencing module
* @param {Module} newModule the new referencing module
* @param {FilterConnection} filterConnection filter predicate for replacement
@@ -450,6 +488,7 @@
}
/**
+ * Copies outgoing module connections.
* @param {Module} oldModule the old referencing module
* @param {Module} newModule the new referencing module
* @param {FilterConnection} filterConnection filter predicate for replacement
@@ -481,6 +520,7 @@
}
/**
+ * Adds the provided module to the module graph.
* @param {Module} module the referenced module
* @param {string} explanation an explanation why it's referenced
* @returns {void}
@@ -491,6 +531,7 @@
}
/**
+ * Gets resolved module.
* @param {Dependency} dependency the dependency to look for a referenced module
* @returns {Module | null} the referenced module
*/
@@ -500,6 +541,7 @@
}
/**
+ * Returns the connection.
* @param {Dependency} dependency the dependency to look for a referenced module
* @returns {ModuleGraphConnection | undefined} the connection
*/
@@ -513,6 +555,7 @@
mgm._unassignedConnections &&
mgm._unassignedConnections.length !== 0
) {
+ /** @type {undefined | ModuleGraphConnection} */
let foundConnection;
for (const connection of mgm._unassignedConnections) {
this._dependencyMap.set(
@@ -536,6 +579,7 @@
}
/**
+ * Returns the referenced module.
* @param {Dependency} dependency the dependency to look for a referenced module
* @returns {Module | null} the referenced module
*/
@@ -545,6 +589,7 @@
}
/**
+ * Returns the referencing module.
* @param {Dependency} dependency the dependency to look for a referencing module
* @returns {Module | null} the referencing module
*/
@@ -554,6 +599,7 @@
}
/**
+ * Gets resolved origin.
* @param {Dependency} dependency the dependency to look for a referencing module
* @returns {Module | null} the original referencing module
*/
@@ -563,6 +609,7 @@
}
/**
+ * Gets incoming connections.
* @param {Module} module the module
* @returns {Iterable<ModuleGraphConnection>} reasons why a module is included
*/
@@ -572,6 +619,7 @@
}
/**
+ * Gets outgoing connections.
* @param {Module} module the module
* @returns {Iterable<ModuleGraphConnection>} list of outgoing connections
*/
@@ -581,6 +629,7 @@
}
/**
+ * Gets incoming connections by origin module.
* @param {Module} module the module
* @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} reasons why a module is included, in a map by source module
*/
@@ -590,6 +639,7 @@
}
/**
+ * Gets outgoing connections by module.
* @param {Module} module the module
* @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>> | undefined} connections to modules, in a map by module
*/
@@ -601,6 +651,7 @@
}
/**
+ * Returns the module profile.
* @param {Module} module the module
* @returns {ModuleProfile | undefined} the module profile
*/
@@ -610,6 +661,7 @@
}
/**
+ * Updates profile using the provided module.
* @param {Module} module the module
* @param {ModuleProfile | undefined} profile the module profile
* @returns {void}
@@ -620,6 +672,7 @@
}
/**
+ * Returns the issuer module.
* @param {Module} module the module
* @returns {Issuer} the issuer module
*/
@@ -629,6 +682,7 @@
}
/**
+ * Updates issuer using the provided module.
* @param {Module} module the module
* @param {Module | null} issuer the issuer module
* @returns {void}
@@ -639,6 +693,7 @@
}
/**
+ * Sets issuer if unset.
* @param {Module} module the module
* @param {Module | null} issuer the issuer module
* @returns {void}
@@ -649,6 +704,7 @@
}
/**
+ * Gets optimization bailout.
* @param {Module} module the module
* @returns {OptimizationBailouts} optimization bailouts
*/
@@ -658,6 +714,7 @@
}
/**
+ * Gets provided exports.
* @param {Module} module the module
* @returns {null | true | ExportInfoName[]} the provided exports
*/
@@ -667,6 +724,7 @@
}
/**
+ * Checks whether this module graph is export provided.
* @param {Module} module the module
* @param {ExportInfoName | ExportInfoName[]} exportName a name of an export
* @returns {boolean | null} true, if the export is provided by the module.
@@ -680,6 +738,7 @@
}
/**
+ * Returns info about the exports.
* @param {Module} module the module
* @returns {ExportsInfo} info about the exports
*/
@@ -689,6 +748,7 @@
}
/**
+ * Returns info about the export.
* @param {Module} module the module
* @param {string} exportName the export
* @returns {ExportInfo} info about the export
@@ -699,6 +759,7 @@
}
/**
+ * Gets read only export info.
* @param {Module} module the module
* @param {string} exportName the export
* @returns {ExportInfo} info about the export (do not modify)
@@ -709,6 +770,7 @@
}
/**
+ * Returns the used exports.
* @param {Module} module the module
* @param {RuntimeSpec} runtime the runtime
* @returns {false | true | SortableSet<string> | null} the used exports
@@ -724,6 +786,7 @@
}
/**
+ * Gets pre order index.
* @param {Module} module the module
* @returns {number | null} the index of the module
*/
@@ -733,6 +796,7 @@
}
/**
+ * Gets post order index.
* @param {Module} module the module
* @returns {number | null} the index of the module
*/
@@ -742,6 +806,7 @@
}
/**
+ * Sets pre order index.
* @param {Module} module the module
* @param {number} index the index of the module
* @returns {void}
@@ -752,6 +817,7 @@
}
/**
+ * Sets pre order index if unset.
* @param {Module} module the module
* @param {number} index the index of the module
* @returns {boolean} true, if the index was set
@@ -766,6 +832,7 @@
}
/**
+ * Sets post order index.
* @param {Module} module the module
* @param {number} index the index of the module
* @returns {void}
@@ -776,6 +843,7 @@
}
/**
+ * Sets post order index if unset.
* @param {Module} module the module
* @param {number} index the index of the module
* @returns {boolean} true, if the index was set
@@ -790,6 +858,7 @@
}
/**
+ * Returns the depth of the module.
* @param {Module} module the module
* @returns {number | null} the depth of the module
*/
@@ -799,6 +868,7 @@
}
/**
+ * Updates depth using the provided module.
* @param {Module} module the module
* @param {number} depth the depth of the module
* @returns {void}
@@ -809,6 +879,7 @@
}
/**
+ * Sets depth if lower.
* @param {Module} module the module
* @param {number} depth the depth of the module
* @returns {boolean} true, if the depth was set
@@ -823,6 +894,7 @@
}
/**
+ * Checks whether this module graph is async.
* @param {Module} module the module
* @returns {boolean} true, if the module is async
*/
@@ -832,6 +904,7 @@
}
/**
+ * Checks whether this module graph is deferred.
* @param {Module} module the module
* @returns {boolean} true, if the module is used as a deferred module at least once
*/
@@ -851,6 +924,7 @@
}
/**
+ * Updates async using the provided module.
* @param {Module} module the module
* @returns {void}
*/
@@ -860,6 +934,7 @@
}
/**
+ * Returns metadata.
* @param {MetaKey} thing any thing
* @returns {Meta} metadata
*/
@@ -873,6 +948,7 @@
}
/**
+ * Gets meta if existing.
* @param {MetaKey} thing any thing
* @returns {Meta | undefined} metadata
*/
@@ -881,6 +957,7 @@
}
/**
+ * Processes the provided cache stage.
* @param {string=} cacheStage a persistent stage name for caching
*/
freeze(cacheStage) {
@@ -894,6 +971,7 @@
}
/**
+ * Returns computed value or cached.
* @template {EXPECTED_ANY[]} T
* @template R
* @param {(moduleGraph: ModuleGraph, ...args: T) => R} fn computer
@@ -906,6 +984,7 @@
}
/**
+ * Sets module mem caches.
* @param {ModuleMemCaches} moduleMemCaches mem caches for modules for better caching
*/
setModuleMemCaches(moduleMemCaches) {
@@ -913,6 +992,7 @@
}
/**
+ * Dependency cache provide.
* @template {Dependency} D
* @template {EXPECTED_ANY[]} ARGS
* @template R
@@ -943,6 +1023,8 @@
// TODO remove in webpack 6
/**
+ * Gets module graph for module.
+ * @deprecated
* @param {Module} module the module
* @param {string} deprecateMessage message for the deprecation message
* @param {string} deprecationCode code for the deprecation
@@ -953,6 +1035,7 @@
if (fn) return fn(module);
const newFn = util.deprecate(
/**
+ * Handles the callback logic for this hook.
* @param {Module} module the module
* @returns {ModuleGraph} the module graph
*/
@@ -976,6 +1059,8 @@
// TODO remove in webpack 6
/**
+ * Sets module graph for module.
+ * @deprecated
* @param {Module} module the module
* @param {ModuleGraph} moduleGraph the module graph
* @returns {void}
@@ -986,6 +1071,8 @@
// TODO remove in webpack 6
/**
+ * Clear module graph for module.
+ * @deprecated
* @param {Module} module the module
* @returns {void}
*/
--
Gitblit v1.9.3