UNPKG

@kcws/lintstaged-config

Version:
22 lines 844 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommand = void 0; const node_child_process_1 = require("node:child_process"); /** * Find command on the system path, and return the absolute path to the command; * Otherwise, return input name and let the system handle if error occurred. * * @param name - commandline name * @returns the absolute path to the command * * @beta */ const getCommand = (name) => { // Remove spaces and symbols from input const _name = name.replaceAll(/[ !#$%&*+@^]/g, ""); const checking = ["command", "-v", _name].join(" "); const output = (0, node_child_process_1.spawnSync)(checking, { shell: true, encoding: "utf8" }); return output.status === 0 ? output.stdout.trim() : name; }; exports.getCommand = getCommand; //# sourceMappingURL=cmd.js.map