microsoft / microsoft/TypeScript
Support Type Acquisition From Npx Shebang
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Issue không nêu tên tệp, bài kiểm thử hoặc điểm vào nào. Hãy bắt đầu bằng cách theo dõi cách TypeScript xử lý shebang của JavaScript và việc tự động thu nhận kiểu, sau đó so sánh việc tra cứu package bằng npx được yêu cầu với hành vi hiện có. Hoàn thành khi các script được gọi bằng npx nhận được thông tin kiểu của package và IntelliSense mà không thay đổi hành vi khi chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, nodejs, typescript
- Lĩnh vực
- developer-experience, tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100