#!/usr/bin/env node 'use strict'; const inspectPattern = /^(--inspect|--inspect-brk)(=\d+)?$/; const inspectArg = process.argv.find((argument) => { return inspectPattern.test(argument); }); if (process.env.NODE_DEBUG_OPTION || inspectArg) { const ChildProcess = require('child_process'); const node = process.argv[0]; const lab = process.argv[1]; const args = []; if (process.env.NODE_DEBUG_OPTION) { // WebStorm debugger args.push.apply(args, process.env.NODE_DEBUG_OPTION.split(' ')); delete process.env.NODE_DEBUG_OPTION; } else { // V8 inspector args.push(inspectArg); args.push('--debug-brk'); } args.push(lab); // Remove node, lab, and the --inspect that might have been provided in the options args.push.apply(args, process.argv.slice(2).filter((argument) => !inspectPattern.test(argument))); const options = { stdio: 'inherit' }; const childLab = ChildProcess.spawn( node, args, options ); childLab.on('close', (code) => { process.exit(code); }); return; } const main = async () => { let { code } = await require('../lib/cli').run(); if (typeof code !== 'number') { code = code[Object.keys(code)[0]]; } process.exit(code); }; main();