MCPcopy
hub / github.com/webpack/webpack / setUrlModuleConstant

Method setUrlModuleConstant

lib/NodeStuffPlugin.js:251–356  ·  view source on GitHub ↗
(
					parser,
					expressionName,
					property,
					value
				)

Source from the content-addressed store, hash-verified

249 * @returns {void}
250 */
251 const setUrlModuleConstant = (
252 parser,
253 expressionName,
254 property,
255 value
256 ) => {
257 parser.hooks.expression
258 .for(expressionName)
259 .tap(PLUGIN_NAME, (expr) => {
260 // We use `CachedConstDependency` because of `eval` devtool, there is no `import.meta` inside `eval()`
261 const { importMetaName, environment, module } =
262 compilation.outputOptions;
263
264 // Generate `import.meta.dirname` and `import.meta.filename` when:
265 // - they are supported by the environment
266 // - it is a universal target, because we can't use `import mod from "node:url"; ` at the top file
267 if (
268 environment.importMetaDirnameAndFilename ||
269 (compiler.platform.web === null &&
270 compiler.platform.node === null &&
271 module)
272 ) {
273 const dep = new CachedConstDependency(
274 `${importMetaName}.${property}`,
275 /** @type {Range} */
276 (expr.range),
277 `__webpack_${property}__`,
278 CachedConstDependency.PLACE_CHUNK
279 );
280
281 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
282 parser.state.module.addPresentationalDependency(dep);
283 return;
284 }
285
286 const dep = new ExternalModuleDependency(
287 "url",
288 [
289 {
290 name: "fileURLToPath",
291 value: URL_MODULE_CONSTANT_FUNCTION_NAME
292 }
293 ],
294 undefined,
295 `${URL_MODULE_CONSTANT_FUNCTION_NAME}(${value()})`,
296 /** @type {Range} */ (expr.range),
297 `__webpack_${property}__`,
298 ExternalModuleDependency.PLACE_CHUNK
299 );
300 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
301 parser.state.module.addPresentationalDependency(dep);
302
303 return true;
304 });
305
306 if (
307 expressionName === IMPORT_META_FILENAME ||
308 expressionName === IMPORT_META_DIRNAME

Callers

nothing calls this directly

Calls 3

valueFunction · 0.85
tapMethod · 0.80

Tested by

no test coverage detected