Skip to content

Commit

Permalink
[@types/node] Update the definition of import.meta.resolve(…) for `…
Browse files Browse the repository at this point in the history
…node` 20.6.

This was previously available:

- behind a flag,
- returning a `Promise`, and
- with an optional second `parent` parameter.

As of `node` v20.6.0 (https://nodejs.org/en/blog/release/v20.6.0), it is now:

- unflagged (with a single param),
- synchronous, and
- with the `parent` parameter only being supported behind the `--experimental-import-meta-resolve` flag.

To minimize the potential of confusion that would come from mixing the
unflagged version with flagged parameter, this change only documents the
unflagged version. This also matches the API implemented by all
browsers, avoiding the potential misunderstandings about the second
parameter in codebased with mixed frontend and backend code.

Note that there was a bug that sometimes returned a `URL` instead of a
`string` in v20.6.0, but this was fixed in v20.8.0
(nodejs/node#49695).
  • Loading branch information
lgarron committed Oct 12, 2023
1 parent b6a2343 commit b8a5270
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions types/node/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,12 @@ declare module 'module' {
interface ImportMeta {
url: string;
/**
* @experimental
* This feature is only available with the `--experimental-import-meta-resolve`
* command flag enabled.
*
* Provides a module-relative resolution function scoped to each module, returning
* the URL string.
*
* @param specified The module specifier to resolve relative to `parent`.
* @param parent The absolute parent module URL to resolve from. If none
* is specified, the value of `import.meta.url` is used as the default.
* @param specified The module specifier to resolve relative to the current module's URL (`import.meta.url`).
*/
resolve?(specified: string, parent?: string | URL): Promise<string>;
resolve?(specified: string): string;
}
}
export = Module;
Expand Down

0 comments on commit b8a5270

Please sign in to comment.