Provide a reliable way to find the entrypoint path or URL
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.4k
- 平均マージ
- 4日 3時間
- マージ済み PR(30日)
- 272
説明
What is the problem this feature will solve?
This solves the same problem as require.main.filename did in a CommonJS-only world: finding the entrypoint script for the Node.js process. This is most commonly used to determine the whether the current file is the entrypoint, but is also useful for various other sorts of introspection about the running Node.js environment. My specific use-case is finding a sensible default base URL to use to replicate Node.js's package resolution algorithm.
What is the feature you are proposing to solve the problem?
I suggest something like process.cliEntrypoint or process.cliMainUrl. I think it's important that any solution be usable regardless of whether the current module is CJS or ESM.
What alternatives have you considered?
require.main.filename provides this information but it doesn't work outside of CJS files, nor does it work if the entrypoint itself is ESM.
process.argv[1] sometimes provides this information, but it has a number of problems:
-
If the Node.js CLI is run without a file extension, like
node myappinstead ofnode myapp.js,process.argv[1]won't have an extension either. -
If the entrypoint is a symlink,
process.argv[1]will point to the symlink instead of the physical JS file. This differs from__filename, which means it also differs from the logic used byrequire(). Note thatnpm execalways creates a symlink when running executables. -
process.argvis mutable, so it's possible for unrelated code to modify it in such a way that it's no longer usable to find the entrypoint.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
実装ファイルもテストも指定されていません。まず、Node.js が現在 CommonJS と ESM の CLI エントリポイントをどのように判定しているかを確認してください。ここで説明されている require.main.filename と process.argv[1] の代替手段も含みます。完了とは、安定した API が両方のモジュールシステムで動作し、拡張子のないパス、シンボリックリンク、および後からの process.argv の変更を処理できることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100