nodejs / nodejs/node

Publish `exports` and `imports` implementations as separate module(s)

オープン
#44,535 コメント 6 件 リアクション 12 件 担当者 0 名 GitHub で見る

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

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

説明

What is the problem this feature will solve?

Projects implementing support for module resolution have to add support for the quite advanced exports and imports fields in package.json.

https://nodejs.org/api/packages.html#exports
https://nodejs.org/api/packages.html#imports

Examples of projects that have done this are Webpack, TypeScript, Jest (only exports, not imports), Yarn and probably more. AFAIK neither Rollup, Parcel or Metro (to name some bundlers) have support.

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

If the algorithm Node uses internally was published as a separate module, I hope (and believe) more projects would be able to add support more readily, and that ecosystem compatibility would improve as a result.

I think part of the reason is the complexity in supporting the algorithm needed, particularly with subpath exports, wildcards and conditionals. E.g. https://github.com/browserify/resolve/issues/222 is stuck, and https://github.com/facebook/jest/issues/9771 took a long time.

Prior art for externalizing parts of Node publishing cjs-module-lexer separately, which means Jest could implement the same feature as node itself when importing CJS from ESM (via vm API).


Note that this is not a request for the full require or ESM resolution algorithm. This is solely a request for "given this exports/imports, this specifier and these conditions, what path does it map to" - no FS access/lookups at all. API similar to https://github.com/lukeed/resolve.exports makes sense to me.

What alternatives have you considered?

Jest (and Yarn) currently use https://github.com/lukeed/resolve.exports to avoid having to implement all the resolution. It currently does not support imports (https://github.com/lukeed/resolve.exports/issues/14).

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

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

はじめの一歩

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

調査の方向性

リンクされた package exports と imports に関する Node.js ドキュメントから始め、次に引用されている resolve.exports モジュールと関連する例を比較します。ファイルシステムにアクセスせずに specifier と conditions をマッピングするスタンドアロン実装の範囲を定義します。完了条件は、提案するモジュールが exports と imports を対象としつつ、完全な require または ESM の解決とは分離されていることです。

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

評価

技術スタック
javascript, node.js
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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