| 
28 | 28 | 
 
  | 
29 | 29 | logger = logging.getLogger(__name__)  | 
30 | 30 | 
 
  | 
31 |  | -compile_typescript_cmd = "/usr/lib/node_modules/@swc/cli/bin/swc.js --config-file /root/.ts.swcrc --filename index.ts"  | 
32 |  | - | 
33 | 31 | class Execution:  | 
34 | 32 |     def __init__(self, in_background: bool = False):  | 
35 | 33 |         self.queue = Queue[  | 
@@ -204,20 +202,29 @@ async def execute(  | 
204 | 202 |             if self.language == "typescript":  | 
205 | 203 |                 logger.info("Compiling TypeScript: %s", code)  | 
206 | 204 | 
 
  | 
207 |  | -                # call swc to compile the typescript code  | 
208 |  | -                compile_result = subprocess.run(compile_typescript_cmd.split(), input=code.encode(), capture_output=True)  | 
209 |  | - | 
210 |  | -                if compile_result.returncode != 0:  | 
211 |  | -                    logger.error("Error during TypeScript compilation: %s", compile_result.stderr.decode())  | 
 | 205 | +                # call SWC to compile the typescript code  | 
 | 206 | +                try:  | 
 | 207 | +                    compile_result = subprocess.run("swc --config-file .ts.swcrc --filename index.ts".split(), input=code.encode(), capture_output=True)  | 
 | 208 | + | 
 | 209 | +                    if compile_result.returncode != 0:  | 
 | 210 | +                        logger.error("Error during TypeScript compilation: %s", compile_result.stderr.decode())  | 
 | 211 | +                        yield Error(  | 
 | 212 | +                            name="TypeScriptCompilerError",  | 
 | 213 | +                            value=compile_result.stderr.decode(),  | 
 | 214 | +                            traceback="",  | 
 | 215 | +                        )  | 
 | 216 | +                        return  | 
 | 217 | + | 
 | 218 | +                    code = compile_result.stdout.decode()  | 
 | 219 | +                except Exception as e:  | 
 | 220 | +                    logger.error("Error starting SWC process: %s", e)  | 
212 | 221 |                     yield Error(  | 
213 | 222 |                         name="TypeScriptCompilerError",  | 
214 |  | -                        value=compile_result.stderr.decode(),  | 
 | 223 | +                        value=str(e),  | 
215 | 224 |                         traceback="",  | 
216 | 225 |                     )  | 
217 | 226 |                     return  | 
218 | 227 | 
 
  | 
219 |  | -                code = compile_result.stdout.decode()  | 
220 |  | - | 
221 | 228 |             logger.info(code)  | 
222 | 229 |             request = self._get_execute_request(message_id, code, False)  | 
223 | 230 | 
 
  | 
 | 
0 commit comments