diff --git a/doc/api/esm.md b/doc/api/esm.md index 9571bb11e8fef4..d67cb47abe526e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -486,9 +486,9 @@ These CommonJS variables are not available in ES modules. `__filename` and `__dirname` use cases can be replicated via [`import.meta.url`][]. -#### No Native Module Loading +#### No Addon Loading -Native modules are not currently supported with ES module imports. +[Addons][] are not currently supported with ES module imports. They can instead be loaded with [`module.createRequire()`][] or [`process.dlopen`][]. @@ -1525,6 +1525,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][]. [6.1.7 Array Index]: https://tc39.es/ecma262/#integer-index +[Addons]: addons.md [CommonJS]: modules.md [Conditional exports]: packages.md#conditional-exports [Core modules]: modules.md#core-modules diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index f25fb7c9f44391..47bd830570fa9f 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -144,7 +144,7 @@ const schemelessBlockList = new SafeSet([ 'DEP0111'); } if (legacyWrapperList.has(module)) { - return nativeModuleRequire('internal/legacy/processbinding')[module](); + return requireBuiltin('internal/legacy/processbinding')[module](); } return internalBinding(module); } @@ -285,14 +285,14 @@ class BuiltinModule { // TODO(aduh95): move this to C++, alongside the initialization of the class. ObjectSetPrototypeOf(ModuleWrap.prototype, null); const url = `node:${this.id}`; - const nativeModule = this; + const builtin = this; const exportsKeys = ArrayPrototypeSlice(this.exportKeys); ArrayPrototypePush(exportsKeys, 'default'); this.module = new ModuleWrap( url, undefined, exportsKeys, function() { - nativeModule.syncExports(); - this.setExport('default', nativeModule.exports); + builtin.syncExports(); + this.setExport('default', builtin.exports); }); // Ensure immediate sync execution to capture exports now this.module.instantiate(); @@ -326,7 +326,7 @@ class BuiltinModule { try { const requireFn = StringPrototypeStartsWith(this.id, 'internal/deps/') ? - requireWithFallbackInDeps : nativeModuleRequire; + requireWithFallbackInDeps : requireBuiltin; const fn = compileFunction(id); // Arguments must match the parameters specified in @@ -350,10 +350,10 @@ class BuiltinModule { const loaderExports = { internalBinding, BuiltinModule, - require: nativeModuleRequire + require: requireBuiltin }; -function nativeModuleRequire(id) { +function requireBuiltin(id) { if (id === loaderId) { return loaderExports; } @@ -371,7 +371,7 @@ function requireWithFallbackInDeps(request) { if (!BuiltinModule.map.has(request)) { request = `internal/deps/${request}`; } - return nativeModuleRequire(request); + return requireBuiltin(request); } // Pass the exports back to C++ land for C++ internals to use. diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 6da0150b1b2fa3..05d0173f7c77f5 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -140,9 +140,9 @@ process.domain = null; process._exiting = false; // process.config is serialized config.gypi -const nativeModule = internalBinding('builtins'); +const binding = internalBinding('builtins'); -const processConfig = JSONParse(nativeModule.config, (_key, value) => { +const processConfig = JSONParse(binding.config, (_key, value) => { // The `reviver` argument of the JSONParse method will visit all the values of // the parsed config, including the "root" object, so there is no need to // explicitly freeze the config outside of this method @@ -288,7 +288,7 @@ const features = { // This needs to be dynamic because --no-node-snapshot disables the // code cache even if the binary is built with embedded code cache. get cached_builtins() { - return nativeModule.hasCachedBuiltins(); + return binding.hasCachedBuiltins(); } };