Try the new batch of enhancements: npm i zx@8.4.0
https://www.npmjs.com/package/zx/v/8.4.0
Changes
const cwd = tmpdir()
const external = tmpdir()
await fs.outputJson(path.join(external, 'node_modules/a/package.json'), {
name: 'a',
version: '1.0.0',
type: 'module',
exports: './index.js',
})
await fs.outputFile(
path.join(external, 'node_modules/a/index.js'),
`
export const a = 'AAA'
`
)
const script = `
import {a} from 'a'
console.log(a);
`
const out = await $`zx --cwd=${cwd} --prefer-local=${external} --test <<< ${script}`
assert.equal(out.stdout, 'AAA\n')
const p = $({prefix: '', postfix: ''})`echo ${[1, '', '*', '2']}`
// before
p.cmd // `echo 1 $'*' 2`)
// after
p.cmd // `echo 1 $'' $'*' 2`)
zx script.zx # Unknown file extension "\.zx"
zx --ext=mjs script.zx # OK
const err = new Error('BrokenSpawn')
const o = await $({
nothrow: true,
spawn() {
throw err
},
})`echo foo`
o.ok // false
o.exitCode // null
o.message // BrokenSpawn...
o.cause // err