microsoft / microsoft/TypeScript
Add a module resolution mode to get module search path from Node.js executable itself
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Search Terms
node path
module path
NODE_PATH
Suggestion
TypeScript's effort to match Node.js's module resolution doesn't seem to always be accurate. Further, it can never be right if Node.js has been modified or configured in any way that does not match the emulation. It should be possible for TypeScript to locate type definitions using the actual module search path that node will be using at runtime, so that the runtime and the static type checking agree exactly on which files are used. After all, the TypeScript compilation is meant to reflect static properties of the code!
Use Cases
My organization has a monorepo-style integration build of first party modules which are available in $PREFIX/lib/node. This path is used by the node executable when processing require, but TypeScript sadly needs to be taught it through tsconfig baseUrl or similar hack. I believe this should be zero config and would fix a bunch of other similar use cases where the Node.js runtime disagrees with the TypeScript compiler.
Examples
One suggested way to set this up would be a new moduleResolution mode, alongside node and classic, which rather than emulating Node.js, actually calls Node.js itself to evaluate the actual module search path which will be used by a project. This mode could be called e.g. nodeIntrospect or something bikesheddable.
A facility to specify the command used to get the module search path could be provided for advanced usages such as running Node.js in a Docker container or other isolation mechanism. The command would merely be required to return a JSON array of paths or something.
(At this point I'm unsure if Node.js actually provides something similar to Python's sys.path for this, but if this issue is accepted in principle I could try to expose something for this in Node.js.)
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Much appreciated! Thanks!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ソースファイルやテストは指定されていません。まず、TypeScript に既存する moduleResolution の処理を見つけ、Node.js が実行時のモジュール検索パスをどのように公開しているかを調査します。完了とは、実際の Node.js の検索パスから型定義を解決する、合意済みの設計と実装があり、提案された設定およびコマンドのバリエーションをカバーしていることを意味します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- node.js, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100