MCPcopy
hub / github.com/webpack/webpack / applyNodeDefaults

Function applyNodeDefaults

lib/config/defaults.js:2099–2134  ·  view source on GitHub ↗
(
	node,
	{ futureDefaults, outputModule, targetProperties }
)

Source from the content-addressed store, hash-verified

2097 * @returns {void}
2098 */
2099const applyNodeDefaults = (
2100 node,
2101 { futureDefaults, outputModule, targetProperties }
2102) => {
2103 if (node === false) return;
2104
2105 F(node, "global", () => {
2106 if (targetProperties && targetProperties.global) return false;
2107 // We use `warm` because overriding `global` with `globalThis` (or a polyfill) is sometimes safe (global.URL), sometimes unsafe (global.process), but we need to warn about it
2108 return futureDefaults ? "warn" : true;
2109 });
2110
2111 const handlerForNames = () => {
2112 // TODO webpack@6 remove `node-module` in favor of `eval-only`
2113 if (targetProperties) {
2114 if (targetProperties.node) {
2115 return "eval-only";
2116 }
2117
2118 // For the "universal" target we only evaluate these values
2119 if (
2120 outputModule &&
2121 targetProperties.node === null &&
2122 targetProperties.web === null
2123 ) {
2124 return "eval-only";
2125 }
2126 }
2127
2128 // TODO webpack@6 should we use `warn-even-only`?
2129 return futureDefaults ? "warn-mock" : "mock";
2130 };
2131
2132 F(node, "__filename", handlerForNames);
2133 F(node, "__dirname", handlerForNames);
2134};
2135
2136/**
2137 * Apply performance defaults.

Callers 1

Calls 1

FFunction · 0.70

Tested by

no test coverage detected