* Creates an instance of SharePlugin. * @param {SharePluginOptions} options options
(options)
| 22 | * @param {SharePluginOptions} options options |
| 23 | */ |
| 24 | constructor(options) { |
| 25 | /** @type {[string, SharedConfig][]} */ |
| 26 | const sharedOptions = parseOptions( |
| 27 | options.shared, |
| 28 | (item, key) => { |
| 29 | if (typeof item !== "string") { |
| 30 | throw new Error("Unexpected array in shared"); |
| 31 | } |
| 32 | /** @type {SharedConfig} */ |
| 33 | const config = |
| 34 | item === key || !isRequiredVersion(item) |
| 35 | ? { |
| 36 | import: item |
| 37 | } |
| 38 | : { |
| 39 | import: key, |
| 40 | requiredVersion: item |
| 41 | }; |
| 42 | return config; |
| 43 | }, |
| 44 | (item) => item |
| 45 | ); |
| 46 | /** @type {Record<string, ConsumesConfig>[]} */ |
| 47 | const consumes = sharedOptions.map(([key, options]) => ({ |
| 48 | [key]: { |
| 49 | import: options.import, |
| 50 | shareKey: options.shareKey || key, |
| 51 | shareScope: options.shareScope, |
| 52 | requiredVersion: options.requiredVersion, |
| 53 | strictVersion: options.strictVersion, |
| 54 | singleton: options.singleton, |
| 55 | packageName: options.packageName, |
| 56 | eager: options.eager |
| 57 | } |
| 58 | })); |
| 59 | /** @type {Record<string, ProvidesConfig>[]} */ |
| 60 | const provides = sharedOptions |
| 61 | .filter(([, options]) => options.import !== false) |
| 62 | .map(([key, options]) => ({ |
| 63 | [options.import || key]: { |
| 64 | shareKey: options.shareKey || key, |
| 65 | shareScope: options.shareScope, |
| 66 | version: options.version, |
| 67 | eager: options.eager |
| 68 | } |
| 69 | })); |
| 70 | /** @type {string | undefined} */ |
| 71 | this._shareScope = options.shareScope; |
| 72 | /** @type {Record<string, ConsumesConfig>[]} */ |
| 73 | this._consumes = consumes; |
| 74 | /** @type {Record<string, ProvidesConfig>[]} */ |
| 75 | this._provides = provides; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Applies the plugin by registering its hooks on the compiler. |
nothing calls this directly
no test coverage detected