~/.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.
|
export function isMain( |
|
metaurl: string = import.meta.url, |
|
scriptpath: string = process.argv[1] |
|
): boolean { |
|
if (metaurl.startsWith('file:')) { |
|
const modulePath = url.fileURLToPath(metaurl).replace(/\.\w+$/, '') |
|
const mainPath = fs.realpathSync(scriptpath).replace(/\.\w+$/, '') |
|
return mainPath === modulePath |
|
} |
|
|
|
return false |
|
} |
|
|
|
isMain() && |
|
main().catch((err) => { |
|
if (err instanceof ProcessOutput) { |
|
console.error('Error:', err.message) |
|
} else { |
|
console.error(err) |
|
} |
|
process.exitCode = 1 |
|
}) |
|
|
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.
isMainreturningfalseis 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 using
jsr:@webpod/zxthe 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
isMainis insufficient.zx/src/cli.ts
Lines 262 to 274 in 1ca9270
zx/src/cli.ts
Lines 57 to 66 in 1ca9270
Footnotes
https://gist.github.com/tcely/a16186fdd9e47189e31c8cd9c5fbfea1 ↩