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

Method apply

lib/dependencies/ProvidedDependency.js:115–160  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Dependency} dependency the dependency for which the template should be applied * @param {ReplaceSource} source the current replace source which can be modified * @param {DependencyTemplateContext} templateContext the cont

(
		dependency,
		source,
		{
			runtime,
			runtimeTemplate,
			moduleGraph,
			chunkGraph,
			initFragments,
			runtimeRequirements
		}
	)

Source from the content-addressed store, hash-verified

113 * @returns {void}
114 */
115 apply(
116 dependency,
117 source,
118 {
119 runtime,
120 runtimeTemplate,
121 moduleGraph,
122 chunkGraph,
123 initFragments,
124 runtimeRequirements
125 }
126 ) {
127 const dep = /** @type {ProvidedDependency} */ (dependency);
128 const connection =
129 /** @type {ModuleGraphConnection} */
130 (moduleGraph.getConnection(dep));
131 const exportsInfo = moduleGraph.getExportsInfo(connection.module);
132 const usedName = exportsInfo.getUsedName(dep.ids, runtime);
133
134 const moduleRaw = runtimeTemplate.moduleRaw({
135 module: moduleGraph.getModule(dep),
136 chunkGraph,
137 request: dep.request,
138 runtimeRequirements
139 });
140
141 const provided = !usedName
142 ? moduleRaw
143 : usedName instanceof InlinedUsedName
144 ? `(${moduleRaw}, ${usedName.render(
145 Template.toNormalComment(
146 `inlined export ${propertyAccess(dep.ids)}`
147 )
148 )})`
149 : `${moduleRaw}${propertyAccess(/** @type {string[]} */ (usedName), 0)}`;
150
151 initFragments.push(
152 new InitFragment(
153 `/* provided dependency */ var ${dep.identifier} = ${provided};\n`,
154 InitFragment.STAGE_PROVIDES,
155 1,
156 `provided ${dep.identifier}`
157 )
158 );
159 source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
160 }
161}
162
163ProvidedDependency.Template = ProvidedDependencyTemplate;

Callers

nothing calls this directly

Calls 10

propertyAccessFunction · 0.85
getConnectionMethod · 0.80
getExportsInfoMethod · 0.80
moduleRawMethod · 0.80
toNormalCommentMethod · 0.80
getUsedNameMethod · 0.45
getModuleMethod · 0.45
renderMethod · 0.45
pushMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected