mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
e77aac2a5f
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> |
||
---|---|---|
.. | ||
assert | ||
bootstrap | ||
child_process | ||
cluster | ||
console | ||
crypto | ||
debugger | ||
dns | ||
events | ||
fs | ||
http2 | ||
legacy | ||
main | ||
modules | ||
per_context | ||
perf | ||
process | ||
readline | ||
repl | ||
source_map | ||
streams | ||
test | ||
test_runner | ||
tls | ||
util | ||
v8 | ||
vm | ||
watch_mode | ||
webstreams | ||
worker | ||
abort_controller.js | ||
assert.js | ||
async_hooks.js | ||
blob.js | ||
blocklist.js | ||
buffer.js | ||
child_process.js | ||
cli_table.js | ||
constants.js | ||
dgram.js | ||
encoding.js | ||
error_serdes.js | ||
errors.js | ||
event_target.js | ||
file.js | ||
fixed_queue.js | ||
freelist.js | ||
freeze_intrinsics.js | ||
heap_utils.js | ||
histogram.js | ||
http.js | ||
idna.js | ||
inspector_async_hook.js | ||
js_stream_socket.js | ||
linkedlist.js | ||
mime.js | ||
navigator.js | ||
net.js | ||
options.js | ||
priority_queue.js | ||
promise_hooks.js | ||
querystring.js | ||
README.md | ||
repl.js | ||
socket_list.js | ||
socketaddress.js | ||
stream_base_commons.js | ||
timers.js | ||
trace_events_async_hooks.js | ||
tty.js | ||
url.js | ||
util.js | ||
v8_prof_polyfill.js | ||
v8_prof_processor.js | ||
validators.js | ||
vm.js | ||
wasm_web_api.js | ||
watchdog.js | ||
webidl.js | ||
webstorage.js | ||
worker.js |
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.