From 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期二, 21 四月 2026 11:46:41 +0800
Subject: [PATCH] 推送

---
 node_modules/webpack/lib/TemplatedPathPlugin.js |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/node_modules/webpack/lib/TemplatedPathPlugin.js b/node_modules/webpack/lib/TemplatedPathPlugin.js
index fafd04b..8774c9a 100644
--- a/node_modules/webpack/lib/TemplatedPathPlugin.js
+++ b/node_modules/webpack/lib/TemplatedPathPlugin.js
@@ -7,10 +7,12 @@
 
 const { basename, extname } = require("path");
 const util = require("util");
-const mime = require("mime-types");
 const Chunk = require("./Chunk");
 const Module = require("./Module");
 const { parseResource } = require("./util/identifier");
+const memoize = require("./util/memoize");
+
+const getMimeTypes = memoize(() => require("./util/mimeTypes"));
 
 /** @typedef {import("./ChunkGraph")} ChunkGraph */
 /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
@@ -18,12 +20,9 @@
 /** @typedef {import("./Compilation").PathData} PathData */
 /** @typedef {import("./Compiler")} Compiler */
 
-const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
+const REGEXP = /\[\\*([\w:]+)\\*\]/g;
 
-/**
- * @param {string | number} id id
- * @returns {string | number} result
- */
+/** @type {PathData["prepareId"]} */
 const prepareId = (id) => {
 	if (typeof id !== "string") return id;
 
@@ -35,10 +34,11 @@
 		} + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
 	}
 
-	return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
+	return id.replace(/(^[.-]|[^a-z0-9_-])+/gi, "_");
 };
 
 /**
+ * Defines the replacer function callback.
  * @callback ReplacerFunction
  * @param {string} match
  * @param {string | undefined} arg
@@ -46,6 +46,7 @@
  */
 
 /**
+ * Returns hash replacer function.
  * @param {ReplacerFunction} replacer replacer
  * @param {((arg0: number) => string) | undefined} handler handler
  * @param {AssetInfo | undefined} assetInfo asset info
@@ -55,6 +56,7 @@
 const hashLength = (replacer, handler, assetInfo, hashName) => {
 	/** @type {Replacer} */
 	const fn = (match, arg, input) => {
+		/** @type {string} */
 		let result;
 		const length = arg && Number.parseInt(arg, 10);
 
@@ -84,6 +86,7 @@
 /** @typedef {(match: string, arg: string | undefined, input: string) => string} Replacer */
 
 /**
+ * Returns replacer.
  * @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
  * @param {boolean=} allowEmpty allow empty
  * @returns {Replacer} replacer
@@ -110,9 +113,11 @@
 	return fn;
 };
 
+/** @type {Map<string, (...args: EXPECTED_ANY[]) => EXPECTED_ANY>} */
 const deprecationCache = new Map();
 const deprecatedFunction = (() => () => {})();
 /**
+ * Returns function with deprecation output.
  * @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T
  * @param {T} fn function
  * @param {string} message message
@@ -137,12 +142,13 @@
 /** @typedef {string | TemplatePathFn} TemplatePath */
 
 /**
+ * Returns the interpolated path.
  * @param {TemplatePath} path the raw path
  * @param {PathData} data context data
- * @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
+ * @param {AssetInfo=} assetInfo extra info about the asset (will be written to)
  * @returns {string} the interpolated path
  */
-const replacePathVariables = (path, data, assetInfo) => {
+const interpolate = (path, data, assetInfo) => {
 	const chunkGraph = data.chunkGraph;
 
 	/** @type {Map<string, Replacer>} */
@@ -164,7 +170,7 @@
 		// check that filename is data uri
 		const match = data.filename.match(/^data:([^;,]+)/);
 		if (match) {
-			const ext = mime.extension(match[1]);
+			const ext = getMimeTypes().extension(match[1]);
 			const emptyReplacer = replacer("", true);
 			// "XXXX" used for `updateHash`, so we don't need it here
 			const contentHash =
@@ -303,7 +309,7 @@
 		const module = data.module;
 
 		const idReplacer = replacer(() =>
-			prepareId(
+			(data.prepareId || prepareId)(
 				module instanceof Module
 					? /** @type {ModuleId} */
 						(/** @type {ChunkGraph} */ (chunkGraph).getModuleId(module))
@@ -353,7 +359,9 @@
 	if (typeof data.runtime === "string") {
 		replacements.set(
 			"runtime",
-			replacer(() => prepareId(/** @type {string} */ (data.runtime)))
+			replacer(() =>
+				(data.prepareId || prepareId)(/** @type {string} */ (data.runtime))
+			)
 		);
 	} else {
 		replacements.set("runtime", replacer("_"));
@@ -385,15 +393,16 @@
 
 class TemplatedPathPlugin {
 	/**
-	 * Apply the plugin
+	 * Applies the plugin by registering its hooks on the compiler.
 	 * @param {Compiler} compiler the compiler instance
 	 * @returns {void}
 	 */
 	apply(compiler) {
 		compiler.hooks.compilation.tap(plugin, (compilation) => {
-			compilation.hooks.assetPath.tap(plugin, replacePathVariables);
+			compilation.hooks.assetPath.tap(plugin, interpolate);
 		});
 	}
 }
 
 module.exports = TemplatedPathPlugin;
+module.exports.interpolate = interpolate;

--
Gitblit v1.9.3