From 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 18:09:58 +0800
Subject: [PATCH] 上报转运调试
---
node_modules/webpack/lib/NormalModule.js | 85 +++++++++++++++++++++++++++++++++++-------
1 files changed, 71 insertions(+), 14 deletions(-)
diff --git a/node_modules/webpack/lib/NormalModule.js b/node_modules/webpack/lib/NormalModule.js
index 2bcfe81..a659317 100644
--- a/node_modules/webpack/lib/NormalModule.js
+++ b/node_modules/webpack/lib/NormalModule.js
@@ -6,7 +6,6 @@
"use strict";
const querystring = require("querystring");
-const parseJson = require("json-parse-even-better-errors");
const { getContext, runLoaders } = require("loader-runner");
const {
AsyncSeriesBailHook,
@@ -53,6 +52,7 @@
} = require("./util/identifier");
const makeSerializable = require("./util/makeSerializable");
const memoize = require("./util/memoize");
+const parseJson = require("./util/parseJson");
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
@@ -79,7 +79,9 @@
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
/** @typedef {import("./Module").BuildCallback} BuildCallback */
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
-/** @typedef {import("./Generator").SourceTypes} SourceTypes */
+/** @typedef {import("./Module").Sources} Sources */
+/** @typedef {import("./Module").SourceType} SourceType */
+/** @typedef {import("./Module").SourceTypes} SourceTypes */
/** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
/** @typedef {import("./ModuleGraph")} ModuleGraph */
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -114,6 +116,8 @@
* @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} NormalModuleLoaderContext
*/
+/** @typedef {(content: string) => boolean} NoParseFn */
+
const getInvalidDependenciesModuleWarning = memoize(() =>
require("./InvalidDependenciesModuleWarning")
);
@@ -122,7 +126,7 @@
const getValidate = memoize(() => require("schema-utils").validate);
-const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
+const ABSOLUTE_PATH_REGEX = /^(?:[a-z]:\\|\\\\|\/)/i;
/**
* @typedef {object} LoaderItem
@@ -226,12 +230,17 @@
/** @typedef {LoaderContext<EXPECTED_ANY>} AnyLoaderContext */
/**
+ * @deprecated Use the `readResource` hook instead.
+ * @typedef {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} DeprecatedReadResourceForScheme
+ */
+
+/**
* @typedef {object} NormalModuleCompilationHooks
* @property {SyncHook<[AnyLoaderContext, NormalModule]>} loader
* @property {SyncHook<[LoaderItem[], NormalModule, AnyLoaderContext]>} beforeLoaders
* @property {SyncHook<[NormalModule]>} beforeParse
* @property {SyncHook<[NormalModule]>} beforeSnapshot
- * @property {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} readResourceForScheme
+ * @property {DeprecatedReadResourceForScheme} readResourceForScheme
* @property {HookMap<AsyncSeriesBailHook<[AnyLoaderContext], string | Buffer | null>>} readResource
* @property {SyncWaterfallHook<[Result, NormalModule]>} processResult
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
@@ -359,7 +368,7 @@
/** @type {NormalModuleCreateData['rawRequest']} */
this.rawRequest = rawRequest;
/** @type {boolean} */
- this.binary = /^(asset|webassembly)\b/.test(type);
+ this.binary = /^(?:asset|webassembly)\b/.test(type);
/** @type {NormalModuleCreateData['parser'] | undefined} */
this.parser = parser;
/** @type {NormalModuleCreateData['parserOptions']} */
@@ -394,7 +403,7 @@
this._source = null;
/**
* @private
- * @type {Map<string | undefined, number> | undefined}
+ * @type {Map<undefined | SourceType, number> | undefined}
*/
this._sourceSizes = undefined;
/**
@@ -402,18 +411,36 @@
* @type {undefined | SourceTypes}
*/
this._sourceTypes = undefined;
-
// Cache
+ /**
+ * @private
+ * @type {BuildMeta}
+ */
this._lastSuccessfulBuildMeta = {};
+ /**
+ * @private
+ * @type {boolean}
+ */
this._forceBuild = true;
+ /**
+ * @private
+ * @type {boolean}
+ */
this._isEvaluatingSideEffects = false;
- /** @type {WeakSet<ModuleGraph> | undefined} */
+ /**
+ * @private
+ * @type {WeakSet<ModuleGraph> | undefined}
+ */
this._addedSideEffectsBailout = undefined;
- /** @type {CodeGenerationResultData} */
+ /**
+ * @private
+ * @type {CodeGenerationResultData}
+ */
this._codeGeneratorData = new Map();
}
/**
+ * Returns the unique identifier used to reference this module.
* @returns {string} a unique identifier of the module
*/
identifier() {
@@ -427,6 +454,7 @@
}
/**
+ * Returns a human-readable identifier for this module.
* @param {RequestShortener} requestShortener the request shortener
* @returns {string} a user readable identifier of the module
*/
@@ -442,6 +470,7 @@
}
/**
+ * Gets the library identifier.
* @param {LibIdentOptions} options options
* @returns {LibIdent | null} an identifier for library inclusion
*/
@@ -456,6 +485,7 @@
}
/**
+ * Returns the path used when matching this module against rule conditions.
* @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
*/
nameForCondition() {
@@ -696,10 +726,13 @@
if (typeof options === "string") {
if (options.startsWith("{") && options.endsWith("}")) {
try {
- options = parseJson(options);
+ options =
+ /** @type {LoaderItem["options"]} */
+ (parseJson(options));
} catch (err) {
throw new Error(
- `Cannot parse string options: ${/** @type {Error} */ (err).message}`
+ `Cannot parse string options: ${/** @type {Error} */ (err).message}`,
+ { cause: err }
);
}
} else {
@@ -713,9 +746,10 @@
options = {};
}
- if (schema) {
+ if (schema && compilation.options.validate) {
let name = "Loader";
let baseDataPath = "options";
+ /** @type {RegExpExecArray | null} */
let match;
if (schema.title && (match = /^(.+) (.+)$/.exec(schema.title))) {
[, name, baseDataPath] = match;
@@ -849,7 +883,6 @@
return /** @type {AnyLoaderContext} */ (loaderContext);
}
- // TODO remove `loaderContext` in webpack@6
/**
* @param {AnyLoaderContext} loaderContext loader context
* @param {number} index index
@@ -980,6 +1013,7 @@
compilation.compiler.root
);
if (this._sourceSizes !== undefined) this._sourceSizes.clear();
+ /** @type {PreparsedAst | null} */
this._ast =
typeof extraInfo === "object" &&
extraInfo !== null &&
@@ -1217,6 +1251,7 @@
}
/**
+ * Builds the module using the provided compilation context.
* @param {WebpackOptions} options webpack options
* @param {Compilation} compilation the compilation
* @param {ResolverWithOptions} resolver the resolver
@@ -1307,7 +1342,7 @@
/** @type {undefined | Set<string>} */
let nonAbsoluteDependencies;
/**
- * @param {LazySet<string>} deps deps
+ * @param {FileSystemDependencies} deps deps
*/
const checkDependencies = (deps) => {
for (const dep of deps) {
@@ -1420,6 +1455,7 @@
}
/**
+ * Returns the reason this module cannot be concatenated, when one exists.
* @param {ConcatenationBailoutReasonContext} context context
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
*/
@@ -1430,6 +1466,7 @@
}
/**
+ * Gets side effects connection state.
* @param {ModuleGraph} moduleGraph the module graph
* @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
*/
@@ -1478,6 +1515,7 @@
}
/**
+ * Returns the source types this module can generate.
* @returns {SourceTypes} types available (do not mutate)
*/
getSourceTypes() {
@@ -1490,6 +1528,7 @@
}
/**
+ * Generates code and runtime requirements for this module.
* @param {CodeGenerationContext} context context for code generation
* @returns {CodeGenerationResult} result
*/
@@ -1516,6 +1555,7 @@
const getData = () => this._codeGeneratorData;
+ /** @type {Sources} */
const sources = new Map();
for (const type of sourceTypes || chunkGraph.getModuleSourceTypes(this)) {
// TODO webpack@6 make generateError required
@@ -1567,6 +1607,7 @@
}
/**
+ * Gets the original source.
* @returns {Source | null} the original source for the module before webpack transformation
*/
originalSource() {
@@ -1574,6 +1615,7 @@
}
/**
+ * Invalidates the cached state associated with this value.
* @returns {void}
*/
invalidateBuild() {
@@ -1581,6 +1623,7 @@
}
/**
+ * Checks whether the module needs to be rebuilt for the current build state.
* @param {NeedBuildContext} context context info
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
* @returns {void}
@@ -1640,6 +1683,7 @@
}
/**
+ * Returns the estimated size for the requested source type.
* @param {string=} type the source type for which the size should be estimated
* @returns {number} the estimated size of the module (must be non-zero)
*/
@@ -1661,6 +1705,7 @@
}
/**
+ * Adds the provided file dependencies to the module.
* @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
* @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
* @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
@@ -1694,6 +1739,7 @@
}
/**
+ * Updates the hash with the data contributed by this instance.
* @param {Hash} hash the hash used to track dependencies
* @param {UpdateHashContext} context context
* @returns {void}
@@ -1704,6 +1750,15 @@
/** @type {string} */
(buildInfo.hash)
);
+ // Clear cached source types and re-compute so that changes in incoming
+ // connections (e.g. asset module newly referenced from JS via lazy
+ // compilation) are reflected in the hash and trigger code generation
+ // cache invalidation.
+ // https://github.com/webpack/webpack/issues/20800
+ this._sourceTypes = undefined;
+ for (const type of this.getSourceTypes()) {
+ hash.update(type);
+ }
/** @type {Generator} */
(this.generator).updateHash(hash, {
module: this,
@@ -1713,6 +1768,7 @@
}
/**
+ * Serializes this instance into the provided serializer context.
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
@@ -1755,6 +1811,7 @@
}
/**
+ * Restores this instance from the provided deserializer context.
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
--
Gitblit v1.9.3