From 1dd5bf6f531cec3a29259e373926483f5584375a Mon Sep 17 00:00:00 2001 From: gin0606 <795891+gin0606@users.noreply.github.com> Date: Fri, 6 Feb 2026 15:45:22 +0900 Subject: [PATCH] fix(cli): prevent double extension in temp file for stdin markdown with --ext .md Pass EXT (.mjs) explicitly when creating the temp file after markdown transformation to avoid falling back to argv.ext, which caused the temp file to be named zx.md.md instead of zx.md.mjs. --- build/cli.cjs | 2 +- src/cli.ts | 2 +- test/cli.test.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build/cli.cjs b/build/cli.cjs index 2a9b043bf9..b4916110d8 100755 --- a/build/cli.cjs +++ b/build/cli.cjs @@ -304,7 +304,7 @@ function readScript() { } if (ext === ".md") { script = transformMarkdown(script); - tempPath = getFilepath(dir, base); + tempPath = getFilepath(dir, base, EXT); } if (argSlice) (0, import_index.updateArgv)(argv._.slice(argSlice)); return { script, scriptPath, tempPath }; diff --git a/src/cli.ts b/src/cli.ts index 5b8783c7a0..cf28081493 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -232,7 +232,7 @@ async function readScript() { } if (ext === '.md') { script = transformMarkdown(script) - tempPath = getFilepath(dir, base) + tempPath = getFilepath(dir, base, EXT) } if (argSlice) updateArgv(argv._.slice(argSlice)) diff --git a/test/cli.test.js b/test/cli.test.js index 936325d115..fabc7a6beb 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -347,6 +347,12 @@ console.log(a); assert.ok(p.stdout.includes('Hello, world!')) }) + test('markdown scripts from stdin with --ext .md', async () => { + const md = '# Test\n\n```js\necho("md-stdin-ok")\n```\n' + const p = await $`node build/cli.js --ext='.md' <<< ${md}` + assert.match(p.stdout, /md-stdin-ok/) + }) + test('exceptions are caught', async () => { const out1 = await $`node build/cli.js <<<${'await $`wtf`'}`.nothrow() const out2 = await $`node build/cli.js <<<'throw 42'`.nothrow()