node/lib/internal
Joyee Cheung e77aac2a5f module: add __esModule to require()'d ESM
Tooling in the ecosystem have been using the __esModule property to
recognize transpiled ESM in consuming code. For example, a 'log'
package written in ESM:

export function log(val) { console.log(val); }

Can be transpiled as:

exports.__esModule = true;
exports.default = function log(val) { console.log(val); }

The consuming code may be written like this in ESM:

import log from 'log'

Which gets transpiled to:

const _mod = require('log');
const log = _mod.__esModule ? _mod.default : _mod;

So to allow transpiled consuming code to recognize require()'d real ESM
as ESM and pick up the default exports, we add a __esModule property by
building a source text module facade for any module that has a default
export and add .__esModule = true to the exports. We don't do this to
modules that don't have default exports to avoid the unnecessary
overhead. This maintains the enumerability of the re-exported names
and the live binding of the exports.

The source of the facade is defined as a constant per-isolate property
required_module_facade_source_string, which looks like this

export * from 'original';
export { default } from 'original';
export const __esModule = true;

And the 'original' module request is always resolved by
createRequiredModuleFacade() to wrap which is a ModuleWrap wrapping
over the original module.

PR-URL: https://github.com/nodejs/node/pull/52166
Refs: https://github.com/nodejs/node/issues/52134
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2024-07-11 18:59:31 +00:00
..
assert lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
bootstrap process: port on-exit-leak-free to core 2024-07-11 17:57:20 +00:00
child_process tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
cluster cluster: replace forEach with for-of loop 2024-05-12 19:58:40 +02:00
console module: print amount of load time of a cjs module 2024-05-30 16:58:59 +00:00
crypto crypto: remove ERR_CRYPTO_SCRYPT_INVALID_PARAMETER 2024-07-10 16:38:00 +00:00
debugger
dns lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
events lib: fix naming convention of Symbol 2024-06-10 14:56:14 +00:00
fs fs: reduce throwing unnecessary errors on glob 2024-07-11 18:51:35 +00:00
http2 http2: remove prototype primordials 2024-07-05 06:20:12 +00:00
legacy tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
main worker: add postMessageToThread 2024-07-09 07:16:04 +00:00
modules module: add __esModule to require()'d ESM 2024-07-11 18:59:31 +00:00
per_context tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
perf lib: add toJSON to PerformanceMeasure 2024-06-29 04:48:23 +00:00
process process: port on-exit-leak-free to core 2024-07-11 17:57:20 +00:00
readline http, readline: replace sort with toSorted 2024-07-10 16:46:24 +00:00
repl repl: fix await object patterns without values 2024-06-07 01:24:32 +00:00
source_map lib: reduce amount of caught URL errors 2024-06-13 18:32:59 +00:00
streams stream: pipeline wait for close before calling the callback 2024-06-27 11:29:35 +00:00
test v8: implement v8.queryObjects() for memory leak regression testing 2024-03-02 22:11:30 +00:00
test_runner test_runner: support module detection in module mocks 2024-07-04 13:30:01 +00:00
tls tls: fix negative sessionTimeout handling 2024-05-18 00:26:11 +00:00
util src: refactor embedded entrypoint loading 2024-07-05 19:58:35 +00:00
v8 lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
vm vm: fix ASCII-betical order 2024-04-25 19:14:16 +00:00
watch_mode test_runner: handle file rename and deletion under watch mode 2024-06-02 08:11:30 +00:00
webstreams stream: use ByteLengthQueuingStrategy when not in objectMode 2024-05-12 19:24:43 +02:00
worker worker: add postMessageToThread 2024-07-09 07:16:04 +00:00
abort_controller.js lib: use predefined variable instead of bit operation 2024-04-20 16:24:25 +00:00
assert.js
async_hooks.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
blob.js buffer: add .bytes() method to Blob 2024-06-04 02:00:05 +00:00
blocklist.js
buffer.js
child_process.js errors: improve hideStackFrames 2023-11-11 16:25:08 +00:00
cli_table.js lib: align console.table row to the left 2023-10-28 01:14:22 +00:00
constants.js
dgram.js lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
encoding.js stream: implement min option for ReadableStreamBYOBReader.read 2024-01-04 12:57:14 +01:00
error_serdes.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
errors.js crypto: remove ERR_CRYPTO_SCRYPT_INVALID_PARAMETER 2024-07-10 16:38:00 +00:00
event_target.js lib: fix naming convention of Symbol 2024-06-10 14:56:14 +00:00
file.js lib,src: replace toUSVString with toWellFormed() 2023-11-29 16:00:57 +00:00
fixed_queue.js
freelist.js
freeze_intrinsics.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
heap_utils.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
histogram.js lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
http.js http: remove prototype primordials 2024-07-06 10:33:16 +02:00
idna.js
inspector_async_hook.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
js_stream_socket.js http2: fix h2-over-h2 connection proxying 2024-04-08 09:53:18 +00:00
linkedlist.js
mime.js util: pass invalidSubtypeIndex instead of trimmedSubtype to error 2023-12-25 04:29:00 +00:00
navigator.js lib: make navigator properties lazy 2024-07-04 14:35:28 +00:00
net.js lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
options.js src: reduce unnecessary serialization of CLI options in C++ 2024-05-02 22:57:03 +00:00
priority_queue.js
promise_hooks.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
querystring.js
README.md lib, doc: rename readme.md to README.md 2024-04-14 10:30:31 +00:00
repl.js
socket_list.js
socketaddress.js
stream_base_commons.js http2: fix h2-over-h2 connection proxying 2024-04-08 09:53:18 +00:00
timers.js timers: emit warning if delay is negative or NaN 2024-06-28 11:36:31 +00:00
trace_events_async_hooks.js
tty.js
url.js url: make URL.parse enumerable 2024-07-06 14:53:26 +00:00
util.js util: fix crashing when emitting new Buffer() deprecation warning #53075 2024-07-11 12:13:20 +00:00
v8_prof_polyfill.js
v8_prof_processor.js
validators.js lib: fix misleading argument of validateUint32 2024-06-05 22:59:05 +00:00
vm.js typings: lib/internal/vm.js 2024-02-19 01:19:44 +00:00
wasm_web_api.js
watchdog.js
webidl.js stream: treat compression web stream format per its WebIDL definition 2023-11-12 10:01:51 +00:00
webstorage.js deps,lib,src: add experimental web storage 2024-06-14 18:40:04 +00:00
worker.js worker: add postMessageToThread 2024-07-09 07:16:04 +00:00

Internal Modules

The modules in lib/internal are intended for internal use in Node.js core only, and are not accessible with require() from user modules. These modules can be changed at any time. Reliance on these modules outside of core is not supported in any way.