nodejs / nodejs/node

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

Aperta
#61,127 3 commenti 7 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature request module
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo l’implementazione esistente di import.meta.resolve in Node.js e il comportamento alla base di --experimental-import-meta-resolve. Confronta l’esportazione node:module proposta con l’API più completa nel pull request #55756. Il lavoro è completo quando il resolver a due argomenti è esposto come API stabile con un comportamento equivalente al caso d’uso richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.