nfischer / shelljs-transpiler

:shell: Easily transpile Bash to ShellJS
https://nfischer.github.io/shelljs-transpiler/
MIT License
74 stars 8 forks source link

JS `error()` gives string whereas SH `$?` gives int #45

Open sam-maverick opened 6 months ago

sam-maverick commented 6 months ago

Input (bash) code

some command
RESULT=$?
if [ $RESULT != 0 ]; then
    echo "Aborting on $RESULT, command failed:"
    exit $RESULT
fi

Expected output ShellJS (JavaScript) code

exec('some command');
env.RESULT = (error()=='null' ? 0 : 1);
if (env.RESULT !== 0) {
  echo('Aborting on ' + env.RESULT + ', command failed:');
  exit(env.RESULT);
}

Actual output ShellJS (JavaScript) code

exec('some command');
env.RESULT = error();
if (env.RESULT !== 0) {
  echo('Aborting on ' + env.RESULT + ', command failed:');
  exit(env.RESULT);
}
nfischer commented 6 months ago

This will be supported in shell.errorCode(). That will be in the next shelljs release when I get around to it.

nfischer commented 6 months ago

I'll keep this open in case someone wants to update the transpiler to use the new API when it's available.

sam-maverick commented 6 months ago

Thanks for the feedback!