* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 46 | * @returns {void} |
| 47 | */ |
| 48 | apply(compiler) { |
| 49 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 50 | compiler.validate( |
| 51 | () => require("../../schemas/plugins/sharing/ProvideSharedPlugin.json"), |
| 52 | this.options, |
| 53 | { |
| 54 | name: "Provide Shared Plugin", |
| 55 | baseDataPath: "options" |
| 56 | }, |
| 57 | (options) => |
| 58 | require("../../schemas/plugins/sharing/ProvideSharedPlugin.check")( |
| 59 | options |
| 60 | ) |
| 61 | ); |
| 62 | }); |
| 63 | |
| 64 | /** @type {[string, ProvideOptions][]} */ |
| 65 | const provides = parseOptions( |
| 66 | this.options.provides, |
| 67 | (item) => { |
| 68 | if (Array.isArray(item)) { |
| 69 | throw new Error("Unexpected array of provides"); |
| 70 | } |
| 71 | /** @type {ProvideOptions} */ |
| 72 | const result = { |
| 73 | shareKey: item, |
| 74 | version: undefined, |
| 75 | shareScope: this.options.shareScope || "default", |
| 76 | eager: false |
| 77 | }; |
| 78 | return result; |
| 79 | }, |
| 80 | (item) => ({ |
| 81 | shareKey: /** @type {string} */ (item.shareKey), |
| 82 | version: item.version, |
| 83 | shareScope: item.shareScope || this.options.shareScope || "default", |
| 84 | eager: Boolean(item.eager) |
| 85 | }) |
| 86 | ).sort(([a], [b]) => { |
| 87 | if (a < b) return -1; |
| 88 | if (b < a) return 1; |
| 89 | return 0; |
| 90 | }); |
| 91 | |
| 92 | /** @type {WeakMap<Compilation, ResolvedProvideMap>} */ |
| 93 | const compilationData = new WeakMap(); |
| 94 | |
| 95 | compiler.hooks.compilation.tap( |
| 96 | PLUGIN_NAME, |
| 97 | (compilation, { normalModuleFactory }) => { |
| 98 | /** @type {ResolvedProvideMap} */ |
| 99 | const resolvedProvideMap = new Map(); |
| 100 | /** @type {Map<string, ProvideOptions>} */ |
| 101 | const matchProvides = new Map(); |
| 102 | /** @type {Map<string, ProvideOptions>} */ |
| 103 | const prefixMatchProvides = new Map(); |
| 104 | for (const [request, config] of provides) { |
| 105 | if (/^\.\.?(?:\/|$)/.test(request)) { |
nothing calls this directly
no test coverage detected