Skip to content

Commit 190aa21

Browse files
authored
chore(node-resolve): remove is-builtin-module (#1735)
Node has shipped `builtinModules` for some time now, so we no longer need a third party package to do this. Once the `engines` constraint is bumped in the `package.json`, we can also move to using the built-in `isBuiltin` function (available since 16.x).
1 parent 1b2ce15 commit 190aa21

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

Diff for: packages/node-resolve/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"@rollup/pluginutils": "^5.0.1",
6565
"@types/resolve": "1.20.2",
6666
"deepmerge": "^4.2.2",
67-
"is-builtin-module": "^3.2.1",
6867
"is-module": "^1.0.0",
6968
"resolve": "^1.22.1"
7069
},

Diff for: packages/node-resolve/src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable no-param-reassign, no-shadow, no-undefined */
22
import { dirname, normalize, resolve, sep } from 'path';
33

4-
import isBuiltinModule from 'is-builtin-module';
4+
import { builtinModules } from 'module';
5+
56
import deepMerge from 'deepmerge';
67
import isModule from 'is-module';
78

@@ -42,6 +43,8 @@ const defaults = {
4243
// TODO: set to false in next major release or remove
4344
allowExportsFolderMapping: true
4445
};
46+
const nodeImportPrefix = /^node:/;
47+
4548
export const DEFAULTS = deepFreeze(deepMerge({}, defaults));
4649

4750
export function nodeResolve(opts = {}) {
@@ -190,7 +193,7 @@ export function nodeResolve(opts = {}) {
190193
allowExportsFolderMapping: options.allowExportsFolderMapping
191194
});
192195

193-
const importeeIsBuiltin = isBuiltinModule(importee);
196+
const importeeIsBuiltin = builtinModules.includes(importee.replace(nodeImportPrefix, ''));
194197
const resolved =
195198
importeeIsBuiltin && preferBuiltins
196199
? {

Diff for: pnpm-lock.yaml

+1-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)