UNPKG

create-nx-workspace

Version:

Smart Repos · Fast Builds

76 lines (75 loc) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.spawnAndWait = spawnAndWait; exports.execAndWait = execAndWait; const child_process_1 = require("child_process"); const fs_1 = require("fs"); const path_1 = require("path"); const error_utils_1 = require("./error-utils"); /** * Use spawn only for interactive shells */ function spawnAndWait(command, args, cwd) { return new Promise((res, rej) => { // Combine command and args into a single string to avoid DEP0190 warning // (passing args with shell: true is deprecated) const fullCommand = [command, ...args] .map((arg) => (arg.includes(' ') ? `"${arg}"` : arg)) .join(' '); const childProcess = (0, child_process_1.spawn)(fullCommand, { cwd, stdio: 'inherit', env: { ...process.env, NX_DAEMON: 'false', // This is the same environment variable that ESLint uses to determine if it should use a flat config. // Default to true for all new workspaces. ESLINT_USE_FLAT_CONFIG: process.env.ESLINT_USE_FLAT_CONFIG ?? 'true', }, shell: true, windowsHide: false, }); childProcess.on('exit', (code, signal) => { if (code === null) code = signalToCode(signal); if (code !== 0) { rej({ code: code }); } else { res({ code: 0 }); } }); }); } function execAndWait(command, cwd, silenceErrors = false) { return new Promise((res, rej) => { (0, child_process_1.exec)(command, { cwd, env: { ...process.env, NX_DAEMON: 'false' }, windowsHide: false }, (error, stdout, stderr) => { if (error) { if (silenceErrors) { rej(); } else { const logFile = (0, path_1.join)(cwd, 'error.log'); (0, fs_1.writeFileSync)(logFile, `${stdout}\n${stderr}`); const message = stderr && stderr.trim().length ? stderr : stdout; rej(new error_utils_1.CreateNxWorkspaceError(message, error.code, logFile)); } } else { res({ code: 0, stdout }); } }); }); } function signalToCode(signal) { switch (signal) { case 'SIGHUP': return 128 + 1; case 'SIGINT': return 128 + 2; case 'SIGTERM': return 128 + 15; default: return 128; } }