microsoft / microsoft/TypeScript

Set as executable files that are intended to be binaries

未关闭
#37,583 13 条评论 15 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

Search Terms

  • mode
  • binary
  • executable
  • package.json bin

Suggestion

Currently, the TypeScript compiler always generates files with the 644 mode. But some files are meant to be executable: they may start with #!/usr/bin/env node; they may be marked as bin in package.json; they may have an executable mode set on the .ts source; and so forth.

It’d be great if the TypeScript compiler would take any of the hints I mentioned above, figure that the file should be executable, and create the .js as so.

At least the TypeScript compiler doesn’t change the mode of existing .js files when overwriting them, so I can chmod once, and as long as never delete the file, it’ll have the right mode.

Use Cases

This is mostly for development and running the binary from the command-line directly. Once you install the package, npm puts the binary in the node_modules/.bin folder, npx picks it up, and all is good.

Examples

You’re working on a project that should provide a binary: src/my-binary.ts. You do one of the things I mentioned to indicate that the file should be executable. You run tsc, and the generated file at lib/my-binary.js is marked as +x. Then you can call the binary with lib/my-binary.js from the command-line and it works.

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从将 src/my-binary.ts 输出为 lib/my-binary.js 的 tsc 流程开始,然后调查当前如何选择输出文件的模式。完成的标准是定义并实现一条受支持的规则来识别预期的二进制文件,并验证生成的 JavaScript 可执行,同时不改变现有行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。