File tree 5 files changed +16
-8
lines changed
5 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 28
28
A list of the names of all modules provided by Node.js. Can be used to verify
29
29
if a module is maintained by a third party or not.
30
30
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 ` .
32
32
33
33
` module ` in this context isn't the same object that's provided
34
34
by 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
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 @@ -320,14 +320,17 @@ class BuiltinModule {
320
320
) ;
321
321
}
322
322
323
- static getCanBeRequiredByUsersWithoutSchemeList ( ) {
324
- return ArrayFrom ( canBeRequiredByUsersWithoutSchemeList ) ;
325
- }
326
-
327
323
static getSchemeOnlyModuleNames ( ) {
328
324
return ArrayFrom ( schemelessBlockList ) ;
329
325
}
330
326
327
+ static getAllBuiltinModuleIds ( ) {
328
+ return [
329
+ ...canBeRequiredByUsersWithoutSchemeList ,
330
+ ...ArrayFrom ( schemelessBlockList , ( x ) => `node:${ x } ` ) ,
331
+ ] ;
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 @@ -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
}
You can’t perform that action at this time.
0 commit comments