Skip to content

Commit 36a1f5b

Browse files
committed
docs changes
1 parent ac973e0 commit 36a1f5b

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

doc/api/esm.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ import { readFileSync } from 'node:fs';
322322
const buffer = readFileSync(new URL('./data.proto', import.meta.url));
323323
```
324324
325-
### `import.meta.resolve(specifier[, parent])`
325+
### `import.meta.resolve(specifier)`
326326
327327
<!--
328328
added:
@@ -337,36 +337,42 @@ changes:
337337
- v14.18.0
338338
pr-url: https://github.com/nodejs/node/pull/38587
339339
description: Add support for WHATWG `URL` object to `parentURL` parameter.
340+
- version:
341+
- REPLACEME
342+
pr-url: https://github.com/nodejs/node/pull/49028
343+
description: Unflag import.meta.resolve, with `parentURL` parameter still
344+
flagged.
340345
-->
341346
342-
> Stability: 1 - Experimental
343-
344-
This feature is only available with the `--experimental-import-meta-resolve`
345-
command flag enabled.
346-
347347
* `specifier` {string} The module specifier to resolve relative to `parent`.
348-
* `parent` {string|URL} The absolute parent module URL to resolve from. If none
349-
is specified, the value of `import.meta.url` is used as the default.
350-
* Returns: {string}
351-
352-
Provides a module-relative resolution function scoped to each module, returning
353-
the URL string. In alignment with browser behavior, this now returns
354-
synchronously.
348+
* Returns: {string} The absolute (`file:`) URL string for the resolved module.
355349
356-
> **Caveat** This can result in synchronous file-system operations, which
357-
> can impact performance similarly to `require.resolve`.
350+
[`import.meta.resolve`][] is a module-relative resolution function scoped to
351+
each module, returning the URL string.
358352
359353
```js
360354
const dependencyAsset = import.meta.resolve('component-lib/asset.css');
355+
// file:///app/node_modules/component-lib/asset.css
361356
```
362357
363-
`import.meta.resolve` also accepts a second argument which is the parent module
364-
from which to resolve:
358+
All features of the Node.js module resolution are supported. Dependency
359+
resolutions are subject to the permitted exports resolutions within the package.
365360
366361
```js
367362
import.meta.resolve('./dep', import.meta.url);
363+
// file:///app/dep
368364
```
369365
366+
> **Caveat** This can result in synchronous file-system operations, which
367+
> can impact performance similarly to `require.resolve`.
368+
369+
Previously, Node.js implemented an asynchonous resolver which also permitted
370+
a second contextual argument. The implementation has since been updated to be
371+
synchronous, with the second contextual `parent` URL still accessible behind the
372+
`--experimental-import-meta-resolve` flag:
373+
374+
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
375+
370376
## Interoperability with CommonJS
371377
372378
### `import` statements
@@ -501,8 +507,8 @@ They can instead be loaded with [`module.createRequire()`][] or
501507
502508
Relative resolution can be handled via `new URL('./local', import.meta.url)`.
503509
504-
For a complete `require.resolve` replacement, there is a flagged experimental
505-
[`import.meta.resolve`][] API.
510+
For a complete `require.resolve` replacement, there is the
511+
[import.meta.resolve][] API.
506512
507513
Alternatively `module.createRequire()` can be used.
508514
@@ -1672,7 +1678,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
16721678
[`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
16731679
[`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
16741680
[`import()`]: #import-expressions
1675-
[`import.meta.resolve`]: #importmetaresolvespecifier-parent
1681+
[`import.meta.resolve`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve
16761682
[`import.meta.url`]: #importmetaurl
16771683
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
16781684
[`initialize`]: #initialize
@@ -1690,6 +1696,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
16901696
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
16911697
[commonjs-extension-resolution-loader]: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader
16921698
[custom https loader]: #https-loader
1699+
[import.meta.resolve]: #importmetaresolvespecifier
16931700
[load hook]: #loadurl-context-nextload
16941701
[percent-encoded]: url.md#percent-encoding-in-urls
16951702
[special scheme]: https://url.spec.whatwg.org/#special-scheme

0 commit comments

Comments
 (0)