microsoft / microsoft/TypeScript

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

Offen
#60,133 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔍 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...

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Die Anfrage betrifft die Option paths in tsconfig.json, nennt aber keine Compiler-Quelldatei, keinen Test und keinen Einstiegspunkt. Beginne damit, die bestehende Behandlung von paths und ihre Tests zur Modulauflösung zu finden, und definiere dann die unterstützte Substitutionssyntax und das Kompatibilitätsverhalten. Als erledigt gilt die Aufgabe, wenn Pfade im Workspace-Stil wiederholte Deklarationen vermeiden können und das Verhalten durch Tests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.