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/ManifestPlugin.js |   70 +++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/node_modules/webpack/lib/ManifestPlugin.js b/node_modules/webpack/lib/ManifestPlugin.js
index cd9e954..9076292 100644
--- a/node_modules/webpack/lib/ManifestPlugin.js
+++ b/node_modules/webpack/lib/ManifestPlugin.js
@@ -8,7 +8,6 @@
 const { RawSource } = require("webpack-sources");
 const Compilation = require("./Compilation");
 const HotUpdateChunk = require("./HotUpdateChunk");
-const createSchemaValidation = require("./util/create-schema-validation");
 
 /** @typedef {import("./Compiler")} Compiler */
 /** @typedef {import("./Chunk")} Chunk */
@@ -22,18 +21,14 @@
 /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestEntrypoint} ManifestEntrypoint */
 /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestItem} ManifestItem */
 
+/** @typedef {(item: ManifestItem) => boolean} Filter */
+/** @typedef {(manifest: ManifestObject) => ManifestObject} Generate */
+/** @typedef {(manifest: ManifestObject) => string} Serialize */
+
 const PLUGIN_NAME = "ManifestPlugin";
 
-const validate = createSchemaValidation(
-	require("../schemas/plugins/ManifestPlugin.check"),
-	() => require("../schemas/plugins/ManifestPlugin.json"),
-	{
-		name: "ManifestPlugin",
-		baseDataPath: "options"
-	}
-);
-
 /**
+ * Returns extname.
  * @param {string} filename filename
  * @returns {string} extname
  */
@@ -42,32 +37,48 @@
 	const split = replaced.split(".");
 	const last = split.pop();
 	if (!last) return "";
-	return last && /^(gz|br|map)$/i.test(last) ? `${split.pop()}.${last}` : last;
+	return last && /^(?:gz|br|map)$/i.test(last)
+		? `${split.pop()}.${last}`
+		: last;
 };
+
+const DEFAULT_PREFIX = "[publicpath]";
+const DEFAULT_FILENAME = "manifest.json";
 
 class ManifestPlugin {
 	/**
+	 * Creates an instance of ManifestPlugin.
 	 * @param {ManifestPluginOptions} options options
 	 */
-	constructor(options) {
-		validate(options);
-
-		/** @type {ManifestPluginOptions & Required<Omit<ManifestPluginOptions,  "filter" | "generate">>} */
-		this.options = {
-			filename: "manifest.json",
-			prefix: "[publicpath]",
-			entrypoints: true,
-			serialize: (manifest) => JSON.stringify(manifest, null, 2),
-			...options
-		};
+	constructor(options = {}) {
+		/** @type {ManifestPluginOptions} */
+		this.options = options;
 	}
 
 	/**
-	 * 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.validate.tap(PLUGIN_NAME, () => {
+			compiler.validate(
+				() => require("../schemas/plugins/ManifestPlugin.json"),
+				this.options,
+				{
+					name: "ManifestPlugin",
+					baseDataPath: "options"
+				},
+				(options) => require("../schemas/plugins/ManifestPlugin.check")(options)
+			);
+		});
+
+		const entrypoints =
+			this.options.entrypoints !== undefined ? this.options.entrypoints : true;
+		const serialize =
+			this.options.serialize ||
+			((manifest) => JSON.stringify(manifest, null, 2));
+
 		compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
 			compilation.hooks.processAssets.tap(
 				{
@@ -81,6 +92,7 @@
 					);
 
 					/**
+					 * Creates a hash reg exp.
 					 * @param {string | string[]} value value
 					 * @returns {RegExp} regexp to remove hash
 					 */
@@ -91,6 +103,7 @@
 						);
 
 					/**
+					 * Removes the provided name from the manifest plugin.
 					 * @param {string} name name
 					 * @param {AssetInfo | null} info asset info
 					 * @returns {string} hash removed name
@@ -104,6 +117,7 @@
 					};
 
 					/**
+					 * Returns chunk name or chunk id.
 					 * @param {Chunk} chunk chunk
 					 * @returns {ChunkName | ChunkId} chunk name or chunk id
 					 */
@@ -116,11 +130,12 @@
 					/** @type {ManifestObject} */
 					let manifest = {};
 
-					if (this.options.entrypoints) {
+					if (entrypoints) {
 						/** @type {ManifestObject["entrypoints"]} */
 						const entrypoints = {};
 
 						for (const [name, entrypoint] of compilation.entrypoints) {
+							/** @type {string[]} */
 							const imports = [];
 
 							for (const chunk of entrypoint.chunks) {
@@ -154,6 +169,7 @@
 					const added = new Set();
 
 					/**
+					 * Processes the provided file.
 					 * @param {string} file file
 					 * @param {string=} usedName usedName
 					 * @returns {void}
@@ -171,7 +187,7 @@
 							// Fallback for unofficial plugins, just remove hash from filename
 							removeHash(file, asset.info);
 
-						const prefix = this.options.prefix.replace(
+						const prefix = (this.options.prefix || DEFAULT_PREFIX).replace(
 							/\[publicpath\]/gi,
 							() => (publicPath === "auto" ? "/" : publicPath)
 						);
@@ -222,8 +238,8 @@
 					}
 
 					compilation.emitAsset(
-						this.options.filename,
-						new RawSource(this.options.serialize(manifest)),
+						this.options.filename || DEFAULT_FILENAME,
+						new RawSource(serialize(manifest)),
 						{ manifest: true }
 					);
 				}

--
Gitblit v1.9.3