microsoft / microsoft/TypeScript

Improve module resolution using "paths" of "tsconfig.json" file

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

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔍 Search Terms

Today the "paths" property only accepts the asterisk as a wildcard character, which means it is necessary to keep redeclaring other modules when they are in subdirectories, example:

{
  "compilerOptions": {
    "paths": {
      "libs/async": ["libs/async/src"],
      "libs/async/*": ["libs/async/src/*"],
      "libs/crypto": ["libs/crypto/src"],
      "libs/crypto/*": ["libs/crypto/src/*"],
      "libs/database": ["libs/database/src"],
      "libs/database/*": ["libs/database/src/*"],
      "libs/domain": ["libs/domain/src"],
      "libs/domain/*": ["libs/domain/src/*"],
      "libs/logger": ["libs/logger/src"],
      "libs/logger/*": ["libs/logger/src/*"],
    }
  }
}

Wouldn't it be interesting to accept other characters as it happens with regex? Example:

{
  "compilerOptions": {
    "paths": {
      "libs/$1": ["libs/$1/src"],
      "libs/$1/*": ["libs/$1/src/*"],
    }
  }
}

This would make TypeScript resolution more dynamic, making it easier to set up monorepos.

✅ Viability Checklist
⭐ Suggestion

Add more wildcards to "paths" property in tsconfig.json, like dynamic directory names ($0 for example), or create a way to use JS/TS to build and return the tsconfig object, with this I can trace the workspace folder extracting all directores needed.

📃 Motivating Example

Normally i'm use only one or 2 paths in tsconfig but I had started to work with NestJS using workspaces and each new app or library need to be added into a new element

💻 Use Cases
  1. What do you want to use this for?

Any project using workspaces and having lots of sub packages

  1. What shortcomings exist with current approaches?

Today is required to declare every directory manually every time when a new app or lib are created in NestJS workspace

  1. What workarounds are you using in the meantime?

Today i need to make every change manually...

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

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

はじめの一歩

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

調査の方向性

このリクエストは tsconfig.json の paths オプションに関するものですが、コンパイラーのソースファイル、テスト、エントリーポイントのいずれも指定していません。まず既存の paths の処理と、そのモジュール解決テストを見つけ、次にサポートする置換構文と互換性の動作を定義してください。workspace 形式の paths で重複した宣言を避けられ、その動作がテストでカバーされれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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