nodejs / nodejs/node

Expose `importMetaResolve(url, baseURL)` from `node:module`, and stabilize it

Offen
#61,127 3 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request module
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

What is the problem this feature will solve?

In Node.js based tools it's common to need to "resolve url X as if it were imported from module Y".

Node.js does not expose this as an API, even though it implements it. It only exposes "resolve url X as if it were imported from this current module", through import.meta.resolve.

https://github.com/wooorm/import-meta-resolve is, for example, a library that is basically code copy&pasted from this repository and published on npm. The annoying part is that, as Node.js resolution rules change, libraries need to change too, and you need to basically check which version of Node.js you are on to know which rules to apply.

What is the feature you are proposing to solve the problem?

Node.js does have a solution to this: the version of import.meta.resolve that takes two arguments, gated behind a flag (--experimental-import-meta-resolve). The reason it's behind a flag is because it would be different from the import.meta.resolve implementation of browsers, that takes only one argument.

It'd be great if Node.js could expose the two-args version as an export of node:module, something like

import { resolveModuleURL } from "node:module"`;

resolveModuleURL(url, parent);

with resolveModuleURL(url, import.meta.url) being equivalent to import.meta.resolve(url).

What alternatives have you considered?

This is related to https://github.com/nodejs/node/pull/55756, which implements a more complex/comprehensive API.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bestehende Implementierung von Node.js für import.meta.resolve und das Verhalten hinter --experimental-import-meta-resolve zu lesen. Vergleiche den vorgeschlagenen node:module-Export mit der umfassenderen API im pull request #55756. Als erledigt gilt die Aufgabe, wenn der Resolver mit zwei Argumenten als stabile API verfügbar ist und ein Verhalten aufweist, das dem angeforderten Anwendungsfall entspricht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs
Bereich
api, backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.