microsoft / microsoft/TypeScript
`--explainFiles` differentiate `import type ...` vs `import`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Suggestion
explainFiles "import type"
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
I would like the --explainFiles behavior to differentiate between import type and import runtime imports in its printout.
📃 Motivating Example
c:/project/src/server-side/contract
Imported Types via '../server-side/contract' from file 'c:/project/src/client-side/app.tsx'
^^^^^
💻 Use Cases
I am looking for suspected non-import type ... imports that are poisoning our build, bleeding code from non-client files ultimately into client bundles (before maybe tree-shaking them out again). At best, this impacts build performance. I know that better code organization could help avoid confusing import chains and improper imports - that's what I'm trying to untangle it for.
I am using the output from --explainFiles to recognize the various patterns and reconstitute a dependency graph:
const targetPattern = /^(?!\s)(.*)/;
const importedViaPattern = /^ Imported via (['"])(.*)\1 from file '([^']*)'/;
const includePattern = /^ Matched by include pattern (['"])(.*)\1 in '([^']*)'/;
const referencedViaPattern = /^ Referenced via (['"])(.*)\1 from file '([^']*)'/;
const libReferencesPattern = /^ Library referenced via (['"])(.*)\1 from file '([^']*)'/;
const typeLibraryPattern = /^ Type library referenced via (['"])(.*)\1 from file '([^']*)'/;
const fileRedirectsPattern = /^ File redirects to file '([^']*)'/
const compilerOptionsPattern = /^ Library '(.*)' specified in compilerOptions/;
const filesPattern = /^ Part of 'files' list in/;
const implicitTypeLibraryPattern = /^ Entry point for implicit type library/;
There seems to be no difference in the output between an import and an import type so my dependency graph can't cull the type imports that won't be emitted to the next stage in the build pipeline.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal punto di ingresso --explainFiles e traccia il modo in cui i file importati sono rappresentati nel suo output; l’issue non fornisce alcun file sorgente né alcun percorso di test. Il lavoro è completato quando l’output distingue import type da un import a runtime, in modo che i consumer possano escludere le dipendenze di soli tipi dal loro grafo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100