microsoft / microsoft/TypeScript
Support Type Acquisition From Npx Shebang
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue にはファイル、テスト、エントリーポイントが記載されていません。まず、TypeScript による JavaScript の shebang と自動型取得の処理を追跡し、次に、要求されている npx パッケージ検索を既存の動作と比較してください。npx で呼び出されたスクリプトが、実行時の動作を変更せずにパッケージの型定義と IntelliSense を受け取れるようになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, nodejs, typescript
- 領域
- developer-experience, tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100