Skip to content

Commit

Permalink
chore(node-resolve): remove is-builtin-module
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
43081j committed Jun 8, 2024
1 parent 8550c4b commit b20469b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/node-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@rollup/pluginutils": "^5.0.1",
"@types/resolve": "1.20.2",
"deepmerge": "^4.2.2",
"is-builtin-module": "^3.2.1",
"is-module": "^1.0.0",
"resolve": "^1.22.1"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/node-resolve/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-param-reassign, no-shadow, no-undefined */
import { dirname, normalize, resolve, sep } from 'path';

import isBuiltinModule from 'is-builtin-module';
import { builtinModules } from 'module';

import deepMerge from 'deepmerge';
import isModule from 'is-module';

Expand Down Expand Up @@ -42,6 +43,8 @@ const defaults = {
// TODO: set to false in next major release or remove
allowExportsFolderMapping: true
};
const nodeImportPrefix = /^node:/;

export const DEFAULTS = deepFreeze(deepMerge({}, defaults));

export function nodeResolve(opts = {}) {
Expand Down Expand Up @@ -190,7 +193,7 @@ export function nodeResolve(opts = {}) {
allowExportsFolderMapping: options.allowExportsFolderMapping
});

const importeeIsBuiltin = isBuiltinModule(importee);
const importeeIsBuiltin = builtinModules.includes(importee.replace(nodeImportPrefix, ''));
const resolved =
importeeIsBuiltin && preferBuiltins
? {
Expand Down
11 changes: 1 addition & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b20469b

Please sign in to comment.