Commit d0393ba
Changed files (2)
src
test
src/cli.ts
@@ -56,7 +56,7 @@ await (async function main() {
get: stdin,
})
let script = (argv.eval || argv.e).toString()
- await runScript(addLogOnLastLine(script))
+ await runScript(script)
return (process.exitCode = 0)
}
let firstArg = process.argv.slice(2).find((a) => !a.startsWith('--'))
@@ -91,18 +91,6 @@ await (async function main() {
process.exitCode = 1
})
-function addLogOnLastLine(script: string) {
- // We don't want to bring a JS parser as a dependency of zx,
- // so the next code should work for most of the cases.
- const lines = script.trim().split('\n')
- let out = lines.slice(0, -1).join('\n') + '\n'
- const lastLine = ';' + lines.at(-1)
- const statements = lastLine.split(';')
- out += statements.slice(0, -1).join(';') + ';'
- out += `console.log(${statements.at(-1)})`
- return out
-}
-
async function runScript(script: string) {
let filepath = join(tmpdir(), randomId() + '.mjs')
await fs.mkdtemp(filepath)
test/cli.test.js
@@ -121,29 +121,19 @@ test('exceptions are caught', async () => {
})
test('eval works', async () => {
- assert.is((await $`node build/cli.js --eval '42'`).stdout, '42\n')
- assert.is((await $`node build/cli.js -e='69'`).stdout, '69\n')
+ assert.is((await $`node build/cli.js --eval 'echo(42)'`).stdout, '42\n')
+ assert.is((await $`node build/cli.js -e='echo(69)'`).stdout, '69\n')
})
test('eval works with stdin', async () => {
let { stdout } =
- await $`printf "Hello world" | node build/cli.js --eval='stdin'`
+ await $`printf "Hello world" | node build/cli.js --eval='echo(stdin)'`
assert.is(stdout, 'Hello world\n')
})
test('eval works with async stdin', async () => {
- let p = $`(printf foo; sleep 0.1; printf bar) | FX_ASYNC_STDIN=true node build/cli.js --eval 'await stdin'`
+ let p = $`(printf foo; sleep 0.1; printf bar) | FX_ASYNC_STDIN=true node build/cli.js --eval 'echo(await stdin)'`
assert.is((await p).stdout, 'foobar\n')
})
-test('eval works with newlines', async () => {
- let p = $`node build/cli.js -e 'console.log(1)\nawait 2'`
- assert.is((await p).stdout, '1\n2\n')
-})
-
-test('eval works with semicolon', async () => {
- let p = $`node build/cli.js -e 'console.log(1); await 2'`
- assert.is((await p).stdout, '1\n2\n')
-})
-
test.run()