为什么`deno run`不使用`jsr:@webpod/zx`?
作者: tcely创建于 2026年1月8日更新于 2026年2月23日
标签bug
~/.cache $ DEBUG_ZX_SH=true zx_run 'jsr:@webpod/zx' <<<'console.log( await $({ verbose: true })echo Hello world! | xargs -t -n 1 echo )'
- install -d -m 00775 /data/data/com.termux/files/../cache/zx
- cd /data/data/com.termux/files/../cache/zx
- zx=jsr:@webpod/zx
- shift
- exec deno run --no-config --allow-read=/data/data/com.termux/files/usr/bin/bash --allow-read=/data/data/com.termux/files/files/home --allow-read=/data/data/com.termux/files/../cache --ignore-read --allow-write=/data/data/com.termux/files/../cache/zx --allow-env --allow-run --allow-sys=homedir,uid,gid,cpus -- jsr:@webpod/zx
~/.cache $ DEBUG_ZX_SH=true zx_run 'npm:zx' <<<'console.log( await $({ verbose: true })
echo Hello world! | xargs -t -n 1 echo)' - install -d -m 00775 /data/data/com.termux/files/../cache/zx
- cd /data/data/com.termux/files/../cache/zx
- zx=npm:zx
- shift
- exec deno run --no-config --allow-read=/data/data/com.termux/files/usr/bin/bash --allow-read=/data/data/com.termux/files/files/home --allow-read=/data/data/com.termux/files/../cache --ignore-read --allow-write=/data/data/com.termux/files/../cache/zx --allow-env --allow-run --allow-sys=homedir,uid,gid,cpus -- npm:zx $ echo Hello world! | xargs -t -n 1 echo echo Hello Hello echo 'world!' world! ProcessOutput { stdout: 'Hello\nworld!\n', stderr: "echo Hello\necho 'world!'\n", signal: null, exitCode: 0, duration: 124 } Only when using 'npm:zx' does the output show up. [^1] Am I doing anything wrong here? Why would it be different?
I looked into this some more. isMain returning false is the reason.
These are the valid cases it should accept from debugging deno run:
DEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx/./cliDEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx/cliDEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx/.DEBUG RS - deno::worker:80 - main_module jsr:@webpod/zxAs you can see, when usingjsr:@webpod/zxthe main module is not translated to a local file path. In addition to that problem, the value forprocess.argv[1]is constructed using the absolute path to the current working directory plus$deno$node.mjs. Which, as far as I could determine, is never actually on the filesystem. In short, the current strategy ofisMainis insufficient. https://GitHub.com/google/zx/blob/1ca92700ef5430b2119d9b8a915ba87cd9d678f3/src/cli.ts#L262-L274 https://GitHub.com/google/zx/blob/1ca92700ef5430b2119d9b8a915ba87cd9d678f3/src/cli.ts#L57-L66 [^1]: https://gist.GitHub.com/tcely/a16186fdd9e47189e31c8cd9c5fbfea1
内容来源: google/zx