UNPKG

just-scripts

Version:
33 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nodeExecTask = void 0; const utils_1 = require("../utils"); const just_task_1 = require("just-task"); const resolve_1 = require("just-task/lib/resolve"); const getTsNodeEnv_1 = require("../typescript/getTsNodeEnv"); /** * Create a task to execute a command in a new process. * Uses `cross-spawn` to avoid issues with spaces in arguments, but does not do any additional escaping. * * **WARNING: If the `shell` option is enabled, do not pass unsanitized user input to this task. * Any input containing shell metacharacters may be used to trigger arbitrary command execution.** */ function nodeExecTask(options) { return function () { const { spawnOptions, enableTypeScript, tsconfig, transpileOnly } = options; const tsNodeRegister = (0, resolve_1.resolveCwd)('ts-node/register'); const nodeExecPath = process.execPath; const args = [...(options.args || [])]; // Preserve the default behavior of inheriting process.env if no options are specified let env = options.env ? { ...options.env } : { ...process.env }; const isTS = enableTypeScript && tsNodeRegister; if (isTS) { args.unshift('-r', tsNodeRegister); env = { ...env, ...(0, getTsNodeEnv_1.getTsNodeEnv)(tsconfig, transpileOnly) }; } just_task_1.logger.info([`Executing${isTS ? ' [TS]' : ''}:`, nodeExecPath, ...args].join(' ')); return (0, utils_1.spawn)(nodeExecPath, args, { stdio: 'inherit', env, ...spawnOptions }); }; } exports.nodeExecTask = nodeExecTask; //# sourceMappingURL=nodeExecTask.js.map