relaycode
Version:
A developer assistant that automates applying code changes from LLMs.
2 lines • 1.64 kB
JavaScript
;var child_process=require('child_process'),p=require('path'),logger=require('./logger'),typescript=require('./typescript');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var p__default=/*#__PURE__*/_interopDefault(p);const a=(r,s=process.cwd())=>{if(!r||r.trim()==="")return Promise.resolve({exitCode:0,stdout:"",stderr:""});const n=p__default.default.resolve(s);return new Promise(c=>{logger.logger.debug(`Executing command: ${r} in directory: ${n}`);const e=child_process.spawn(r,{cwd:n,shell:true,stdio:["ignore","pipe","pipe"]});let t="",u="";e.stdout.on("data",o=>{t+=o.toString();}),e.stderr.on("data",o=>{u+=o.toString();}),e.on("close",o=>{c({exitCode:o??1,stdout:t.trim(),stderr:u.trim()});}),e.on("error",o=>{c({exitCode:1,stdout:"",stderr:o.message});});})},b=async(r,s=process.cwd())=>{if(!r||r.trim()==="")return 0;if(r.includes("tsc")){logger.logger.debug("Detected tsc command, attempting to use TypeScript API for error counting.");try{const t=typescript.getTypeScriptErrorCount(r,s);if(t!==-1)return logger.logger.debug(`TypeScript API returned ${t} errors.`),t}catch(t){logger.logger.debug(`TypeScript API error counting threw an exception, falling back to shell execution. Error: ${t instanceof Error?t.message:String(t)}`);}logger.logger.debug("TypeScript API error counting failed or was not applicable, falling back to shell execution.");}const{exitCode:n,stderr:c}=await a(r,s);if(n===0)return 0;const e=c.match(/(\d+) error/i);return e&&e[1]?parseInt(e[1],10):1};exports.executeShellCommand=a;exports.getErrorCount=b;//# sourceMappingURL=shell.cjs.map
//# sourceMappingURL=shell.cjs.map