microsoft / microsoft/TypeScript

Support Type Acquisition From Npx Shebang

Aperta
#35,916 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Originally filed under https://github.com/microsoft/vscode/issues/87834.

Search Terms

shebang, npx, type acquisition

Suggestion

When authoring JS scripts that are to be invoked using npx, it would be great if the typing information could be inferred from the package that npx will call.

Use Cases

I'm currently building a library, where primary use case is to be consumed as executable scripts, with npx as the shebang command (this allows for global execution without the need for prior installation). And since all of the needed functionality is automatically injected into the global scope there is no need for external references. This is intended for portability and ease of authoring.

When authoring these scripts, the desire is to leverage the typings provided by the library called by npx. The assumption here is that the toolchain would detect the npx invocation in the shebang, and load the appropriate typings (local if library is previously installed, or downloaded if not).

Examples

#!/usr/bin/npx @arcsine/nodesh
stdin
  .sort()
  .unique()
  .stdout

In the sample above, stdin is a global variable that should be picked up via intellisense, and the methods it exposes should be searchable (with the associated docs).

Considerations

Alternatively, one thought was to leverage a triple-slash directive, but that is limited as it cannot:

  • point to global node modules (without an absolute path)
  • reference ephemeral libraries as loaded by npx

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

La issue non indica file, test o punti di ingresso. Inizia tracciando la gestione degli shebang JavaScript e dell’acquisizione automatica dei tipi da parte di TypeScript, quindi confronta la ricerca del pacchetto richiesta tramite npx con il comportamento esistente. Il lavoro è completato quando gli script invocati tramite npx ricevono le definizioni dei tipi del pacchetto e IntelliSense senza modificare il comportamento a runtime.

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

Valutazione

Stack tecnologico
javascript, nodejs, typescript
Ambito
developer-experience, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.