microsoft / microsoft/TypeScript

`--showConfig` doesn't resolve `paths`

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

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

Bug Domain: Module Resolution Help Wanted
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

"showConfig", "paths", "extends", "relative"

🕗 Version & Regression Information

v5.2.2 (no regression AFAIK)

⏯ Playground Link

https://stackblitz.com/edit/stackblitz-starters-gst2kr?file=tsconfig.json

Commands:

  • npm run config -> tsc --showConfig

  • npm run trace -> tsc --noEmit --traceResolution
    Use this to confirm that foo does resolve to ./this-path-should-be-in-config/bar.ts

💻 Code

No response

🙁 Actual behavior

Given a tsconfig that extends another config:

./tsconfig.json

{
  "extends": "./this-path-should-be-in-config/tsconfig.json"
}

./this-path-should-be-in-config/tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "foo": ["./bar"]
    }
  }
}

The resolved tsconfig (via tsc --showConfig) doesn't reflect that ./bar is actually resolved relative to ./this-path-should-be-in-config/tsconfig.json:

{
    "compilerOptions": {
        "paths": {
            "foo": [
                "./bar"
            ]
        }
    },
    "files": [
        "./file.ts"
    ]
}
🙂 Expected behavior

For the config to include the relevant information (e.g. the relative path):

{
    "compilerOptions": {
        "paths": {
            "foo": [
                "./this-path-should-be-in-config/bar"
            ]
        }
    },
    "files": [
        "./file.ts"
    ]
}

Currently, it seems to indicate that paths is resolved relative to the CWD. When it's in fact relative to this-path-should-be-in-config.

It's also impossible for a custom TypeScript paths resolver (e.g. https://github.com/privatenumber/get-tsconfig) to correctly resolve the paths aliases based on this output.

Additional information about the issue

From https://github.com/privatenumber/get-tsconfig/pull/62

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

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

はじめの一歩

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

調査の方向性

リンクされた StackBlitz の再現環境から始め、npm run config (tsc --showConfig) と npm run trace (tsc --noEmit --traceResolution) を実行します。2 つの tsconfig.json ファイルにある継承された paths の値を、トレースに表示される解決済みモジュールパスと比較します。--showConfig が拡張された設定ファイルからの相対パスを報告し、示されているエイリアス解決を維持していれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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