nodejs / nodejs/node

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

オープン
#61,127 コメント 3 件 リアクション 7 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request module
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、Node.js に既に存在する import.meta.resolve の実装と、--experimental-import-meta-resolve の背後にある動作を読んでください。提案されている node:module のエクスポートを、pull request #55756 にあるより包括的な API と比較してください。2 引数のリゾルバーが安定した API として公開され、要求されたユースケースと同等の動作をするようになれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, nodejs
領域
api, backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。