Menu

Your Script's Shape Decides Which Exit Code You Get
πŸ“°

Your Script's Shape Decides Which Exit Code You Get

DEV Community: cicdΒ·Mustafa ERBAYΒ·15 days ago
#sWp8qXjH
#devtocicd#devto#dev#node#script
Long article (3425 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Since Node 22 you can run the scripts in your package.json without going

through npm at all: node --run build . The pitch is one word β€” speed. Node's own

documentation does not hide it: the implementation is "intentionally more

limited, in order to focus on top performance for the most common use cases".

Two of those limitations are spelled out in the docs. Two differences that turned

up in today's measurements are not in the docs at all, and the second one is the

surprise: under node --run , the shape of your script decides which exit code

the same death gets. A script that kills itself with SIGKILL returns 0 when it

is a single command and 1 once a true && is put in front of it. Under npm run

that same death is 137 either way β€” three codes in total, two of them separated

by nothing but syntax.

The cause is a layer neither side documents: node --run hands the command to a

/bin/sh , and whether that shell survives decides the exit code.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.