修复 npm link 后 wanman 静默退出#8
Open
crazygit 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 link本地安装@wanman/cli后,执行wanman或wanman --help会静默退出,退出码为 0 但没有任何输出。根因是 CLI 入口的
isDirectCliExecution()只比较process.argv[1]和import.meta.url对应的普通解析路径。npm link暴露的 bin 是 symlink,process.argv[1]指向全局 bin 链接路径,而import.meta.url指向真实的dist/index.js路径,两者字符串不相等,导致入口没有调用run()。变更
fs.realpathSync()解析 symlink 后比较真实路径。npm link这类全局 bin 链接执行方式。验证
pnpm --filter @wanman/cli typecheckpnpm --filter @wanman/cli test -- src/index.test.tspnpm --filter @wanman/cli testwanman --help可以正常输出帮助文本