Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(node-resolve): remove is-builtin-module #1735

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause a behavior change if you're bundling on one version of node, but a newer node has that module available? Or does it not matter because node will never add any new module without the node: prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unlikely they will add any new modules without the prefix as far as I understand

Also the third party package also has a fixed list which won't always be accurate to the runtime node


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.

Loading