[9.x] backport 19112, 19177 (bootstrapper & loaders reafactor)
src: move internal loaders out of bootstrap_node.js
- Moves the creation of
process.binding()
,process._linkedBinding()
internalBinding()
andNativeModule
into a separate filelib/internal/bootstrap_loaders.js
, and documents them there. This file will be compiled and run beforebootstrap_node.js
, which means we now bootstrap the internal module & binding system before actually bootstrapping Node.js. - Rename the special ID that can be used to require
NativeModule
asinternal/bootstrap_loaders
since it is setup there. Also putinternalBinding
in the object exported byNativeModule.require
instead of putting it inside theNativeModule.wrapper
- Use the original
getBinding()
to get the source code of native modules instead of getting it fromprocess.binding('native')
so that users cannot fake native modules by modifying the binding object. - Names the bootstrapping functions so their names show up in the stack trace.
test: remove NODE_DEBUG in global module loading test
Otherwise the debug log output might be mixed up with the expected errors and the assertion matching the error message would fail.
src: put bootstrappers in lib/internal/bootstrap/
Create lib/internal/bootstrap/
and put bootstrappers there:
Before:
lib/internal
├── ...
├── bootstrap_loaders.js
└── bootstrap_node.js
After:
lib/internal
├── ...
└── bootstrap
├── loaders.js
└── node.js
lib: restructure cjs and esm loaders
Create lib/internal/modules
and restructure the module loaders
to make the purpose of those files clearer.
Also make it clear in the code that the object exported by
lib/internal/modules/cjs/loader.js
is CJSModule
instead of the
ambiguous Module
.
Before:
lib
├── ...
├── internal
│ ├── loaders
│ │ ├── CreateDynamicModule.js
│ │ ├── DefaultResolve.js
│ │ ├── Loader.js
│ │ ├── ModuleJob.js
│ │ ├── ModuleMap.js
│ │ ├── ModuleWrap.js
│ │ └── Translators.js
│ └── module.js
└── module.js
After:
lib
├── ...
├── internal
│ ├── ...
│ └── modules
│ ├── cjs
│ │ ├── helpers.js
│ │ └── loader.js
│ └── esm
│ ├── CreateDynamicModule.js
│ ├── DefaultResolve.js
│ ├── Loader.js
│ ├── ModuleJob.js
│ ├── ModuleMap.js
│ └── Translators.js
└── module.js # deleted in this commit to work with git file mode
lib: add back lib/module.js redirection
The previous commit deleted lib/module.js so that git
recognize the file move lib/module.js
->
lib/internal/modules/cjs/loader.js
. This commit add the
redirection back.
Refs #19112 Refs #19177