Skip to content

Commit 0f757bc

Browse files
guybedfordMylesBorins
authored andcommittedNov 16, 2020
esm: use "node:" namespace for builtins
Backport-PR-URL: #35757 PR-URL: #35387 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1f34230 commit 0f757bc

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed
 

‎doc/api/esm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ The resolver can throw the following errors:
10071007
> 1. If _selfUrl_ is not **undefined**, return _selfUrl_.
10081008
> 1. If _packageSubpath_ is _"."_ and _packageName_ is a Node.js builtin
10091009
> module, then
1010-
> 1. Return the string _"nodejs:"_ concatenated with _packageSpecifier_.
1010+
> 1. Return the string _"node:"_ concatenated with _packageSpecifier_.
10111011
> 1. While _parentURL_ is not the file system root,
10121012
> 1. Let _packageURL_ be the URL resolution of _"node_modules/"_
10131013
> concatenated with _packageSpecifier_, relative to _parentURL_.

‎lib/internal/modules/esm/get_format.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (experimentalJsonModules)
3434
extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json';
3535

3636
function defaultGetFormat(url, context, defaultGetFormatUnused) {
37-
if (StringPrototypeStartsWith(url, 'nodejs:')) {
37+
if (StringPrototypeStartsWith(url, 'node:')) {
3838
return { format: 'builtin' };
3939
}
4040
const parsed = new URL(url);

‎lib/internal/modules/esm/resolve.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,13 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
750750
};
751751
}
752752
} catch {}
753-
if (parsed && parsed.protocol === 'nodejs:')
753+
if (parsed && parsed.protocol === 'node:')
754754
return { url: specifier };
755755
if (parsed && parsed.protocol !== 'file:' && parsed.protocol !== 'data:')
756756
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed);
757757
if (NativeModule.canBeRequiredByUsers(specifier)) {
758758
return {
759-
url: 'nodejs:' + specifier
759+
url: 'node:' + specifier
760760
};
761761
}
762762
if (parentURL && StringPrototypeStartsWith(parentURL, 'data:')) {

‎lib/internal/modules/esm/translators.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ function cjsPreparseModuleExports(filename) {
261261
// through normal resolution
262262
translators.set('builtin', async function builtinStrategy(url) {
263263
debug(`Translating BuiltinModule ${url}`);
264-
// Slice 'nodejs:' scheme
265-
const id = url.slice(7);
264+
// Slice 'node:' scheme
265+
const id = url.slice(5);
266266
const module = loadNativeModule(id, url, true);
267-
if (!url.startsWith('nodejs:') || !module) {
268-
throw new ERR_UNKNOWN_BUILTIN_MODULE(id);
267+
if (!url.startsWith('node:') || !module) {
268+
throw new ERR_UNKNOWN_BUILTIN_MODULE(url);
269269
}
270270
debug(`Loading BuiltinModule ${url}`);
271271
return module.getESMFacade();

‎test/es-module/test-esm-dynamic-import.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ function expectFsNamespace(result) {
4848
expectFsNamespace(import('fs'));
4949
expectFsNamespace(eval('import("fs")'));
5050
expectFsNamespace(eval('import("fs")'));
51-
expectFsNamespace(import('nodejs:fs'));
51+
expectFsNamespace(import('node:fs'));
5252

53-
expectModuleError(import('nodejs:unknown'),
53+
expectModuleError(import('node:unknown'),
5454
'ERR_UNKNOWN_BUILTIN_MODULE');
5555
expectModuleError(import('./not-an-existing-module.mjs'),
5656
'ERR_MODULE_NOT_FOUND');

‎test/fixtures/es-module-loaders/example-loader.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ baseURL.pathname = process.cwd() + '/';
1111
export function resolve(specifier, { parentURL = baseURL }, defaultResolve) {
1212
if (builtinModules.includes(specifier)) {
1313
return {
14-
url: 'nodejs:' + specifier
14+
url: 'node:' + specifier
1515
};
1616
}
1717
if (/^\.{1,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
@@ -27,7 +27,7 @@ export function resolve(specifier, { parentURL = baseURL }, defaultResolve) {
2727
}
2828

2929
export function getFormat(url, context, defaultGetFormat) {
30-
if (url.startsWith('nodejs:') && builtinModules.includes(url.slice(7))) {
30+
if (url.startsWith('node:') && builtinModules.includes(url.slice(5))) {
3131
return {
3232
format: 'builtin'
3333
};

‎test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export async function resolve(specifier, { parentURL }, defaultResolve) {
22
if (specifier === 'unknown-builtin-module') {
33
return {
4-
url: 'nodejs:unknown-builtin-module'
4+
url: 'node:unknown-builtin-module'
55
};
66
}
77
return defaultResolve(specifier, {parentURL}, defaultResolve);
88
}
99

1010
export async function getFormat(url, context, defaultGetFormat) {
11-
if (url === 'nodejs:unknown-builtin-module') {
11+
if (url === 'node:unknown-builtin-module') {
1212
return {
1313
format: 'builtin'
1414
};

‎test/fixtures/es-module-loaders/not-found-assert-loader.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function resolve(specifier, { parentURL }, defaultResolve) {
1414
catch (e) {
1515
assert.strictEqual(e.code, 'ERR_MODULE_NOT_FOUND');
1616
return {
17-
url: 'nodejs:fs'
17+
url: 'node:fs'
1818
};
1919
}
2020
assert.fail(`Module resolution for ${specifier} should be throw ERR_MODULE_NOT_FOUND`);

‎test/parallel/test-loaders-unknown-builtin-module.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { expectsError, mustCall } from '../common/index.mjs';
33
import assert from 'assert';
44

5-
const unknownBuiltinModule = 'unknown-builtin-module';
5+
const unknownBuiltinModule = 'node:unknown-builtin-module';
66

77
import(unknownBuiltinModule)
88
.then(assert.fail, expectsError({

0 commit comments

Comments
 (0)
Please sign in to comment.