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/sharing/ProvideSharedPlugin.js | 96 +++++++++++++++++++++++++----------------------
1 files changed, 51 insertions(+), 45 deletions(-)
diff --git a/node_modules/webpack/lib/sharing/ProvideSharedPlugin.js b/node_modules/webpack/lib/sharing/ProvideSharedPlugin.js
index 5ad4c3d..f4fe9a6 100644
--- a/node_modules/webpack/lib/sharing/ProvideSharedPlugin.js
+++ b/node_modules/webpack/lib/sharing/ProvideSharedPlugin.js
@@ -7,7 +7,6 @@
const WebpackError = require("../WebpackError");
const { parseOptions } = require("../container/options");
-const createSchemaValidation = require("../util/create-schema-validation");
const ProvideForSharedDependency = require("./ProvideForSharedDependency");
const ProvideSharedDependency = require("./ProvideSharedDependency");
const ProvideSharedModuleFactory = require("./ProvideSharedModuleFactory");
@@ -17,16 +16,8 @@
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../NormalModuleFactory").NormalModuleCreateData} NormalModuleCreateData */
-const validate = createSchemaValidation(
- require("../../schemas/plugins/sharing/ProvideSharedPlugin.check"),
- () => require("../../schemas/plugins/sharing/ProvideSharedPlugin.json"),
- {
- name: "Provide Shared Plugin",
- baseDataPath: "options"
- }
-);
-
/**
+ * Defines the provide options type used by this module.
* @typedef {object} ProvideOptions
* @property {string} shareKey
* @property {string} shareScope
@@ -40,48 +31,62 @@
class ProvideSharedPlugin {
/**
+ * Creates an instance of ProvideSharedPlugin.
* @param {ProvideSharedPluginOptions} options options
*/
constructor(options) {
- validate(options);
-
- this._provides = /** @type {[string, ProvideOptions][]} */ (
- parseOptions(
- options.provides,
- (item) => {
- if (Array.isArray(item)) {
- throw new Error("Unexpected array of provides");
- }
- /** @type {ProvideOptions} */
- const result = {
- shareKey: item,
- version: undefined,
- shareScope: options.shareScope || "default",
- eager: false
- };
- return result;
- },
- (item) => ({
- shareKey: item.shareKey,
- version: item.version,
- shareScope: item.shareScope || options.shareScope || "default",
- eager: Boolean(item.eager)
- })
- )
- );
- this._provides.sort(([a], [b]) => {
- if (a < b) return -1;
- if (b < a) return 1;
- return 0;
- });
+ 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/sharing/ProvideSharedPlugin.json"),
+ this.options,
+ {
+ name: "Provide Shared Plugin",
+ baseDataPath: "options"
+ },
+ (options) =>
+ require("../../schemas/plugins/sharing/ProvideSharedPlugin.check")(
+ options
+ )
+ );
+ });
+
+ /** @type {[string, ProvideOptions][]} */
+ const provides = parseOptions(
+ this.options.provides,
+ (item) => {
+ if (Array.isArray(item)) {
+ throw new Error("Unexpected array of provides");
+ }
+ /** @type {ProvideOptions} */
+ const result = {
+ shareKey: item,
+ version: undefined,
+ shareScope: this.options.shareScope || "default",
+ eager: false
+ };
+ return result;
+ },
+ (item) => ({
+ shareKey: /** @type {string} */ (item.shareKey),
+ version: item.version,
+ shareScope: item.shareScope || this.options.shareScope || "default",
+ eager: Boolean(item.eager)
+ })
+ ).sort(([a], [b]) => {
+ if (a < b) return -1;
+ if (b < a) return 1;
+ return 0;
+ });
+
/** @type {WeakMap<Compilation, ResolvedProvideMap>} */
const compilationData = new WeakMap();
@@ -94,14 +99,14 @@
const matchProvides = new Map();
/** @type {Map<string, ProvideOptions>} */
const prefixMatchProvides = new Map();
- for (const [request, config] of this._provides) {
- if (/^(\/|[A-Za-z]:\\|\\\\|\.\.?(\/|$))/.test(request)) {
+ for (const [request, config] of provides) {
+ if (/^(?:\/|[A-Z]:\\|\\\\|\.\.?(?:\/|$))/i.test(request)) {
// relative request
resolvedProvideMap.set(request, {
config,
version: config.version
});
- } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
+ } else if (/^(?:\/|[A-Z]:\\|\\\\)/i.test(request)) {
// absolute path
resolvedProvideMap.set(request, {
config,
@@ -117,6 +122,7 @@
}
compilationData.set(compilation, resolvedProvideMap);
/**
+ * Provide shared module.
* @param {string} key key
* @param {ProvideOptions} config config
* @param {NormalModuleCreateData["resource"]} resource resource
--
Gitblit v1.9.3