|
1 | 1 | import fs from 'node:fs' |
2 | | -import { builtinModules } from 'node:module' |
3 | 2 | import path from 'node:path' |
4 | 3 |
|
| 4 | +import isNodeCoreModule from '@nolyfill/is-core-module' |
5 | 5 | import debug from 'debug' |
6 | 6 | import type { FileSystem, ResolveOptions, Resolver } from 'enhanced-resolve' |
7 | 7 | import enhancedResolve from 'enhanced-resolve' |
@@ -119,15 +119,6 @@ let resolver: Resolver | undefined |
119 | 119 | const digestHashObject = (value: object | null | undefined) => |
120 | 120 | hashObject(value ?? {}).digest('hex') |
121 | 121 |
|
122 | | -/** |
123 | | - * Checks if a module is a core module |
124 | | - * module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older |
125 | | - * versions of Node.js, we can use module.isBuiltin instead of this function. |
126 | | - */ |
127 | | -function isBuiltin(moduleName: string) { |
128 | | - return builtinModules.includes(moduleName.replace(/^node:/, '')) |
129 | | -} |
130 | | - |
131 | 122 | /** |
132 | 123 | * @param source the module to resolve; i.e './some-module' |
133 | 124 | * @param file the importing file's full path; i.e. '/usr/local/bin/file.js' |
@@ -172,7 +163,7 @@ export function resolve( |
172 | 163 |
|
173 | 164 | // don't worry about core node/bun modules |
174 | 165 | if ( |
175 | | - isBuiltin(source) || |
| 166 | + isNodeCoreModule(source) || |
176 | 167 | isBunModule(source, (process.versions.bun ?? 'latest') as Version) |
177 | 168 | ) { |
178 | 169 | log('matched core:', source) |
|
0 commit comments