microsoft / microsoft/TypeScript
Improve module resolution using "paths" of "tsconfig.json" file
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
🔍 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
- 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, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ 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
- What do you want to use this for?
Any project using workspaces and having lots of sub packages
- 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
- What workarounds are you using in the meantime?
Today i need to make every change manually...
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
La demande concerne l’option paths de tsconfig.json, mais ne nomme aucun fichier source du compilateur, test ou point d’entrée. Commencez par localiser la gestion existante de paths et ses tests de résolution de modules, puis définissez la syntaxe de substitution prise en charge et le comportement de compatibilité. Le travail sera considéré comme terminé lorsque des paths de type workspace pourront éviter les déclarations répétées et que le comportement sera couvert par des tests.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100