fix: 构建产物添加 shebang - #22
Open
JiahaoXu10Arthur wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
npm 生成命令启动脚本(cmd-shim)时,靠读取目标文件的 shebang 判断该用哪个解释器。
dist/index.js没有 shebang,生成出来的pica-cli、pica-cli.cmd、pica-cli.ps1里就完全没有node,而是直接执行.js路径本身。Windows 会把它交给
.js的关联程序处理 —— 默认是WScript.exe(Windows 脚本宿主)。WScript 解析不了 ESM 的import,进程立刻结束。表现
npm i -g pica-cli之后运行pica-cli,立刻返回提示符,没有任何输出,看起来像“跑了但什么都没做”,很容易误判成 PATH 或权限问题。所有从 npm 全局安装的 Windows 用户都会遇到。两种 shim 的区别:
改动
rollup 的 output 加一行
banner: '#!/usr/bin/env node'。影响范围
只动
rollup.config.js,产物首行多一句 shebang。Linux / macOS 本来就靠 shebang 执行,不受影响,运行时行为无变化。