Frontmatter for inline scripts
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- javascript, node.js, typescript
调研方向
没有列出实现文件或测试。首先将提议的格式与链接的 Node.js、Nix、Cargo 和 Python 参考资料进行比较,然后确定 frontmatter 应如何与显式选项、package.json、node.config.json 和 argv 交互;在开始实现之前,必须就语法和行为达成一致,才能标记为「done」。
由索引模型根据 Issue 内容生成。
描述
What is the problem this feature will solve?
Taking inspiration from nix, cargo, and python I would like a way for stand-alone scripts to embed configuration normally passed via package.json, node.config.json, argv, or wrapper scripts.
https://github.com/nodejs/node/issues/59565 asks to support typescript-module in extensionless files but proposals for #!/usr/bin/env node --ext mts were rejected because many systems don't support multi-word shebangs.
I don't think this limitation is exclusive to that --ext use cases, there are other options including --permission that cannot be set in a self contained script, yes you can use .env, node.config.json, or package.json but that's no-longer self contained.
This would also be an interesting integration point for package managers that could read dependencies from the frontmatter and support npm x ./script to install the script's inline dependencies.
https://nixos.wiki/wiki/Nix-shell_shebang
https://rust-lang.github.io/rfcs/3424-cargo-script.html
https://packaging.python.org/en/latest/specifications/inline-script-metadata/
What is the feature you are proposing to solve the problem?
The rough outline is for node to parse a leading comment in the main entry point and read command line arguments,
node.config, and package.json fields. The comment would only be read in the main entry point and would sit after explicit options in priority.
#!/usr/bin/env node
// ```node.config.json
// {
// "nodeOptions": { "ext": "mts" },
// "permission": {},
// }
// ```
await main(process.argv.slice(2))
async function main(args: string[]) {
console.log(args)
}
What alternatives have you considered?
Today I'll create directories with package.jsonuse .mts file extensions, or use nasty tricks to combine shell and ts into a single script
#!/bin/sh
':' // ; exec node --ext mts
// script goes here
let n: number = 1;
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 273
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nodejs/node 的其他 Issue
-
doc
难度 2/5 1-3 小时 新手友好度 65/100
-
build
难度 1/5 1 小时以内 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 1/5 1 小时以内 新手友好度 90/100
-
feature request
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
Edit: CW+ 未关闭channels:edit check:passed
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 78/100
idean3885/claude-ops-agent#521 ·
-
forespørsel 🥰 ikoner 🖼 nytt ✨
难度 2/5 1-3 小时 新手友好度 68/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
avniproject/avni-client#2135 ·
-
automated broken-link
难度 1/5 1 小时以内 新手友好度 85/100