* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 51 | * @returns {void} |
| 52 | */ |
| 53 | apply(compiler) { |
| 54 | // TODO webpack 6 remove string support |
| 55 | if (typeof this.options !== "string") { |
| 56 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 57 | compiler.validate( |
| 58 | () => |
| 59 | require("../../schemas/plugins/sharing/ConsumeSharedPlugin.json"), |
| 60 | this.options, |
| 61 | { |
| 62 | name: "Consume Shared Plugin", |
| 63 | baseDataPath: "options" |
| 64 | }, |
| 65 | (options) => |
| 66 | require("../../schemas/plugins/sharing/ConsumeSharedPlugin.check")( |
| 67 | options |
| 68 | ) |
| 69 | ); |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | /** @type {[string, ConsumeOptions][]} */ |
| 74 | const consumes = parseOptions( |
| 75 | this.options.consumes, |
| 76 | (item, key) => { |
| 77 | if (Array.isArray(item)) throw new Error("Unexpected array in options"); |
| 78 | /** @type {ConsumeOptions} */ |
| 79 | const result = |
| 80 | item === key || !isRequiredVersion(item) |
| 81 | ? // item is a request/key |
| 82 | { |
| 83 | import: key, |
| 84 | shareScope: this.options.shareScope || "default", |
| 85 | shareKey: key, |
| 86 | requiredVersion: undefined, |
| 87 | packageName: undefined, |
| 88 | strictVersion: false, |
| 89 | singleton: false, |
| 90 | eager: false |
| 91 | } |
| 92 | : // key is a request/key |
| 93 | // item is a version |
| 94 | { |
| 95 | import: key, |
| 96 | shareScope: this.options.shareScope || "default", |
| 97 | shareKey: key, |
| 98 | requiredVersion: parseRange(item), |
| 99 | strictVersion: true, |
| 100 | packageName: undefined, |
| 101 | singleton: false, |
| 102 | eager: false |
| 103 | }; |
| 104 | return result; |
| 105 | }, |
| 106 | (item, key) => ({ |
| 107 | import: item.import === false ? undefined : item.import || key, |
| 108 | shareScope: item.shareScope || this.options.shareScope || "default", |
| 109 | shareKey: item.shareKey || key, |
| 110 | requiredVersion: |
nothing calls this directly
no test coverage detected