| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c5b0862 commit b5a2c07
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,15 +21,17 @@ added: | |||
| 21 | 21 | - v9.3.0 | |
| 22 | 22 | - v8.10.0 | |
| 23 | 23 | - v6.13.0 | |
| 24 | + changes: | ||
| 25 | + - version: REPLACEME | ||
| 26 | + pr-url: https://github.com/nodejs/node/pull/56185 | ||
| 27 | + description: The list now also contains prefix-only modules. | ||
| 24 | 28 | --> | |
| 25 | 29 | ||
| 26 | 30 | * {string\[]} | |
| 27 | 31 | ||
| 28 | 32 | A list of the names of all modules provided by Node.js. Can be used to verify | |
| 29 | 33 | if a module is maintained by a third party or not. | |
| 30 | 34 | ||
| 31 | - Note: the list doesn't contain [prefix-only modules][] like `node:test`. | ||
| 32 | - | ||
| 33 | 35 | `module` in this context isn't the same object that's provided | |
| 34 | 36 | by the [module wrapper][]. To access it, require the `Module` module: | |
| 35 | 37 | ||
@@ -1723,7 +1725,6 @@ returned object contains the following keys: | |||
| 1723 | 1725 | [load hook]: #loadurl-context-nextload | |
| 1724 | 1726 | [module compile cache]: #module-compile-cache | |
| 1725 | 1727 | [module wrapper]: modules.md#the-module-wrapper | |
| 1726 | - [prefix-only modules]: modules.md#built-in-modules-with-mandatory-node-prefix | ||
| 1727 | 1728 | [realm]: https://tc39.es/ecma262/#realm | |
| 1728 | 1729 | [resolve hook]: #resolvespecifier-context-nextresolve | |
| 1729 | 1730 | [source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -513,7 +513,7 @@ Some built-in modules are always preferentially loaded if their identifier is | |||
| 513 | 513 | passed to `require()`. For instance, `require('http')` will always | |
| 514 | 514 | return the built-in HTTP module, even if there is a file by that name. The list | |
| 515 | 515 | of built-in modules that can be loaded without using the `node:` prefix is exposed | |
| 516 | - as [`module.builtinModules`][]. | ||
| 516 | + in [`module.builtinModules`][], listed without the prefix. | ||
| 517 | 517 | ||
| 518 | 518 | ### Built-in modules with mandatory `node:` prefix | |
| 519 | 519 | ||
@@ -527,6 +527,8 @@ taken the name. Currently the built-in modules that requires the `node:` prefix | |||
| 527 | 527 | * [`node:test`][] | |
| 528 | 528 | * [`node:test/reporters`][] | |
| 529 | 529 | ||
| 530 | + The list of these modules is exposed in [`module.builtinModules`][], including the prefix. | ||
| 531 | + | ||
| 530 | 532 | ## Cycles | |
| 531 | 533 | ||
| 532 | 534 | <!--type=misc--> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,7 @@ const { | |||
| 54 | 54 | ArrayPrototypeIncludes, | |
| 55 | 55 | ArrayPrototypeMap, | |
| 56 | 56 | ArrayPrototypePush, | |
| 57 | + ArrayPrototypePushApply, | ||
| 57 | 58 | ArrayPrototypeSlice, | |
| 58 | 59 | Error, | |
| 59 | 60 | ObjectDefineProperty, | |
@@ -320,14 +321,16 @@ class BuiltinModule { | |||
| 320 | 321 | ); | |
| 321 | 322 | } | |
| 322 | 323 | ||
| 323 | - static getCanBeRequiredByUsersWithoutSchemeList() { | ||
| 324 | - return ArrayFrom(canBeRequiredByUsersWithoutSchemeList); | ||
| 325 | - } | ||
| 326 | - | ||
| 327 | 324 | static getSchemeOnlyModuleNames() { | |
| 328 | 325 | return ArrayFrom(schemelessBlockList); | |
| 329 | 326 | } | |
| 330 | 327 | ||
| 328 | + static getAllBuiltinModuleIds() { | ||
| 329 | + const allBuiltins = ArrayFrom(canBeRequiredByUsersWithoutSchemeList); | ||
| 330 | + ArrayPrototypePushApply(allBuiltins, ArrayFrom(schemelessBlockList, (x) => `node:${x}`)); | ||
| 331 | + return allBuiltins; | ||
| 332 | + } | ||
| 333 | + | ||
| 331 | 334 | // Used by user-land module loaders to compile and load builtins. | |
| 332 | 335 | compileForPublicLoader() { | |
| 333 | 336 | if (!BuiltinModule.canBeRequiredByUsers(this.id)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -434,8 +434,8 @@ Module.isBuiltin = BuiltinModule.isBuiltin; | |||
| 434 | 434 | */ | |
| 435 | 435 | function initializeCJS() { | |
| 436 | 436 | // This need to be done at runtime in case --expose-internals is set. | |
| 437 | - const builtinModules = BuiltinModule.getCanBeRequiredByUsersWithoutSchemeList(); | ||
| 438 | - Module.builtinModules = ObjectFreeze(builtinModules); | ||
| 437 | + | ||
| 438 | + Module.builtinModules = ObjectFreeze(BuiltinModule.getAllBuiltinModuleIds()); | ||
| 439 | 439 | ||
| 440 | 440 | initializeCjsConditions(); | |
| 441 | 441 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,7 +130,7 @@ const { shouldColorize } = require('internal/util/colors'); | |||
| 130 | 130 | const CJSModule = require('internal/modules/cjs/loader').Module; | |
| 131 | 131 | let _builtinLibs = ArrayPrototypeFilter( | |
| 132 | 132 | CJSModule.builtinModules, | |
| 133 | - (e) => e[0] !== '_', | ||
| 133 | + (e) => e[0] !== '_' && !StringPrototypeStartsWith(e, 'node:'), | ||
| 134 | 134 | ); | |
| 135 | 135 | const nodeSchemeBuiltinLibs = ArrayPrototypeMap( | |
| 136 | 136 | _builtinLibs, (lib) => `node:${lib}`); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,9 @@ if (process.argv[2] === 'child') { | |||
| 87 | 87 | }); | |
| 88 | 88 | } else { | |
| 89 | 89 | require(id); | |
| 90 | + if (!id.startsWith('node:')) { | ||
| 91 | + require(`node:${id}`); | ||
| 92 | + } | ||
| 90 | 93 | publicModules.add(id); | |
| 91 | 94 | } | |
| 92 | 95 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,15 +41,19 @@ for (const id of publicBuiltins) { | |||
| 41 | 41 | } | |
| 42 | 42 | // Check that import(id).default returns the same thing as process.getBuiltinModule(id). | |
| 43 | 43 | for (const id of publicBuiltins) { | |
| 44 | - const imported = await import(`node:${id}`); | ||
| 45 | - assert.strictEqual(process.getBuiltinModule(id), imported.default); | ||
| 44 | + if (!id.startsWith('node:')) { | ||
| 45 | + const imported = await import(`node:${id}`); | ||
| 46 | + assert.strictEqual(process.getBuiltinModule(id), imported.default); | ||
| 47 | + } | ||
| 46 | 48 | } | |
| 47 | 49 | ||
| 48 | 50 | // publicBuiltins does not include 'test' which requires the node: prefix. | |
| 49 | 51 | const ids = publicBuiltins.add('test'); | |
| 50 | 52 | // Check that import(id).default returns the same thing as process.getBuiltinModule(id). | |
| 51 | 53 | for (const id of ids) { | |
| 52 | - const prefixed = `node:${id}`; | ||
| 53 | - const imported = await import(prefixed); | ||
| 54 | - assert.strictEqual(process.getBuiltinModule(prefixed), imported.default); | ||
| 54 | + if (!id.startsWith('node:')) { | ||
| 55 | + const prefixed = `node:${id}`; | ||
| 56 | + const imported = await import(prefixed); | ||
| 57 | + assert.strictEqual(process.getBuiltinModule(prefixed), imported.default); | ||
| 58 | + } | ||
| 55 | 59 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ const ArrayStream = require('../common/arraystream'); | |||
| 5 | 5 | const fixtures = require('../common/fixtures'); | |
| 6 | 6 | const assert = require('assert'); | |
| 7 | 7 | const { builtinModules } = require('module'); | |
| 8 | - const publicModules = builtinModules.filter((lib) => !lib.startsWith('_')); | ||
| 8 | + const publicUnprefixedModules = builtinModules.filter((lib) => !lib.startsWith('_') && !lib.startsWith('node:')); | ||
| 9 | 9 | ||
| 10 | 10 | if (!common.isMainThread) | |
| 11 | 11 | common.skip('process.chdir is not available in Workers'); | |
@@ -31,7 +31,7 @@ testMe._domain.on('error', assert.ifError); | |||
| 31 | 31 | // Tab complete provides built in libs for import() | |
| 32 | 32 | testMe.complete('import(\'', common.mustCall((error, data) => { | |
| 33 | 33 | assert.strictEqual(error, null); | |
| 34 | - publicModules.forEach((lib) => { | ||
| 34 | + publicUnprefixedModules.forEach((lib) => { | ||
| 35 | 35 | assert( | |
| 36 | 36 | data[0].includes(lib) && data[0].includes(`node:${lib}`), | |
| 37 | 37 | `${lib} not found`, | |
@@ -55,7 +55,7 @@ testMe.complete("import\t( 'n", common.mustCall((error, data) => { | |||
| 55 | 55 | // import(...) completions include `node:` URL modules: | |
| 56 | 56 | let lastIndex = -1; | |
| 57 | 57 | ||
| 58 | - publicModules.forEach((lib, index) => { | ||
| 58 | + publicUnprefixedModules.forEach((lib, index) => { | ||
| 59 | 59 | lastIndex = completions.indexOf(`node:${lib}`); | |
| 60 | 60 | assert.notStrictEqual(lastIndex, -1); | |
| 61 | 61 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -275,7 +275,7 @@ testMe.complete('require(\'', common.mustCall(function(error, data) { | |||
| 275 | 275 | assert.strictEqual(error, null); | |
| 276 | 276 | publicModules.forEach((lib) => { | |
| 277 | 277 | assert( | |
| 278 | - data[0].includes(lib) && data[0].includes(`node:${lib}`), | ||
| 278 | + data[0].includes(lib) && (lib.startsWith('node:') || data[0].includes(`node:${lib}`)), | ||
| 279 | 279 | `${lib} not found` | |
| 280 | 280 | ); | |
| 281 | 281 | }); | |
@@ -295,7 +295,7 @@ testMe.complete("require\t( 'n", common.mustCall(function(error, data) { | |||
| 295 | 295 | // require(...) completions include `node:`-prefixed modules: | |
| 296 | 296 | let lastIndex = -1; | |
| 297 | 297 | ||
| 298 | - publicModules.forEach((lib, index) => { | ||
| 298 | + publicModules.filter((lib) => !lib.startsWith('node:')).forEach((lib, index) => { | ||
| 299 | 299 | lastIndex = data[0].indexOf(`node:${lib}`); | |
| 300 | 300 | assert.notStrictEqual(lastIndex, -1); | |
| 301 | 301 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,10 +61,9 @@ require(fixtures.path('resolve-paths', 'default', 'verify-paths.js')); | |||
| 61 | 61 | // builtinModules. | |
| 62 | 62 | builtinModules.forEach((mod) => { | |
| 63 | 63 | assert.strictEqual(require.resolve.paths(mod), null); | |
| 64 | - }); | ||
| 65 | - | ||
| 66 | - builtinModules.forEach((mod) => { | ||
| 67 | - assert.strictEqual(require.resolve.paths(`node:${mod}`), null); | ||
| 64 | + if (!mod.startsWith('node:')) { | ||
| 65 | + assert.strictEqual(require.resolve.paths(`node:${mod}`), null); | ||
| 66 | + } | ||
| 68 | 67 | }); | |
| 69 | 68 | ||
| 70 | 69 | // node_modules. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments