From ec474401b08ef26e1c06a3b0a71427bb4edc0538 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 19 Aug 2023 19:04:44 +0200 Subject: [PATCH 1/3] doc: edit `import.meta.resolve` documentation --- doc/api/esm.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 120d185d39bb64..c178affcb31193 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -329,6 +329,9 @@ added: - v13.9.0 - v12.16.2 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/49028 + description: No longer behind the `--experimental-import-meta-resolve` flag. - version: v20.0.0 pr-url: https://github.com/nodejs/node/pull/44710 description: This API now returns a string synchronously instead of a Promise. @@ -348,7 +351,7 @@ changes: * `specifier` {string} The module specifier to resolve relative to the current module. -* Returns: {string} The absolute (`file:`) URL string for the resolved module. +* Returns: {string} The absolute URL string that the specifier would resolve to. [`import.meta.resolve`][] is a module-relative resolution function scoped to each module, returning the URL string. @@ -356,18 +359,16 @@ each module, returning the URL string. ```js const dependencyAsset = import.meta.resolve('component-lib/asset.css'); // file:///app/node_modules/component-lib/asset.css +import.meta.resolve('./dep'); +// file:///app/dep ``` All features of the Node.js module resolution are supported. Dependency resolutions are subject to the permitted exports resolutions within the package. -```js -import.meta.resolve('./dep', import.meta.url); -// file:///app/dep -``` - > **Caveat** This can result in synchronous file-system operations, which -> can impact performance similarly to `require.resolve`. +> can impact performance similarly to `require.resolve`. This feature is not +> available within custom loaders (it would create a deadlock). Previously, Node.js implemented an asynchronous resolver which also permitted a second contextual argument. The implementation has since been updated to be @@ -376,9 +377,6 @@ behind the `--experimental-import-meta-resolve` flag: * `parent` {string|URL} An optional absolute parent module URL to resolve from. -> **Caveat** This feature is not available within module customization hooks (it -> would create a deadlock). - ## Interoperability with CommonJS ### `import` statements From 3d69edbc425388027ee4724150441c14ed0940b4 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 19 Aug 2023 19:33:08 +0200 Subject: [PATCH 2/3] fixup! doc: edit `import.meta.resolve` documentation --- doc/api/esm.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index c178affcb31193..9f02269f7871c6 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -359,23 +359,27 @@ each module, returning the URL string. ```js const dependencyAsset = import.meta.resolve('component-lib/asset.css'); // file:///app/node_modules/component-lib/asset.css -import.meta.resolve('./dep'); -// file:///app/dep +import.meta.resolve('./dep.js'); +// file:///app/dep.js ``` All features of the Node.js module resolution are supported. Dependency resolutions are subject to the permitted exports resolutions within the package. -> **Caveat** This can result in synchronous file-system operations, which -> can impact performance similarly to `require.resolve`. This feature is not -> available within custom loaders (it would create a deadlock). +**Caveats**: -Previously, Node.js implemented an asynchronous resolver which also permitted -a second contextual argument. The implementation has since been updated to be -synchronous, with the second contextual `parent` argument still accessible -behind the `--experimental-import-meta-resolve` flag: +* This can result in synchronous file-system operations, which + can impact performance similarly to `require.resolve`. +* This feature is not available within custom loaders (it would + create a deadlock). + +**Non-standard API**: + +When using the `--experimental-import-meta-resolve` flag, that function accepts +a second argument: * `parent` {string|URL} An optional absolute parent module URL to resolve from. + **Default:** `import.meta.url` ## Interoperability with CommonJS From d20e63068086037969ac0c646d776e60c178b449 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 4 Sep 2023 23:01:56 +0200 Subject: [PATCH 3/3] fixup! doc: edit `import.meta.resolve` documentation --- doc/api/esm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 9f02269f7871c6..79793aef9cfe24 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -329,7 +329,7 @@ added: - v13.9.0 - v12.16.2 changes: - - version: REPLACEME + - version: 20.6.0 pr-url: https://github.com/nodejs/node/pull/49028 description: No longer behind the `--experimental-import-meta-resolve` flag. - version: v20.0.0