Support TypeScript executable without extension when flag is set
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
What is the problem this feature will solve?
When I write an executable utility like build-game, I have to expose the implementation detail of the language it's written in, like build-game.ts.
#!/usr/bin/env node
// This file is named `build-game` not `build-game.ts`. Only plain JavaScript is allowed.
const foo: number = 1 // Error: TypeScript encountered.
console.log(foo)
/home/user/bin/build-game:3
const foo: number = 1
^^^
SyntaxError: Missing initializer in const declaration
at wrapSafe (node:internal/modules/cjs/loader:1624:18)
at Module._compile (node:internal/modules/cjs/loader:1666:20)
at Object..js (node:internal/modules/cjs/loader:1824:10)
at Module.load (node:internal/modules/cjs/loader:1427:32)
at Module._load (node:internal/modules/cjs/loader:1250:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:152:5)
at node:internal/main/run_main_module:33:47
Node.js v24.4.1
What is the feature you are proposing to solve the problem?
When --experimental-strip-types is set (or add a new flag), force TypeScript evaluation. This will allow a script to encapsulate all interpreter detail.
#!/usr/bin/env -S node --experimental-strip-types
// This file is named `build-game` not `build-game.ts`. TypeScript is allowed
// because the `--experimental-strip-types` flag was passed.
const foo: number = 1
console.log(foo)
What alternatives have you considered?
If the executable is in an NPM package, I can just alias it in the package.json. If the executable is in my ~/bin, I can just shell alias it. However, these are both limited and really prevent me from sharing scripts with nice names that work everywhere.
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 các tệp triển khai, điểm vào hoặc bài kiểm thử nào, vì vậy hãy bắt đầu bằng cách xác định cơ chế xử lý các cờ dòng lệnh của Node và hành vi thực thi của TypeScript. Xác minh hành vi mong muốn đối với một tệp thực thi không có phần mở rộng khi dùng --experimental-strip-types, bao gồm cả việc hành vi hiện có dựa trên phần mở rộng vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- nodejs, typescript
- Lĩnh vực
- cli
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100