MCPcopy
hub / github.com/webpack/webpack / normalizeNodeCoreModuleRequest

Function normalizeNodeCoreModuleRequest

lib/ExternalModule.js:128–154  ·  view source on GitHub ↗
(
	request,
	externalType,
	runtimeTemplate
)

Source from the content-addressed store, hash-verified

126 * @returns {string | string[]} the normalized request
127 */
128const normalizeNodeCoreModuleRequest = (
129 request,
130 externalType,
131 runtimeTemplate
132) => {
133 if (!NODE_RESOLVING_EXTERNAL_TYPES.has(externalType)) return request;
134 const name = Array.isArray(request) ? request[0] : request;
135 if (typeof name !== "string") return request;
136 /**
137 * @param {string} next replacement specifier
138 * @returns {string | string[]} request with the specifier swapped
139 */
140 const withName = (next) =>
141 Array.isArray(request) ? [next, ...request.slice(1)] : next;
142
143 if (
144 runtimeTemplate.outputOptions.environment.nodePrefixForCoreModules === false
145 ) {
146 if (!name.startsWith(NODE_PREFIX)) return request;
147 const stripped = name.slice(NODE_PREFIX.length);
148 return coreModules.has(stripped) ? withName(stripped) : request;
149 }
150 if (runtimeTemplate.isUniversalTarget() && !name.startsWith(NODE_PREFIX)) {
151 return coreModules.has(name) ? withName(NODE_PREFIX + name) : request;
152 }
153 return request;
154};
155
156/**
157 * Gets source for global variable external.

Callers 1

_getSourceDataMethod · 0.85

Calls 5

isArrayMethod · 0.80
sliceMethod · 0.80
withNameFunction · 0.70
hasMethod · 0.45
isUniversalTargetMethod · 0.45

Tested by

no test coverage detected