Vscode-vsce: Show `vscode:prepublish` script output even if it failed

Created on 17 Apr 2020  路  6Comments  路  Source: microsoft/vscode-vsce

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.

bug help wanted

All 6 comments

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

https://github.com/microsoft/vscode-vsce/blob/fbebf951823f28c46abf351b7981bf094f3e36a9/src/package.ts#L932-L934

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixfbecker picture felixfbecker  路  6Comments

mlewand picture mlewand  路  3Comments

shanalikhan picture shanalikhan  路  6Comments

jkeech picture jkeech  路  4Comments

muuvmuuv picture muuvmuuv  路  6Comments