UNPKG

teen_process

Version:
47 lines 1.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatEnoent = formatEnoent; const node_path_1 = __importDefault(require("node:path")); const promises_1 = __importDefault(require("node:fs/promises")); /** * Enhances ENOENT errors from spawn with descriptive messages. * * This is an internal helper that mutates the error object to provide context about: * - Invalid working directory paths * - Missing executables in PATH * * @param error - The original ENOENT error from spawn * @param cmd - The command that was attempted to execute * @param cwd - The working directory used (if any) * @returns The same error object with an enhanced message * * @internal */ async function formatEnoent(error, cmd, cwd) { if (cwd) { try { const stat = await promises_1.default.stat(cwd); if (!stat.isDirectory()) { error.message = `The working directory '${cwd}' of '${cmd}' is not a valid folder path`; return error; } } catch (e) { const err = e; if (err.code === 'ENOENT') { error.message = `The working directory '${cwd}' of '${cmd}' does not exist`; return error; } } } const curDir = node_path_1.default.resolve(cwd ?? process.cwd()); const pathMsg = process.env.PATH ?? 'which is not defined for the process'; error.message = `'${cmd}' executable is not found neither in the process working folder (${curDir}) ` + `nor in any folders specified in the PATH environment variable (${pathMsg})`; return error; } //# sourceMappingURL=helpers.js.map