Support Type Acquisition From Npx Shebang

Ouverte
#35,916 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
25/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
javascript, nodejs, typescript

Piste de recherche

L’issue ne mentionne aucun fichier, test ou point d’entrée. Commencez par suivre la gestion par TypeScript des shebangs JavaScript et de l’acquisition automatique de types, puis comparez la recherche de package demandée via npx avec le comportement existant. Le travail est terminé lorsque les scripts invoqués par npx reçoivent les définitions de types du package et IntelliSense sans modifier le comportement à l’exécution.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Awaiting More Feedback Suggestion

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.
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de microsoft/TypeScript

Toutes les issues de microsoft/TypeScript

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.