Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
492 commits
Select commit Hold shift + click to select a range
9d52480
doc: move addaleax to TSC emeritus
addaleax Aug 17, 2020
53eae0d
process: correctly parse Unicode in NODE_OPTIONS
bzoz Jul 22, 2020
cc98103
test: run REPL preview test regardless of terminal type
Trott Aug 16, 2020
d016cdc
test: fix test-cluster-net-listen-relative-path.js to run in /
Trott Aug 18, 2020
f87b6c0
deps: upgrade npm to 6.14.8
ruyadorno Aug 17, 2020
a6b6556
n-api: handle weak no-finalizer refs correctly
Aug 19, 2020
5f09f45
doc: use 'console' info string for console output
Trott Aug 20, 2020
3ea7e03
doc: adopt Microsoft Style Guide officially
Trott Aug 18, 2020
da150f4
doc: fix ESM/CJS wrapper example
fox1t Aug 20, 2020
c059d3d
tls: enable renegotiation when using BoringSSL
nornagon Aug 18, 2020
d953fa3
src: usage of modernize-use-equals-default
yashLadha Aug 17, 2020
26a596b
src: fix abort on uv_loop_init() failure
bnoordhuis Aug 22, 2020
26b060f
doc: indicate the format of process.version
dguo Aug 22, 2020
e8ddaa3
doc,n-api: add link to n-api tutorial website
jschlight Aug 21, 2020
961844d
doc: improve fs doc intro
jasnell Aug 19, 2020
9b53b4d
deps: upgrade to libuv 1.39.0
cjihrig Aug 25, 2020
76d991c
test: simplify test-vm-memleak
Trott Aug 22, 2020
222fcb1
doc: use "previous"/"preceding" instead of "above" as modifier
Trott Aug 22, 2020
acf63b0
build,deps: add gen-openssl target
evanlucas Aug 6, 2020
f6c0b27
deps: add openssl support for arm64
evanlucas Jul 7, 2020
d2f44a7
build: add support for build on arm64
evanlucas Jul 7, 2020
36c705d
meta: enable wasi for CODEOWNERS
gengjiawen Aug 23, 2020
5c968a0
errors: use `ErrorPrototypeToString` from `primordials` object
ExE-Boss Aug 23, 2020
4a0c01e
tools,doc: remove "toc" anchor name
Trott Aug 23, 2020
302d389
src,doc: rephrase for clarity
wjabbour Aug 22, 2020
2a7c65a
src,doc: fix wording to refer to context, not environment
wjabbour Aug 22, 2020
f50fec6
doc: use consistent typography for node-addon-api
Trott Aug 24, 2020
1b27f09
doc: provide more guidance about process.version
Trott Aug 24, 2020
533d00d
doc: fix CHANGELOG.md parsing issue
juanarbol Aug 25, 2020
1e33bfc
doc: make minor fixes to maintaining-openssl.md
Trott Aug 25, 2020
a5b4526
doc: simplify "make use of" to "use"
Trott Aug 21, 2020
481cced
deps: update brotli to v1.0.9
addaleax Aug 26, 2020
cda459e
zlib: replace usage of internal stream state with public api
lundibundi Aug 23, 2020
3c4abe0
net: replace usage of internal stream state with public api
lundibundi Aug 23, 2020
0695e24
doc: make minor improvements to query string sentence in http2.md
Trott Aug 26, 2020
46f94f9
test: make test-tls-reuse-host-from-socket pass without internet
Trott Aug 28, 2020
3fd7889
test: add readline test for escape sequence
Trott Aug 28, 2020
327d009
test: fix typo in test/parallel/test-icu-punycode.js
watilde Aug 26, 2020
d44b05b
stream: allow using `.push()`/`.unshift()` during `once('data')`
addaleax Aug 28, 2020
8d27998
build: use latest node-core-utils from npm
lundibundi Aug 29, 2020
9bb6814
build: use autorebase option for git node land
lundibundi Aug 29, 2020
b575e63
doc: fix typos in buffer doc
robhybrid Aug 30, 2020
4e2415f
doc: fix broken link to writableEnded in deprecations doc
Trott Aug 30, 2020
23389a0
doc: fix broken link to response.finished in deprecations doc
Trott Aug 30, 2020
4d28435
doc: fix broken link to response.writableFinished in deprecations doc
Trott Aug 30, 2020
c68c6cd
doc: drop the --production flag for installing windows-build-tools
DeeDeeG Aug 29, 2020
0bd1768
test: remove incorrect debug() in test-policy-integrity
Trott Aug 28, 2020
e7c74eb
doc: change effected to affected
wjabbour Aug 30, 2020
3975dd3
doc,tools: remove malfunctioning Linux manpage linker
Trott Aug 30, 2020
60774c0
build: close stalled issues and PRs with github action
phillipj Jul 29, 2020
9107595
build: comment about auto close when stalled via with github action
phillipj Aug 10, 2020
0ec3e61
tools,doc: fix global table of content active element
aduh95 Aug 29, 2020
8cc7a73
doc: revise commit-queue.md
Trott Sep 1, 2020
fed08a8
tools,doc: allow page titles to contain inline code
aduh95 Aug 31, 2020
eeb8a4a
tools: update ESLint to 7.8.0
cjihrig Sep 1, 2020
0f61020
tools: update ESLint to 7.8.1
cjihrig Sep 1, 2020
6ccacdf
querystring: manage percent character at unescape
watilde Sep 1, 2020
1dce35d
tools: add banner to lint-md.js by rollup.config.js
KuthorX Jul 7, 2020
00e020b
src: disallow JS execution during exit()
addaleax Sep 2, 2020
5eb1c9c
src: add get/set pair for env context awareness
codebytere Sep 1, 2020
2529ba2
doc: change color contrast for accessibility
Trott Sep 4, 2020
cd4b2aa
test: change var to let
PoojaDurgad Aug 24, 2020
627e484
test: use mustCall() in test-http-timeout
PoojaDurgad Aug 25, 2020
80fa1f5
doc: fix malformed hashes in assert.md
Trott Sep 3, 2020
d7989bd
doc: use consistent header typography
Trott Sep 3, 2020
3c98411
doc: fix certificate display in tls doc
Trott Sep 3, 2020
1ce26fe
doc: remove style for empty links
aduh95 Sep 3, 2020
08b5613
doc: update syntax highlighting color for accessibility
Trott Sep 5, 2020
6d6c6fa
tools: fix doc build targets
aduh95 Sep 4, 2020
fb1a133
doc: spruce up user journey to local docs browsing
DerekNonGeneric Aug 30, 2020
a3c59d8
tools: fix docopen target
aduh95 Sep 4, 2020
7c947b2
doc: add deprecated badge to legacy URL methods
aduh95 Aug 26, 2020
7bc26c2
bootstrap: correct --frozen-intrinsics override fix
guybedford Sep 3, 2020
ef8d373
doc: change stablility-2 color for accessibility
Trott Sep 4, 2020
65b7bf4
doc: restore color for visited links
Trott Sep 8, 2020
756ac65
http: fix crash for sync write errors during header parsing
addaleax Jul 7, 2020
867c451
test: add regression tests for HTTP parser crash
addaleax Jul 7, 2020
4d0129a
http2: do not modify explicity set date headers
rexagod Apr 25, 2020
17a098b
cli: add alias for report-directory to make it consistent
May 27, 2020
5c3c8b3
events: variable originalListener is useless
fuxingZhang May 28, 2020
2302dff
doc: fix typo in cli.md for report-dir
Jun 4, 2020
33b22d7
zlib: add `maxOutputLength` option
rosaxxny May 22, 2020
be6aee9
dgram: allow typed arrays in .send()
SirR4T Aug 20, 2018
388d125
http: expose host and protocol on ClientRequest
Jun 9, 2020
7551a8b
http2: return this for Http2ServerRequest#setTimeout
rexagod Jun 20, 2020
1b24d3a
zlib: remove redundant variable in zlibBufferOnEnd
puzpuzpuz Jun 26, 2020
fb68487
http: return this from IncomingMessage#destroy()
cjihrig Apr 11, 2020
19b55be
src: add equality operators for BaseObjectPtr
addaleax Jun 6, 2020
9b27933
tls: make 'createSecureContext' honor more options
mkrawczuk Jun 19, 2020
403deb7
src: allow setting a dir for all diagnostic output
May 27, 2020
de174cd
dgram: add IPv6 scope id suffix to received udp6 dgrams
pekkanikander Jul 26, 2017
18e8687
src: allow preventing SetPromiseRejectCallback
codebytere Jul 16, 2020
e7486d4
n-api: support type-tagging objects
Jun 14, 2019
45d2f4d
async_hooks: add AsyncResource.bind utility
jasnell Jul 31, 2020
07968ac
async_hooks: improve property descriptors in als.bind
Flarna Aug 4, 2020
0a44017
async_hooks: avoid unneeded AsyncResource creation
Flarna Aug 3, 2020
2cf2316
n-api,src: provide asynchronous cleanup hooks
addaleax Jul 31, 2020
148383f
async_hooks: avoid GC tracking of AsyncResource in ALS
Flarna Aug 3, 2020
c440748
n-api: fix use-after-free with napi_remove_async_cleanup_hook
addaleax Aug 7, 2020
5846bef
doc: use _Class Method_ in async_hooks.md
Trott Aug 4, 2020
d05f615
doc: tidy some addons.md text
Trott Aug 6, 2020
14d4bfa
doc: use _Static method_ instead of _Class Method_
Trott Aug 7, 2020
987e0cb
timers: allow timers to be used as primitives
lundibundi Jun 19, 2020
9d07217
buffer: alias UInt ➡️ Uint in buffer methods
addaleax Aug 11, 2020
06c5120
build: add build flag for OSS-Fuzz integration
DavidKorczynski Aug 13, 2020
4079cdd
http2: fix Http2Response.sendDate
joaolucasl Aug 20, 2020
2b3d4bd
meta: remove non-existent quic from CODEOWNERS
richardlau Aug 27, 2020
b117467
doc: improve link-local text in dgram.md
Trott Aug 21, 2020
2c409a2
perf_hooks: add idleTime and event loop util
trevnorris Aug 25, 2020
53c9975
crypto: add randomInt function
olalonde Aug 2, 2020
921129c
crypto: align parameter names with documentation
Trott Sep 4, 2020
8ed4ab5
doc: format exponents better
tniessen Sep 4, 2020
bf39354
doc: add link to safe integer definition
tniessen Sep 4, 2020
5ef9ee4
crypto: fix randomInt range check
tniessen Sep 4, 2020
bf5a85b
crypto: improve randomInt out-of-range error message
Trott Sep 7, 2020
2b7273b
crypto: improve invalid arg type message for randomInt()
Trott Sep 7, 2020
d60c487
test: remove setMaxListeners in test-crypto-random
tniessen Sep 6, 2020
3954b8f
doc: add note about path.basename on Windows
tniessen Sep 5, 2020
43c0174
test: revise test-policy-integrity
Trott Sep 8, 2020
55b8caa
doc: fix broken links in deprecations.md
Trott Sep 8, 2020
ec5a0ad
doc: fix broken link in fs.md
Trott Sep 8, 2020
1e39820
doc: fix broken link in http2.md
Trott Sep 9, 2020
255d47a
doc: fix broken link in perf_hooks.md
Trott Sep 9, 2020
b47172d
doc,test: specify and test CLI option precedence rules
addaleax Sep 8, 2020
f0b9866
doc: update security process
mhdawson Sep 8, 2020
0f9908b
doc: add missing changes entry for breakEvalOnSigint REPL option
addaleax Sep 10, 2020
f3f72fd
doc: update my email address
mhdawson Sep 8, 2020
c7eb462
meta: update my collab entry
devsnek Sep 12, 2020
745987e
doc: update contact info for Ash Cripps
Sep 10, 2020
23dcfe5
doc: fix left nav color contrast
Trott Sep 10, 2020
09100ce
meta: add links to OpenJSF Slack
mmarchini Sep 9, 2020
62436e6
doc: fix minor punctuation issue in path.md
amilajack Sep 9, 2020
ff0b100
build: filter issues & PRs to auto close by matching on stalled label
phillipj Sep 11, 2020
799fad7
doc: perform cleanup on security-release-process.md
Trott Sep 11, 2020
52eba5b
doc: add missing copyFile change history
codebytere Sep 4, 2020
d94dac4
doc: update process.release
schamberg97 Sep 12, 2020
55ed2d2
tools: update ESLint to 7.9.0
cjihrig Sep 12, 2020
4af4a80
doc: remove problematic auto-linking of curl man pages
Trott Sep 13, 2020
942551e
test: improve pummel/test-timers.js
Trott Sep 13, 2020
2b86032
doc: fix broken link in crypto.md
Trott Sep 14, 2020
3094ace
doc: fix deprecation documentation inconsistencies
aduh95 Sep 6, 2020
c606ed7
doc: fix missing word in dgram.md
Nibbler999 Sep 16, 2020
3ffaf66
doc: replace "you should do X" with "do X"
Trott Sep 14, 2020
ee1bcdb
doc: remove "end user"
Trott Sep 15, 2020
d81db1d
doc: add technical values document
mhdawson Sep 10, 2020
8f2d2aa
build: increase API requests for stale action
phillipj Sep 16, 2020
f050ecc
doc: fix small grammatical issues in timers.md
wjabbour Sep 15, 2020
e21d1cd
doc: add issue labels sections to release guide
targos Sep 16, 2020
89636e3
doc: update attributes used by n-api samples (#35220)
Flarna Sep 18, 2020
6669eff
doc: clarify use of NAPI_EXPERIMENTAL
mhdawson Sep 14, 2020
e026ce9
doc: sort repl references in ASCII order
Trott Sep 16, 2020
1018e52
doc: remove excessive formatting in dgram.md
Trott Sep 16, 2020
5a6bdd0
test: improve assertions in pummel/test-timers
Trott Sep 15, 2020
746517a
doc: revise stability section of values doc
Trott Sep 17, 2020
55dc7aa
doc: standardize on _backward_
Trott Sep 17, 2020
1d3638b
src: use enum for refed flag on native immediates
addaleax May 17, 2020
7d92ac7
src: make `FreeEnvironment()` perform all necessary cleanup
addaleax Nov 10, 2019
9a5cec3
src: fix memory leak in CreateEnvironment when bootstrap fails
addaleax Nov 11, 2019
b7350e8
src: move worker_context from Environment to IsolateData
addaleax Nov 12, 2019
e809a5c
src: associate is_main_thread() with worker_context()
addaleax Nov 12, 2019
808dedc
src: align worker and main thread code with embedder API
addaleax Nov 11, 2019
c5aa3f4
src: provide a variant of LoadEnvironment taking a callback
addaleax Nov 13, 2019
4a6748d
src: add LoadEnvironment() variant taking a string
addaleax Nov 19, 2019
f325c95
test: re-enable cctest that was commented out
addaleax Feb 27, 2020
8005e63
src: add unique_ptr equivalent of CreatePlatform
addaleax Feb 28, 2020
a770a35
src: make InitializeNodeWithArgs() official public API
addaleax Feb 28, 2020
9b84ee6
src: add ability to look up platform based on `Environment*`
addaleax Feb 28, 2020
2f8f767
src: allow non-Node.js TracingControllers
addaleax Feb 28, 2020
a28c990
src: fix what a dispose without checking
Jan 8, 2020
b8c9048
src: shutdown platform from FreePlatform()
addaleax Feb 28, 2020
4af336d
src,test: add full-featured embedder API test
addaleax Feb 28, 2020
1a70820
doc: add basic embedding example documentation
addaleax Feb 28, 2020
cb635c2
test: add extended embedder cctest
addaleax Mar 12, 2020
61eec0c
test: wait for message from parent in embedding cctest
addaleax Mar 30, 2020
ff0a036
embedding: provide hook for custom process.exit() behaviour
addaleax Mar 28, 2020
7a8f59f
embedding: make Stop() stop Workers
addaleax Mar 29, 2020
bdf6d41
test: use InitializeNodeWithArgs in cctest
addaleax Mar 21, 2020
bd71cdf
test: use common.buildType in embedding test
addaleax Mar 22, 2020
1066341
src: initialize inspector before RunBootstrapping()
addaleax Apr 5, 2020
18ecaeb
worker: unify custom error creation
addaleax Apr 27, 2020
4513b6a
src: make `Environment::interrupt_data_` atomic
addaleax Mar 22, 2020
4704e58
src: fix cleanup hook removal for InspectorTimer
addaleax Mar 27, 2020
2e4536e
src: use env->RequestInterrupt() for inspector io thread start
addaleax Mar 22, 2020
29620c4
src: use env->RequestInterrupt() for inspector MainThreadInterface
addaleax Mar 22, 2020
1474405
src: flush V8 interrupts from Environment dtor
addaleax Mar 28, 2020
7e2cd72
src: add callback scope for native immediates
addaleax Jul 14, 2020
26ede7f
test,doc: add missing uv_setup_args() calls
cjihrig Aug 12, 2020
57564eb
deps: V8: cherry-pick 71736859756b2bd0444bdb0a87a
danbev Sep 15, 2020
e9e3390
deps: V8: backport 3f071e3e7e15
Sep 22, 2020
27ceec0
Forces Powershell to use tls1.2
bzoz Jul 21, 2020
4277d95
doc: mark assert.CallTracker experimental
BridgeAR Apr 28, 2020
d1be44c
meta: update module pages in CODEOWNERS
aduh95 Aug 26, 2020
b0c1aca
test: verify threadId in reports
Jan 28, 2020
9173b09
worker: add stack size resource limit option
addaleax Apr 27, 2020
4cd7f5f
test: add non-ASCII character embedding test
addaleax Jun 19, 2020
5e28660
src: allow embedders to disable esm loader
codebytere Jun 26, 2020
efd46e3
lib: always initialize esm loader callbackMap
codebytere Jul 1, 2020
5e9f0cf
worker: fix --abort-on-uncaught-exception handling
addaleax Aug 11, 2020
b7e4d5f
src: shutdown libuv before exit()
addaleax Sep 2, 2020
5db8b35
deps: V8: cherry-pick eec10a2fd8fa
Qard Jun 6, 2020
232f6e1
test: AsyncLocalStorage works with thenables
Flarna Jun 6, 2020
a19933f
fs: implement lutimes
arcanis May 14, 2020
0affe86
src: add public APIs to manage v8::TracingController
addaleax Jun 11, 2020
8545fb2
test: add common/udppair utility
jasnell May 12, 2020
a5aa3dd
n-api: re-implement async env cleanup hooks
Aug 17, 2020
3e21dd9
src: add option to track unmanaged file descriptors
addaleax Jul 10, 2020
b4819db
worker: add option to track unmanaged file descriptors
addaleax Jul 10, 2020
667d520
src: introduce BaseObject base FunctionTemplate
addaleax Apr 8, 2020
8e1698a
worker: allow transferring/cloning generic BaseObjects
addaleax Apr 9, 2020
0d35eaa
worker: allow passing JS wrapper objects via postMessage
addaleax Jun 6, 2020
dd51ba3
worker,fs: make FileHandle transferable
addaleax Jun 6, 2020
dafa380
worker: emit `'messagerror'` events for failed deserialization
addaleax Jun 8, 2020
9197882
src: rename internal key handles to KeyObjectHandle
tniessen May 10, 2020
bf3aaa3
src: add NativeKeyObject base class
tniessen May 10, 2020
50b1cde
src: store key data in separate class
tniessen May 11, 2020
b828560
crypto: allow KeyObjects in postMessage
tniessen May 11, 2020
090f869
src: fix minor comment typo in KeyObjectData
danbev Jul 2, 2020
ed72d83
crypto: simplify KeyObject constructor
Trott Sep 5, 2020
44864d7
worker: do not crash when JSTransferable lists untransferable value
addaleax Aug 13, 2020
139442c
worker: add public method for marking objects as untransferable
addaleax Jun 19, 2020
6ee800f
buffer: also alias BigUInt methods
addaleax Aug 28, 2020
63cd05b
src: fix ParseEncoding
sapics Jun 16, 2020
4ff6c77
deps: V8: cherry-pick e06ace6b5cdb
addaleax Aug 7, 2020
3598056
test: add vm crash regression test
addaleax Aug 7, 2020
9f16b7f
lib: improve debuglog() performance
mscdex Mar 14, 2020
4a2accb
internal: rename error-serdes for consistency
evanlucas Jun 8, 2020
8d0c21f
util: restrict custom inspect function + vm.Context interaction
addaleax Jun 1, 2020
cef9921
doc: specify how fs.WriteStream/ReadStreams are created
jasnell Jul 3, 2020
ed055c0
doc: replace http to https of link urls
sapics Jun 29, 2020
a9f0fc9
doc: document behavior for once(ee, 'error')
jasnell Jul 6, 2020
831328b
doc: add note about multiple sync events and once
jasnell Jul 6, 2020
05da376
doc: remove errors that were never released
Trott Jul 4, 2020
2f67e99
test: add arrayOfStreams to pipeline
rickyes Jul 1, 2020
b9d0f73
n-api: create N-API version 7
Sep 15, 2020
3d1bdc2
http: add maxTotalSockets to agent class
rickyes May 28, 2020
1a8669d
doc: Add maxTotalSockets option to agent constructor
rickyes Jun 22, 2020
b7be751
repl: support --loader option in builtin REPL
targos May 16, 2020
d065334
module: package "imports" field
guybedford Jun 28, 2020
00aa935
module: self referential modules in repl or `-r`
dnlup Jul 16, 2020
3ad146d
module: use cjsCache over esm injection
guybedford Aug 3, 2020
d9857fd
module: custom --conditions flag option
guybedford Aug 5, 2020
cecc193
module: share CJS/ESM resolver fns, refactoring
guybedford Aug 9, 2020
740c958
module: fix check for package.json at volume root
DerekNonGeneric Aug 2, 2020
fc93cc9
module: drop `-u` alias for `--conditions`
richardlau Aug 26, 2020
551be2a
esm: improve error message of ERR_UNSUPPORTED_ESM_URL_SCHEME
lundibundi Aug 16, 2020
9159649
esm: shorten ERR_UNSUPPORTED_ESM_URL_SCHEME message
Trott Aug 19, 2020
bf7b796
esm: better package.json parser errors
guybedford Sep 9, 2020
89a58f6
module: use isURLInstance instead of instanceof
aduh95 Aug 27, 2020
ed3278d
module: fix crash on multiline named cjs imports
ctavan Sep 18, 2020
d68bff2
2020-10-06, Version 12.19.0 'Erbium' (LTS)
codebytere Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
module: package "imports" field
PR-URL: #34117
Backport-PR-URL: #35385
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Bradley Farias <[email protected]>
  • Loading branch information
guybedford authored and codebytere committed Oct 1, 2020
commit d065334d42e0206d8875fddc6631446f4ca05617
7 changes: 7 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,12 @@ A non-context-aware native addon was loaded in a process that disallows them.

A given value is out of the accepted range.

<a id="ERR_PACKAGE_IMPORT_NOT_DEFINED"></a>
### `ERR_PACKAGE_IMPORT_NOT_DEFINED`

The `package.json` ["imports" field][] does not define the given internal
package specifier mapping.

<a id="ERR_PACKAGE_PATH_NOT_EXPORTED"></a>
### `ERR_PACKAGE_PATH_NOT_EXPORTED`

Expand Down Expand Up @@ -2533,3 +2539,4 @@ closed.
[vm]: vm.html
[self-reference a package using its name]: esm.html#esm_self_referencing_a_package_using_its_name
[define a custom subpath]: esm.html#esm_subpath_exports
["imports" field]: esm.html#esm_internal_package_imports
159 changes: 122 additions & 37 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,43 @@ and in a CommonJS one. For example, this code will also work:
const { something } = require('a-package/foo'); // Loads from ./foo.js.
```

### Internal package imports

In addition to the `"exports"` field it is possible to define internal package
import maps that only apply to import specifiers from within the package itself.

Entries in the imports field must always start with `#` to ensure they are
clearly disambiguated from package specifiers.

For example, the imports field can be used to gain the benefits of conditional
exports for internal modules:

```json
// package.json
{
"imports": {
"#dep": {
"node": "dep-node-native",
"default": "./dep-polyfill.js"
}
},
"dependencies": {
"dep-node-native": "^1.0.0"
}
}
```

where `import '#dep'` would now get the resolution of the external package
`dep-node-native` (including its exports in turn), and instead get the local
file `./dep-polyfill.js` relative to the package in other environments.

Unlike the exports field, import maps permit mapping to external packages
because this provides an important use case for conditional loading and also can
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.

### Dual CommonJS/ES module packages

Prior to the introduction of support for ES modules in Node.js, it was a common
Expand Down Expand Up @@ -1577,10 +1614,11 @@ The resolver can throw the following errors:
or package subpath specifier.
* _Invalid Package Configuration_: package.json configuration is invalid or
contains an invalid configuration.
* _Invalid Package Target_: Package exports define a target module within the
package that is an invalid type or string target.
* _Invalid Package Target_: Package exports or imports define a target module
for the package that is an invalid type or string target.
* _Package Path Not Exported_: Package exports do not define or permit a target
subpath in the package for the given module.
* _Package Import Not Defined_: Package imports do not define the specifier.
* _Module Not Found_: The package or module requested does not exist.

<details>
Expand All @@ -1592,11 +1630,14 @@ The resolver can throw the following errors:
> 1. If _specifier_ is a valid URL, then
> 1. Set _resolvedURL_ to the result of parsing and reserializing
> _specifier_ as a URL.
> 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
> 1. Set _resolvedURL_ to the URL resolution of _specifier_ relative to
> _parentURL_.
> 1. Otherwise, if _specifier_ starts with _"#"_, then
> 1. Set _resolvedURL_ to the result of
> **PACKAGE_INTERNAL_RESOLVE**(_specifier_, _parentURL_).
> 1. If _resolvedURL_ is **null** or **undefined**, throw a
> _Package Import Not Defined_ error.
> 1. Otherwise,
> 1. Note: _specifier_ is now a bare specifier.
> 1. Set _resolvedURL_ the result of
Expand Down Expand Up @@ -1634,7 +1675,7 @@ The resolver can throw the following errors:
> 1. If _packageSubpath_ contains any _"."_ or _".."_ segments or percent
> encoded strings for _"/"_ or _"\\"_, then
> 1. Throw an _Invalid Module Specifier_ error.
> 1. Set _selfUrl_ to the result of
> 1. Let _selfUrl_ be the result of
> **SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
> 1. If _selfUrl_ isn't empty, return _selfUrl_.
> 1. If _packageSubpath_ is _undefined_ and _packageName_ is a Node.js builtin
Expand All @@ -1657,8 +1698,11 @@ The resolver can throw the following errors:
> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then
> 1. Let _exports_ be _pjson.exports_.
> 1. If _exports_ is not **null** or **undefined**, then
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
> _packageSubpath_, _pjson.exports_).
> 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_RESOLVE**(
> _packageURL_, _packageSubpath_, _pjson.exports_).
> 1. If _resolved_ is **null** or **undefined**, throw a
> _Package Path Not Exported_ error.
> 1. Return _resolved_.
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
> 1. Throw a _Module Not Found_ error.

Expand All @@ -1679,8 +1723,11 @@ The resolver can throw the following errors:
> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then
> 1. Let _exports_ be _pjson.exports_.
> 1. If _exports_ is not **null** or **undefined**, then
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_,
> _pjson.exports_).
> 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_RESOLVE**(
> _packageURL_, _subpath_, _pjson.exports_).
> 1. If _resolved_ is **null** or **undefined**, throw a
> _Package Path Not Exported_ error.
> 1. Return _resolved_.
> 1. Return the URL resolution of _subpath_ in _packageURL_.
> 1. Otherwise, return **undefined**.

Expand All @@ -1693,12 +1740,18 @@ The resolver can throw the following errors:
> not starting with _"."_, throw an _Invalid Package Configuration_ error.
> 1. If _pjson.exports_ is a String or Array, or an Object containing no
> keys starting with _"."_, then
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
> _pjson.exports_, _""_).
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
> _packageURL_, _pjson.exports_, _""_, **false**, _defaultEnv_).
> 1. If _resolved_ is **null** or **undefined**, throw a
> _Package Path Not Exported_ error.
> 1. Return _resolved_.
> 1. If _pjson.exports_ is an Object containing a _"."_ property, then
> 1. Let _mainExport_ be the _"."_ property in _pjson.exports_.
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
> _mainExport_, _""_).
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
> _packageURL_, _mainExport_, _""_, **false**, _defaultEnv_).
> 1. If _resolved_ is **null** or **undefined**, throw a
> _Package Path Not Exported_ error.
> 1. Return _resolved_.
> 1. Throw a _Package Path Not Exported_ error.
> 1. Let _legacyMainURL_ be the result applying the legacy
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
Expand All @@ -1712,31 +1765,37 @@ The resolver can throw the following errors:
> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
> 1. If _packagePath_ is a key of _exports_, then
> 1. Let _target_ be the value of _exports\[packagePath\]_.
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
> _""_, _defaultEnv_).
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
> _""_, **false**, _defaultEnv_).
> 1. Let _directoryKeys_ be the list of keys of _exports_ ending in
> _"/"_, sorted by length descending.
> 1. For each key _directory_ in _directoryKeys_, do
> 1. If _packagePath_ starts with _directory_, then
> 1. Let _target_ be the value of _exports\[directory\]_.
> 1. Let _subpath_ be the substring of _target_ starting at the index
> of the length of _directory_.
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
> _subpath_, _defaultEnv_).
> 1. Throw a _Package Path Not Exported_ error.
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
> _subpath_, **false**, _defaultEnv_).
> 1. Return **null**.

**PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _env_)
**PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _internal_, _env_)

> 1. If _target_ is a String, then
> 1. If _target_ does not start with _"./"_ or contains any _"node_modules"_
> segments including _"node_modules"_ percent-encoding, throw an
> _Invalid Package Target_ error.
> 1. If _target_ contains any _"node_modules"_ segments including
> _"node_modules"_ percent-encoding, throw an _Invalid Package Target_
> error.
> 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
> throw an _Invalid Module Specifier_ error.
> 1. If _target_ does not start with _"./"_, then
> 1. If _target_ does not start with _"../"_ or _"/"_ and is not a valid
> URL, then
> 1. If _internal_ is **true**, return **PACKAGE_RESOLVE**(
> _target_ + _subpath_, _packageURL_ + _"/"_)_.
> 1. Otherwise throw an _Invalid Package Target_ error.
> 1. Let _resolvedTarget_ be the URL resolution of the concatenation of
> _packageURL_ and _target_.
> 1. If _resolvedTarget_ is not contained in _packageURL_, throw an
> _Invalid Package Target_ error.
> 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
> throw an _Invalid Module Specifier_ error.
> 1. Let _resolved_ be the URL resolution of the concatenation of
> _subpath_ and _resolvedTarget_.
> 1. If _resolved_ is not contained in _resolvedTarget_, throw an
Expand All @@ -1748,22 +1807,48 @@ The resolver can throw the following errors:
> 1. For each property _p_ of _target_, in object insertion order as,
> 1. If _p_ equals _"default"_ or _env_ contains an entry for _p_, then
> 1. Let _targetValue_ be the value of the _p_ property in _target_.
> 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(
> _packageURL_, _targetValue_, _subpath_, _env_), continuing the
> loop on any _Package Path Not Exported_ error.
> 1. Throw a _Package Path Not Exported_ error.
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
> _packageURL_, _targetValue_, _subpath_, _internal_, _env_)
> 1. If _resolved_ is equal to **undefined**, continue the loop.
> 1. Return _resolved_.
> 1. Return **undefined**.
> 1. Otherwise, if _target_ is an Array, then
> 1. If _target.length is zero, throw a _Package Path Not Exported_ error.
> 1. If _target.length is zero, return **null**.
> 1. For each item _targetValue_ in _target_, do
> 1. If _targetValue_ is an Array, continue the loop.
> 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
> _targetValue_, _subpath_, _env_), continuing the loop on any
> _Package Path Not Exported_ or _Invalid Package Target_ error.
> 1. Throw the last fallback resolution error.
> 1. Otherwise, if _target_ is _null_, throw a _Package Path Not Exported_
> error.
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
> _packageURL_, _targetValue_, _subpath_, _internal_, _env_),
> continuing the loop on any _Invalid Package Target_ error.
> 1. If _resolved_ is **undefined**, continue the loop.
> 1. Return _resolved_.
> 1. Return or throw the last fallback resolution **null** return or error.
> 1. Otherwise, if _target_ is _null_, return **null**.
> 1. Otherwise throw an _Invalid Package Target_ error.

**PACKAGE_INTERNAL_RESOLVE**(_specifier_, _parentURL_)

> 1. Assert: _specifier_ begins with _"#"_.
> 1. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
> 1. Throw an _Invalid Module Specifier_ error.
> 1. Let _packageURL_ be the result of **READ_PACKAGE_SCOPE**(_parentURL_).
> 1. If _packageURL_ is not **null**, then
> 1. Let _pjson_ be the result of **READ_PACKAGE_JSON**(_packageURL_).
> 1. If _pjson.imports is a non-null Object, then
> 1. Let _imports_ be _pjson.imports_.
> 1. If _specifier_ is a key of _imports_, then
> 1. Let _target_ be the value of _imports\[specifier\]_.
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
> _""_, **true**, _defaultEnv_).
> 1. Let _directoryKeys_ be the list of keys of _imports_ ending in
> _"/"_, sorted by length descending.
> 1. For each key _directory_ in _directoryKeys_, do
> 1. If _specifier_ starts with _directory_, then
> 1. Let _target_ be the value of _imports\[directory\]_.
> 1. Let _subpath_ be the substring of _target_ starting at the
> index of the length of _directory_.
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
> _subpath_, **true**, _defaultEnv_).
> 1. Return **null**.

**ESM_FORMAT**(_url_)

> 1. Assert: _url_ corresponds to an existing file.
Expand Down
13 changes: 12 additions & 1 deletion doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ require(X) from module at path Y
a. LOAD_AS_FILE(Y + X)
b. LOAD_AS_DIRECTORY(Y + X)
c. THROW "not found"
4. LOAD_SELF_REFERENCE(X, dirname(Y))
4. If X begins with '#'
a. LOAD_INTERAL_IMPORT(X, Y)
4. LOAD_SELF_REFERENCE(X, Y)
5. LOAD_NODE_MODULES(X, dirname(Y))
6. THROW "not found"

Expand Down Expand Up @@ -236,6 +238,15 @@ LOAD_PACKAGE_EXPORTS(DIR, X)
12. Otherwise
a. If RESOLVED is a file, load it as its file extension format. STOP
13. Throw "not found"

LOAD_INTERNAL_IMPORT(X, START)
1. Find the closest package scope to START.
2. If no scope was found or the `package.json` has no "imports", return.
3. let RESOLVED =
fileURLToPath(PACKAGE_INTERNAL_RESOLVE(X, pathToFileURL(START)), as defined
in the ESM resolver.
4. If RESOLVED is not a valid file, throw "not found"
5. Load RESOLVED as its file extension format. STOP
```

## Caching
Expand Down
64 changes: 23 additions & 41 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
NumberIsInteger,
ObjectDefineProperty,
ObjectKeys,
StringPrototypeSlice,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
Expand Down Expand Up @@ -1097,16 +1096,9 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError);
E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError);
E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError);
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
if (subpath === undefined) {
return `Invalid package name '${pkgPath}' imported from ${base}`;
} else if (base === undefined) {
assert(subpath !== '.');
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath}${sep}package.json`;
}
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath} imported from ${base}`;
E('ERR_INVALID_MODULE_SPECIFIER', (request, reason, base = undefined) => {
return `Invalid module "${request}" ${reason}${base ?
` imported from ${base}` : ''}`;
}, TypeError);
E('ERR_INVALID_OPT_VALUE', (name, value) =>
`The value "${String(value)}" is invalid for option "${name}"`,
Expand All @@ -1120,31 +1112,20 @@ E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
return `Invalid JSON in ${path} imported from ${message}`;
}, Error);
E('ERR_INVALID_PACKAGE_TARGET',
(pkgPath, key, subpath, target, base = undefined) => {
const relError = typeof target === 'string' &&
(pkgPath, key, target, isImport = false, base = undefined) => {
const relError = typeof target === 'string' && !isImport &&
target.length && !StringPrototypeStartsWith(target, './');
if (key === null) {
if (subpath !== '') {
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
`for '${subpath}' in the package config ${pkgPath} imported from ` +
`${base}.${relError ? '; targets must start with "./"' : ''}`;
}
return `Invalid "exports" main target ${target} defined in the ` +
`package config ${pkgPath} imported from ${base}${relError ?
'; targets must start with "./"' : ''}`;
} else if (key === '.') {
if (key === '.') {
assert(isImport === false);
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
`in the package config ${pkgPath}${sep}package.json${relError ?
'; targets must start with "./"' : ''}`;
} else if (relError) {
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json; ` +
'targets must start with "./"';
`in the package config ${pkgPath}package.json${base ?
` imported from ${base}` : ''}${relError ?
'; targets must start with "./"' : ''}`;
}
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json`;
return `Invalid "${isImport ? 'imports' : 'exports'}" target ${
JSONStringify(target)} defined for '${key}' in the package config ${
pkgPath}package.json${base ? ` imported from ${base}` : ''}${relError ?
'; targets must start with "./"' : ''}`;
}, Error);
E('ERR_INVALID_PERFORMANCE_MARK',
'The "%s" performance mark has not been set', Error);
Expand Down Expand Up @@ -1293,15 +1274,16 @@ E('ERR_OUT_OF_RANGE',
msg += ` It must be ${range}. Received ${received}`;
return msg;
}, RangeError);
E('ERR_PACKAGE_IMPORT_NOT_DEFINED', (specifier, packagePath, base) => {
return `Package import specifier "${specifier}" is not defined${packagePath ?
` in package ${packagePath}package.json` : ''} imported from ${base}`;
}, TypeError);
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
if (subpath === '.') {
return `No "exports" main resolved in ${pkgPath}${sep}package.json`;
} else if (base === undefined) {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath}${sep}package.json`;
}
if (subpath === '.')
return `No "exports" main defined in ${pkgPath}package.json${base ?
` imported from ${base}` : ''}`;
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath} imported from ${base}`;
pkgPath}package.json${base ? ` imported from ${base}` : ''}`;
}, Error);
E('ERR_REQUIRE_ESM',
(filename, parentPath = null, packageJsonPath = null) => {
Expand Down Expand Up @@ -1419,7 +1401,7 @@ E('ERR_UNKNOWN_FILE_EXTENSION',
E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError);
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError);
E('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " +
'resolving ES modules, imported from %s', Error);
'resolving ES modules imported from %s', Error);
E('ERR_UNSUPPORTED_ESM_URL_SCHEME', 'Only file and data URLs are supported ' +
'by the default ESM loader', Error);

Expand Down
Loading