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()