microsoft / microsoft/TypeScript

Add some way to specify a different output shebang

Aperta
#45,319 3 commenti 10 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

🔍 Search Terms

  • shebang, hashbang, javascript, compiled shebang, #!/usr/bin/env node

✅ 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

TypeScript should offer some way to specify a shebang to be added to the top of the compiled JS file that is different to the one specified (or not) in the TS source.

For example, this TypeScript file:

#!/usr/bin/env tsx
//->#!/usr/bin/env node
...

would become:

#!/usr/bin/env node
...

📃 Motivating Example

Currently, if you want to create a file that should be an executable when compiled, you must place #!/usr/bin/env node in the TypeScript file if you want that at the top of the JavaScript file.

This is not ideal as the TypeScript file is then therefore classified as a Node executable / JavaScript file instead of TypeScript source code. It renders the TS shebang completely misleading as it should never be run with that executable.

💻 Use Cases

The main use case is creating a Node CLI application in TypeScript. CLIs must be executables, so the outputted JS file must have #!/usr/bin/env node, which must also be found in the TS file, misclassifying it.

Extensions are just a suggestion; shebangs (usually) mean "execute me only with this", which should guarantee a language match. TS is forcing misuse of the shebang which should be changed.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

L’issue non indica file, test o punti di ingresso. Inizia tracciando il modo in cui TypeScript gestisce gli shebang quando produce JavaScript e confronta gli esempi richiesti di TypeScript e dell’output. Il lavoro sarebbe completato quando fosse definito un meccanismo concordato per selezionare uno shebang di output diverso senza modificare il comportamento esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
node.js, typescript
Ambito
cli, compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.