microsoft / microsoft/TypeScript
Support Type Acquisition From Npx Shebang
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Dateien, Tests oder Einstiegspunkte. Beginne damit, TypeScripts Verarbeitung von JavaScript-Shebangs und die automatische Typenerfassung nachzuverfolgen, und vergleiche dann die angeforderte npx-Paketsuche mit dem bestehenden Verhalten. Als abgeschlossen gilt die Aufgabe, wenn über npx aufgerufene Skripte die Typdefinitionen des Pakets und IntelliSense erhalten, ohne das Laufzeitverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, nodejs, typescript
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100