MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/sharing/ConsumeSharedPlugin.js:53–384  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 13

parseOptionsFunction · 0.85
isRequiredVersionFunction · 0.85
parseRangeFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
isArrayMethod · 0.80
sliceMethod · 0.80
addRuntimeModuleMethod · 0.80
resolveMethod · 0.65
requireFunction · 0.50
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected