Support TypeScript executable without extension when flag is set
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 没有指出任何实现文件、入口点或测试,因此请先定位 Node 的命令行标志处理和 TypeScript 的执行行为。验证在使用 --experimental-strip-types 时无扩展名可执行文件的预期行为,并确认现有的基于扩展名的行为保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- nodejs, typescript
- 领域
- cli
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100