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

fix(node-resolve): support node: protocol #1124

Merged
merged 1 commit into from May 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/node-resolve/package.json
Expand Up @@ -57,8 +57,8 @@
"dependencies": {
"@rollup/pluginutils": "^3.1.0",
"@types/resolve": "1.17.1",
"builtin-modules": "^3.1.0",
"deepmerge": "^4.2.2",
"is-builtin-module": "^3.1.0",
"is-module": "^1.0.0",
"resolve": "^1.19.0"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/node-resolve/src/index.js
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign, no-shadow, no-undefined */
import { dirname, normalize, resolve, sep } from 'path';

import builtinList from 'builtin-modules';
import isBuiltinModule from 'is-builtin-module';
import deepMerge from 'deepmerge';
import isModule from 'is-module';

Expand All @@ -13,7 +13,6 @@ import { fileExists, readFile, realpath } from './fs';
import resolveImportSpecifiers from './resolveImportSpecifiers';
import { getMainFields, getPackageName, normalizeInput } from './util';

const builtins = new Set(builtinList);
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
const deepFreeze = (object) => {
Object.freeze(object);
Expand Down Expand Up @@ -166,7 +165,7 @@ export function nodeResolve(opts = {}) {
ignoreSideEffectsForRoot
});

const importeeIsBuiltin = builtins.has(importee);
const importeeIsBuiltin = isBuiltinModule(importee);
const resolved =
importeeIsBuiltin && preferBuiltins
? {
Expand Down
1 change: 1 addition & 0 deletions packages/node-resolve/test/fixtures/node-protocol.js
@@ -0,0 +1 @@
import 'node:fs';
13 changes: 13 additions & 0 deletions packages/node-resolve/test/prefer-builtins.js
Expand Up @@ -103,3 +103,16 @@ test('does not warn when using a builtin module when there is no local version,

t.is(warning, null);
});

test('detects builtins imported with node: protocol', async (t) => {
const warnings = [];
await rollup({
input: 'node-protocol.js',
onwarn({ message }) {
warnings.push(message);
},
plugins: [nodeResolve()]
});

t.is(warnings.length, 0);
});
24 changes: 10 additions & 14 deletions pnpm-lock.yaml

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