nve
Version:
Run any command on specific Node.js versions
47 lines (29 loc) • 792 B
JavaScript
import{stderr}from"node:process";
import chalk from"chalk";
export const handleFault=(error)=>{
if(shouldPrintHelp(error)){
error.message+=`\n${SHORT_USAGE}`
}
};
const shouldPrintHelp=(error)=>
error instanceof Error&&
typeof error.message==="string"&&
error.message.includes("Missing version");
export const printInvalidCommand=(code,exitCode)=>{
if(!isInvalidComment(code,exitCode)){
return
}
stderr.write(`${SHORT_USAGE}\n`)
};
const isInvalidComment=(code,exitCode)=>
code==="ENOENT"||exitCode===BASH_COMMAND_CODE;
const BASH_COMMAND_CODE=127;
const SHORT_USAGE=`
${chalk.red("Invalid input syntax.")}
It should be:
nve [OPTIONS...] VERSION,... [COMMAND] [ARGS...]
Examples:
nve 8 node file.js
nve 8 npm test
nve 8,9,10 npm test
nve --no-progress 8 npm test`;