microsoft / microsoft/TypeScript
Support Type Acquisition From Npx Shebang
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no menciona archivos, pruebas ni puntos de entrada. Empieza rastreando cómo TypeScript gestiona los shebangs de JavaScript y la adquisición automática de tipos; después, compara la búsqueda solicitada del paquete mediante npx con el comportamiento existente. Se considera terminado cuando los scripts invocados mediante npx reciben las definiciones de tipos del paquete y IntelliSense sin cambiar el comportamiento en tiempo de ejecución.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, nodejs, typescript
- Área
- developer-experience, tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100