Why does`deno run` not use `jsr:@webpod/zx`?
- Dominant language
- JavaScript
- Stars
- 45.7k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
```
~/.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/./cli`
- `DEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx/cli`
- `DEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx/.`
- `DEBUG RS - deno::worker:80 - main_module jsr:@webpod/zx`
As you can see, when using `jsr:@webpod/zx` the main module is not translated to a local file path.
In addition to that problem, the value for `process.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 of `isMain` is 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
Contributor guide
Assessment
This issue has not been assessed yet.