Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Fixed Short circuiting of chained commands doesn't work with npm scripts

Nov
4
0
Using TCC/LE 14.00.6 x64, commands chained with && in npm scripts do not short circuit, e.g. a nonzero exit code does not stop the next command from running.

For example in a package.json:

{
scripts: {
pretest: "eslint ./src && npm run build",
test: "mocha ./test"
}
}

Running "npm test" from a normal DOS shell, if "eslint ./src" fails, then the next command will not run. Under TCC, however, the exit codes seem to be ignored, and every step runs to completion regardless of outcome.

I tried to reproduce this without using npm scripts - e.g. if I just create a simple node.js app that exists with code zero, and do:

> node app1 && node app2

then it works as expected. So it has something to do with the way npm runs scripts -- in that I believe it launches a new shell instance for the script, and maybe this causes the exit code to get lost? But I can't blame npm since this works fine with a regular cmd shell.

 
More information: this actually has do with batch files and not npm scripts. This repository demonstrates the issue.

https://github.com/jamietre/tccle-issue

The wrapper that npm creates for so-called "global" modules (which are really command line applications) looks like this;

@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "exit1.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "exit1.js" %*
)

Apparently the exit code returned from within the conditionals (or maybe just any batch file, not sure) is not returned to the consumer.

In the repository above I have two scripts "exit1.cmd" and "exit0.cmd" which do what you'd expect using the construct above. This:

> exit1 && exit0

returns:

This process exits with code 1
This process exits with code 0


running under TCC/LE. In a normal dos shell it returns

This process exits with code 1

as expected.
 
Back
Top