A simple script like echo foobar prints this:
> npx vsce package
npx: installed 67 in 4.988s
Executing prepublish script 'npm run vscode:prepublish'...
> [email protected] vscode:prepublish /home/iliazeus/Repositories/sample-extension
> echo foobar
foobar
DONE Packaged: /home/iliazeus/Repositories/sample-extension/sample-extension-0.0.1.vsix (5 files, 2.04KB)
But if i change it to fail (echo foobar && exit 1), it prints this:
> npx vsce package
npx: installed 67 in 4.731s
Executing prepublish script 'npm run vscode:prepublish'...
ERROR Command failed: npm run vscode:prepublish
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] vscode:prepublish: `echo foobar && exit 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] vscode:prepublish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/iliazeus/.npm/_logs/2020-04-17T07_44_46_912Z-debug.log
Notice that foobar is missing from the second output.
It makes it hard, for example, to debug prepublish script errors running in a CI pipeline.
What does npm run vscode:prepublish when you have that echo foobar && exit 1 sample?
iliazeus@iliazeus:~/Repositories/sample-extension/ > npm run vscode:prepublish
> [email protected] vscode:prepublish /home/iliazeus/Repositories/sample-extension
> echo foobar && exit 1
foobar
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] vscode:prepublish: `echo foobar && exit 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] vscode:prepublish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/iliazeus/.npm/_logs/2020-04-17T08_12_41_892Z-debug.log
Versions of npm and vsce:
iliazeus@iliazeus:~/Repositories/sample-extension/ > npx vsce --version
1.75.0
iliazeus@iliazeus:~/Repositories/sample-extension/ > npm --version
6.14.4
We await exec, capturing the output, and only then write it out. That means that if exec throws, the output is never getting written.
The quirk about node's child_process.exec() is that it can call the callback with _both_ an error and a result (stdout/stderr).
The workaround is actually covered in the denodeify docs:
https://www.npmjs.com/package/denodeify#advanced-usage
I will try and submit a PR to hopefully fix this.