File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828A list of the names of all modules provided by Node.js. Can be used to verify
2929if a module is maintained by a third party or not.
3030
31- Note: the list doesn't contain [ prefix-only modules] [ ] like ` node:test ` .
31+ Note: the list also contains [ prefix-only modules] [ ] like ` node:test ` .
3232
3333` module ` in this context isn't the same object that's provided
3434by the [ module wrapper] [ ] . To access it, require the ` Module ` module:
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
513513passed to ` require() ` . For instance, ` require('http') ` will always
514514return the built-in HTTP module, even if there is a file by that name. The list
515515of 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 .
517517
518518### Built-in modules with mandatory ` node: ` prefix
519519
@@ -527,6 +527,8 @@ taken the name. Currently the built-in modules that requires the `node:` prefix
527527* [ ` node:test ` ] [ ]
528528* [ ` node:test/reporters ` ] [ ]
529529
530+ The list of these modules is exposed in [ ` module.builtinModules ` ] [ ] , including the prefix.
531+
530532## Cycles
531533
532534<!-- type=misc-->
Original file line number Diff line number Diff line change @@ -320,14 +320,17 @@ class BuiltinModule {
320320 ) ;
321321 }
322322
323- static getCanBeRequiredByUsersWithoutSchemeList ( ) {
324- return ArrayFrom ( canBeRequiredByUsersWithoutSchemeList ) ;
325- }
326-
327323 static getSchemeOnlyModuleNames ( ) {
328324 return ArrayFrom ( schemelessBlockList ) ;
329325 }
330326
327+ static getAllBuiltinModuleIds ( ) {
328+ return [
329+ ...canBeRequiredByUsersWithoutSchemeList ,
330+ ...ArrayFrom ( schemelessBlockList , ( x ) => `node:${ x } ` ) ,
331+ ] ;
332+ }
333+
331334 // Used by user-land module loaders to compile and load builtins.
332335 compileForPublicLoader ( ) {
333336 if ( ! BuiltinModule . canBeRequiredByUsers ( this . id ) ) {
Original file line number Diff line number Diff line change @@ -434,8 +434,8 @@ Module.isBuiltin = BuiltinModule.isBuiltin;
434434 */
435435function initializeCJS ( ) {
436436 // 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 ( ) ) ;
439439
440440 initializeCjsConditions ( ) ;
441441
Original file line number Diff line number Diff line change @@ -87,6 +87,9 @@ if (process.argv[2] === 'child') {
8787 } ) ;
8888 } else {
8989 require ( id ) ;
90+ if ( ! id . startsWith ( 'node:' ) ) {
91+ require ( `node:${ id } ` ) ;
92+ }
9093 publicModules . add ( id ) ;
9194 }
9295 }
You can’t perform that action at this time.
0 commit comments