-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esm: bypass CommonJS loader under --default-type=module
#49986
esm: bypass CommonJS loader under --default-type=module
#49986
Conversation
Review requested:
|
a0fba47
to
4669340
Compare
4669340
to
6c6aefe
Compare
So there are really two places where we resolve the input into a path: the const main = path.isAbsolute(mainPath) ?
pathToFileURL(mainPath).href : mainPath; If we bypass or immediately return from So I think either we undo the commit I just pushed, and always resolve the input into a path within |
@aduh95 I pushed some more commits, that undo the “streamline” commit, and add some tests and comments and improve an error message. I’m open to being convinced otherwise, but it feels like a mistake to completely bypass Assuming the above is all correct so far, I wanted a better error message for the “left off the file extension” case than just |
6f61ca0
to
4cf437c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huzzah 🙂
A small nit: somewhere (I can't find the line now—on my mobile), it declares a typedef for default-type as a string: it's not any old string, it's an enum of specific strings. Ideally, those are numerated in the typedef.
error.stack = | ||
ArrayPrototypeShift(lines) + '\n' + | ||
hint + '\n' + | ||
ArrayPrototypeJoin(lines, '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error.stack = | |
ArrayPrototypeShift(lines) + '\n' + | |
hint + '\n' + | |
ArrayPrototypeJoin(lines, '\n'); | |
error.stack = `${ArrayPrototypeShift(lines)}\n${hint}\n${ArrayPrototypeJoin(lines, '\n')}`; |
I reverted the optimization for the legacy flow. I don’t want to make changes to the legacy flow in this PR, I’m too nervous about such changes introducing bugs since the changes don’t break any tests when I’d expect that they should. I want to just land the new feature intended by this PR, bypassing the CommonJS loader under |
Landed in 19b470f |
PR-URL: nodejs#49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: #49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
no code changes; patch just needed an update due to nearby upstream changes Xref: nodejs/node#49986
…patch Xref: nodejs/node#49986 minor manual changes needed to sync with upstream change
no code changes; patch just needed an update due to nearby upstream changes Xref: nodejs/node#49986
…patch Xref: nodejs/node#49986 minor manual changes needed to sync with upstream change
* chore: bump node in DEPS to v20.10.0 * chore: update feat_initialize_asar_support.patch no code changes; patch just needed an update due to nearby upstream changes Xref: nodejs/node#49986 * chore: update pass_all_globals_through_require.patch no manual changes; patch applied with fuzz Xref: nodejs/node#49657 * chore: update refactor_allow_embedder_overriding_of_internal_fs_calls Xref: nodejs/node#49912 no code changes; patch just needed an update due to nearby upstream changes * chore: update chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch Xref: nodejs/node#49986 minor manual changes needed to sync with upstream change * update fix_expose_the_built-in_electron_module_via_the_esm_loader.patch Xref: nodejs/node#50096 Xref: nodejs/node#50314 in lib/internal/modules/esm/load.js, update the code that checks for `format === 'electron'`. I'd like 👀 on this Xref: nodejs/node#49657 add braces in lib/internal/modules/esm/translators.js to sync with upstream * fix: lazyload fs in esm loaders to apply asar patches * nodejs/node#50127 * nodejs/node#50096 * esm: jsdoc for modules code nodejs/node#49523 * test: set test-cli-node-options as flaky nodejs/node#50296 * deps: update c-ares to 1.20.1 nodejs/node#50082 * esm: bypass CommonJS loader under --default-type=module nodejs/node#49986 * deps: update uvwasi to 0.0.19 nodejs/node#49908 * lib,test: do not hardcode Buffer.kMaxLength nodejs/node#49876 * crypto: account for disabled SharedArrayBuffer nodejs/node#50034 * test: fix edge snapshot stack traces nodejs/node#49659 * src: generate snapshot with --predictable nodejs/node#48749 * chore: fixup patch indices * fs: throw errors from sync branches instead of separate implementations nodejs/node#49913 * crypto: ensure valid point on elliptic curve in SubtleCrypto.importKey nodejs/node#50234 * esm: detect ESM syntax in ambiguous JavaScrip nodejs/node#50096 * fixup! test: fix edge snapshot stack traces * esm: unflag extensionless ES module JavaScript and Wasm in module scope nodejs/node#49974 * [tagged-ptr] Arrowify objects https://chromium-review.googlesource.com/c/v8/v8/+/4705331 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: nodejs#49986 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs/node#49986 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs/node#49986 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This PR implements the part of #49432 where we avoid using the CommonJS loader for ESM entry points in the new
--default-type=module
mode. This effectively completes some TODOs in the code that note that particular code paths should be deprecated.The only user-observable effects of this are that, under
--experimental-default-type=module
:node entry.js
, notnode entry
.--require
will no longer achieve anything. They weren’t achieving much before, as monkey-patching the CommonJS loader only affects CommonJS and not ES modules, so it’s not like the previous behavior was really working very well (if at all) for applications with an ESM entry point.This inches us closer to actually deprecating the CommonJS loader and having the ESM loader handle all modules, which is a long term goal that will aid in maintainability and future functionality for the modules subsystem.