-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
module: package "imports" field #34117
Conversation
This makes me really exciting to dig into the changes! 🎉 |
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.
I think this will help getting a consistent set of metadata for describing resolution for JavaScript (independent of where it runs). Using #
("private field marker") seems consistent with JavaScript terms and since this happens before conversion to URLs, it shouldn't conflict / should be web-compatible.
> 1. Otherwise, if _specifier_ starts with _"/"_, then | ||
> 1. Throw an _Invalid Module Specifier_ error. | ||
> 1. Otherwise, if _specifier_ starts with _"./"_ or _"../"_, then | ||
> 1. Otherwise, if _specifier_ starts with _"/"_, _"./"_ or _"../"_, then |
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.
OT: This algorithm is pretty much un-reviewable at this point (at least to me). I don't think it's in scope for this PR but maybe the answer is to move it to its own page and rethink how it's organized?
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.
I'm totally open to suggestions. My main concerns are keeping the API nature of the docs straightforward and having a nice link to this spec as it should be a reference. I do generally not like having it in a details element because it makes it difficult to link this spec without it being overlooked so I'd be all for a dedicated page actually.
Forgot to cc @nodejs/modules-active-members here. |
Thanks @jkrems for the quick review here, just let me know if you have further feedback. |
be done without the risk of cycles, unlike for exports. | ||
|
||
Apart from the above, the resolution rules for the imports field are otherwise | ||
analogous to the exports field. |
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.
we might want to add that fragments and queries are not preserved for non-directory paths.
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.
I assume they are neither preserved nor removed..? It may make sense to call out that for bare specifiers ?
/#
/etc. are treated like any other character if we don't do that already.
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.
looking at the markdown algorithm they would be removed it seems.
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.
I tried to find the part where it removes anything from the specifier and I can't find a reference to "?"/"#" or "query"/"fragment". According to my reading of the markdown algorithm (and memory of the spec), the following should work:
// ./package.json
{
"name": "pkg",
"imports": {
"#/some?private#specifier": "dep/this?is?all#just%chars"
}
}
// ./entry.mjs
import '#/some?private#specifier';
// ./node_modules/dep/package.json
{
"name": "pkg",
"exports": {
"./this?is?all#just%chars": "./foo.mjs?some=query"
}
}
The import in entry.mjs
should load ./node_modules/dep/package.json/foo.mjs?some=query
. It does honor the entire specifier, including the bits that happen to follow a question mark. So "not preserved" could be misunderstood I think. Similar behavior can also be observed in directory "exports", so this isn't specific to exact match:
{
"exports": {
"./this?may#contain/other/chars/": "./lib/"
}
}
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.
the point is that
{
"field (you used exports but this PR is imports)": {
"#/x?y" : "./x"
}
import '#/x?z';
would not carry ?
or #
parts of the URL from input to right hand side. It also needs those to match the left hand side if they are present. I am not willing to state that these left hand side strings are not URL based/like as that goes back to my problem with putting #
in the exports field of making the switch of being an opaque value/string quite confusing and not matching any other specifier. I do think this is a difference that was fine in "exports" since it is a single location/workflow for the exception but as we grow the usage of these non relative non propagating specifiers we need to document the actual workflow. Even reading your comment above I am unclear on your meaning which is concerning on its own.
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.
@bmeck like import maps, the left hand side is always a direct string replacement, so the only difference remains the standard CJS v ESM resolvers handling resolution differently for those cases, but this applies equally to any absolute or relative paths - imports and exports targets are no different.
@jkrems note that I have disallowed #/
as a mapping prefix explicitly so your example wouldn't work and instead give an invalid specifier error. I thought it seemed sensible to lock down these base cases, but happy to reconsider.
So to make sure i understand: “imports” would only be accessible via a package self-reference, and would not imply an “exports” entry? Can “exports” use an “imports” LHS as a RHS value? The # appears in the LHS of “imports” - is it required in the in-code specifier? |
I understand it this way: No. imports is not related to self-reference. You use it this way:
No. exports allows only paths inside of the package.
Yes. See first comment. |
Co-authored-by: Jan Olaf Krems <jan.krems@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
68adf43
to
2fb1548
Compare
2fb1548
to
1dc83f5
Compare
Can’t an existing folder in node_modules start with a #? |
@ljharb yes it is possible in theory. Like |
What would happen if foo/#bar is a valid path, and they add the imports field? Would they have to add a “#bar” import field value in order to make that backwards compatible? |
Relative path loading is entirely unaffected by this PR - the only case where |
Thanks for clarifying! |
Is there any further feedback on this PR? Is there anything we should be discussing in the meeting with regards to this? @bmeck let me know if I've answered all your questions above. |
@guybedford the explanation seems fine but it still isn't in the docs. |
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.
Can amend docs later
Notable changes: deps: * upgrade npm to 6.14.6 (claudiahdz) #34246 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 * (SEMVER-MINOR) update V8 to 8.4.371.19 (Michaël Zasso) [#33579](#33579) module: * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 src: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) allow embedders to disable esm loader (Shelley Vohr) #34060 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 vm: * (SEMVER-MINOR) add run-after-evaluate microtask mode (Anna Henningsen) #34023 worker: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 New Collaborators: * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 PR-URL: #34371
Notable changes: deps: * upgrade npm to 6.14.6 (claudiahdz) #34246 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 * (SEMVER-MINOR) update V8 to 8.4.371.19 (Michaël Zasso) [#33579](#33579) module: * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 src: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) allow embedders to disable esm loader (Shelley Vohr) #34060 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 vm: * (SEMVER-MINOR) add run-after-evaluate microtask mode (Anna Henningsen) #34023 worker: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 New Collaborators: * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 PR-URL: #34371
Notable changes: deps: * upgrade npm to 6.14.6 (claudiahdz) #34246 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 * (SEMVER-MINOR) update V8 to 8.4.371.19 (Michaël Zasso) [#33579](#33579) module: * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 src: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) allow embedders to disable esm loader (Shelley Vohr) #34060 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 vm: * (SEMVER-MINOR) add run-after-evaluate microtask mode (Anna Henningsen) #34023 worker: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 New Collaborators: * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 PR-URL: #34371
Notable changes: deps: * upgrade npm to 6.14.6 (claudiahdz) #34246 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 * (SEMVER-MINOR) update V8 to 8.4.371.19 (Michaël Zasso) [#33579](#33579) module: * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 src: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) allow embedders to disable esm loader (Shelley Vohr) #34060 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 vm: * (SEMVER-MINOR) add run-after-evaluate microtask mode (Anna Henningsen) #34023 worker: * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 New Collaborators: * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 PR-URL: #34371
PR-URL: nodejs#34117 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) #31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) #34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) #34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) #34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) #34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) #33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) #33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) #34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) #34915 * upgrade npm to 6.14.7 (claudiahdz) #34468 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) #22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) #33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) #30467 * add Ricky Zhou to collaborators (rickyes) #34676 * add release key for Ruy Adorno (Ruy Adorno) #34628 * add DerekNonGeneric to collaborators (Derek Lewis) #34602 * add AshCripps to collaborators (Ash Cripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) #32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) #32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) #32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) #33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) #33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) #32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) #33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) #33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) #33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) #35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) #34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) #35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) #28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) #34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) #34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) #34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) #33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) #33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) #33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) #33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) #33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) #33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) #33516 * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: TODO
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) #31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) #34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) #34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) #34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) #34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) #33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) #33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) #34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) #34915 * upgrade npm to 6.14.7 (claudiahdz) #34468 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) #22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) #33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) #30467 * add Ricky Zhou to collaborators (rickyes) #34676 * add release key for Ruy Adorno (Ruy Adorno) #34628 * add DerekNonGeneric to collaborators (Derek Lewis) #34602 * add AshCripps to collaborators (Ash Cripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) #32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) #32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) #32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) #33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) #33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) #32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) #33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) #33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) #33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) #35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) #34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) #35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) #28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) #34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) #34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) #34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) #33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) #33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) #33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) #33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) #33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) #33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) #33516 * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: TODO
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) #31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) #34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) #34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) #34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) #34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) #33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) #33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) #34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) #34915 * upgrade npm to 6.14.7 (claudiahdz) #34468 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) #22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) #33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) #30467 * add Ricky Zhou to collaborators (rickyes) #34676 * add release key for Ruy Adorno (Ruy Adorno) #34628 * add DerekNonGeneric to collaborators (Derek Lewis) #34602 * add AshCripps to collaborators (Ash Cripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) #32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) #32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) #32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) #33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) #33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) #32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) #33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) #33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) #33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) #35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) #34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) #35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) #28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) #34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) #34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) #34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) #33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) #33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) #33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) #33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) #33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) #33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) #33516 * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: TODO
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) #31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) #34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) #34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) #34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) #34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) #33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) #33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) #34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) #34915 * upgrade npm to 6.14.7 (claudiahdz) #34468 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) #22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) #33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) #30467 * add Ricky Zhou to collaborators (rickyes) #34676 * add release key for Ruy Adorno (Ruy Adorno) #34628 * add DerekNonGeneric to collaborators (Derek Lewis) #34602 * add AshCripps to collaborators (Ash Cripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) #32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) #32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) #32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) #33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) #33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) #32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) #33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) #33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) #33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) #35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) #34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) #35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) #28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) #34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) #34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) #34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) #33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) #33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) #33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) #33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) #33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) #33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) #33516 * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: #35401
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) #31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) #34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) #34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) #34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) #34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) #33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) #33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) #34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) #34915 * upgrade npm to 6.14.7 (claudiahdz) #34468 * upgrade to libuv 1.38.1 (Colin Ihrig) #34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) #22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) #33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) #30467 * add Ricky Zhou to collaborators (rickyes) #34676 * add release key for Ruy Adorno (Ruy Adorno) #34628 * add DerekNonGeneric to collaborators (Derek Lewis) #34602 * add AshCripps to collaborators (Ash Cripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 * add danielleadams to collaborators (Danielle Adams) #34360 * add sxa as collaborator (Stewart X Addison) #34338 * add ruyadorno to collaborators (Ruy Adorno) #34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) #32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) #32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) #32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) #33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) #33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) #32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) #33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) #33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) #33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) #35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) #34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) #34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) #32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) #35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) #28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) #34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) #34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) #34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) #33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) #33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) #33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) #33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) #33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) #34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) #33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) #33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) #33516 * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: #35401
Notable changes: assert: * (SEMVER-MINOR) port common.mustCall() to assert (ConorDavenport) nodejs#31982 async_hooks: * (SEMVER-MINOR) add AsyncResource.bind utility (James M Snell) nodejs#34574 buffer: * (SEMVER-MINOR) also alias BigUInt methods (Anna Henningsen) nodejs#34960 * (SEMVER-MINOR) alias UInt ➡️ Uint in buffer methods (Anna Henningsen) nodejs#34729 build: * (SEMVER-MINOR) add build flag for OSS-Fuzz integration (davkor) nodejs#34761 cli: * (SEMVER-MINOR) add alias for report-directory to make it consistent (Ash Cripps) nodejs#33587 crypto: * (SEMVER-MINOR) allow KeyObjects in postMessage (Tobias Nießen) nodejs#33360 * (SEMVER-MINOR) add randomInt function (Oli Lalonde) nodejs#34600 deps: * upgrade to libuv 1.39.0 (Colin Ihrig) nodejs#34915 * upgrade npm to 6.14.7 (claudiahdz) nodejs#34468 * upgrade to libuv 1.38.1 (Colin Ihrig) nodejs#34187 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) nodejs#14500 * (SEMVER-MINOR) allow typed arrays in .send() (Sarat Addepalli) nodejs#22413 doc: * (SEMVER-MINOR) Add maxTotalSockets option to agent constructor (rickyes) nodejs#33617 * (SEMVER-MINOR) add basic embedding example documentation (Anna Henningsen) nodejs#30467 * add Ricky Zhou to collaborators (rickyes) nodejs#34676 * add release key for Ruy Adorno (Ruy Adorno) nodejs#34628 * add DerekNonGeneric to collaborators (Derek Lewis) nodejs#34602 * add AshCripps to collaborators (Ash Cripps) nodejs#34494 * add HarshithaKP to collaborators (Harshitha K P) nodejs#34417 * add rexagod to collaborators (Pranshu Srivastava) nodejs#34457 * add release key for Richard Lau (Richard Lau) nodejs#34397 * add danielleadams to collaborators (Danielle Adams) nodejs#34360 * add sxa as collaborator (Stewart X Addison) nodejs#34338 * add ruyadorno to collaborators (Ruy Adorno) nodejs#34297 * (SEMVER-MAJOR) deprecate process.umask() with no arguments (Colin Ihrig) nodejs#32499 embedding: * (SEMVER-MINOR) make Stop() stop Workers (Anna Henningsen) nodejs#32531 * (SEMVER-MINOR) provide hook for custom process.exit() behaviour (Anna Henningsen) nodejs#32531 fs: * (SEMVER-MINOR) implement lutimes (Maël Nison) nodejs#33399 http: * (SEMVER-MINOR) add maxTotalSockets to agent class (rickyes) nodejs#33617 * (SEMVER-MINOR) return this from IncomingMessage#destroy() (Colin Ihrig) nodejs#32789 * (SEMVER-MINOR) expose host and protocol on ClientRequest (wenningplus) nodejs#33803 http2: * (SEMVER-MINOR) return this for Http2ServerRequest#setTimeout (Pranshu Srivastava) nodejs#33994 * (SEMVER-MINOR) do not modify explicity set date headers (Pranshu Srivastava) nodejs#33160 module: * (SEMVER-MINOR) named exports for CJS via static analysis (Guy Bedford) nodejs#35249 * (SEMVER-MINOR) exports pattern support (Guy Bedford) nodejs#34718 * (SEMVER-MINOR) package "imports" field (Guy Bedford) nodejs#34117 * (SEMVER-MINOR) deprecate module.parent (Antoine du HAMEL) nodejs#32217 n-api: * (SEMVER-MINOR) create N-API version 7 (Gabriel Schulhof) nodejs#35199 * (SEMVER-MINOR) support type-tagging objects (Gabriel Schulhof) nodejs#28237 n-api,src: * (SEMVER-MINOR) provide asynchronous cleanup hooks (Anna Henningsen) nodejs#34572 perf_hooks: * (SEMVER-MINOR) add idleTime and event loop util (Trevor Norris) nodejs#34938 timers: * (SEMVER-MINOR) allow timers to be used as primitives (Denys Otrishko) nodejs#34017 tls: * (SEMVER-MINOR) make 'createSecureContext' honor more options (Mateusz Krawczuk) nodejs#33974 worker: * (SEMVER-MINOR) add public method for marking objects as untransferable (Anna Henningsen) nodejs#33979 * (SEMVER-MINOR) emit `'messagerror'` events for failed deserialization (Anna Henningsen) nodejs#33772 * (SEMVER-MINOR) allow passing JS wrapper objects via postMessage (Anna Henningsen) nodejs#33772 * (SEMVER-MINOR) allow transferring/cloning generic BaseObjects (Anna Henningsen) nodejs#33772 * (SEMVER-MINOR) add option to track unmanaged file descriptors (Anna Henningsen) nodejs#34303 * (SEMVER-MINOR) add stack size resource limit option (Anna Henningsen) nodejs#33085 worker,fs: * (SEMVER-MINOR) make FileHandle transferable (Anna Henningsen) nodejs#33772 zlib: * (SEMVER-MINOR) add `maxOutputLength` option (unknown) nodejs#33516 * switch to lazy init for zlib streams (Andrey Pechkurov) nodejs#34048 PR-URL: nodejs#35401
This is a follow-up to #33780 that implements the full package.json
"imports"
field, as specified in https://github.com/jkrems/proposal-pkg-exports#3-imports-field.See the specification there or the docs updates in this PR for the full implementation details but the gist of it is:
#specifier
means a private internal "imports" resolution."imports": { "#specifier": "./asdf.js" }
permits local package mappings"imports": { "#specifier": "dependency/asdf.js" }
permits external mappings.The main justification for this is to enable the features of the
"exports"
field to fully cover what was provided by the"browser"
field such that the"exports"
and"imports"
fields can entirely replace these use cases.For example, if a package only wants to resolve an optional dependency when running in Node.js, but want to use a local polyfill otherwise you can define an
"imports"
field like:Then any use of
require('#dep')
orimport('#dep')
within the package itself will resolve appropriately where the local polyfill is used when not in a Node.js environment allows the extension of conditional resolution provided by the exports field to apply within a package itself.The sigil
"#"
is used to properly disambiguate these internal resolutions. In the CommonJS implementation, full backwards compatibility is provided fornode_modules/#pkg
packages that happen to start with#
, even though these are likely very rare.This PR fully shares the code that resolves both "exports" and "imports" so provides some significant refactorings including to error handling cases.
It is also the first case of full code sharing between the CJS and ESM resolvers thanks to @addaleax porting the ESM resolver to JS. This made this PR much easier than it would have been otherwise.
The ability for internal resolutions to map to external packages is a new unique feature not offered by the existing
"exports"
field. This is a benefit over the previous PR at #33780 and is enabled by the fact that circular resolutions are not possible for "imports" as they are for "exports".There is certainly some added complexity here - but at the same time this closes the full loop on providing the same functionality for the "browser" field through this "imports" analog to the "exports" field, which is quite important for cross-environment use cases and does still come up quite a bit practically.
I have recently discussed the need for this PR in practical tooling scenarios with both @mafintosh and @sokra who as far as I could tell are in support of this work.
The tests and implementation are fairly comprehensive. We should also aim to land this while we are still within the window to backport to v12.