( request, externalType, runtimeTemplate )
| 126 | * @returns {string | string[]} the normalized request |
| 127 | */ |
| 128 | const 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. |
no test coverage detected