Skip to content

Commit abac1f7

Browse files
committed
minor nits by @0div
1 parent 5c0db79 commit abac1f7

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

template/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RUN R -e "IRkernel::installspec(user = FALSE, name = 'r', displayname = 'R')"
3131
RUN npm install -g --unsafe-perm ijavascript
3232
RUN ijsinstall --install=global
3333

34-
## TypeScript support
34+
## TypeScript compiler
3535
RUN npm install -g @swc/cli @swc/core
3636
COPY .ts.swcrc /root/.ts.swcrc
3737

template/server/messaging.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
logger = logging.getLogger(__name__)
3030

31-
compile_typescript_cmd = "/usr/lib/node_modules/@swc/cli/bin/swc.js --config-file /root/.ts.swcrc --filename index.ts"
32-
3331
class Execution:
3432
def __init__(self, in_background: bool = False):
3533
self.queue = Queue[
@@ -204,20 +202,29 @@ async def execute(
204202
if self.language == "typescript":
205203
logger.info("Compiling TypeScript: %s", code)
206204

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)
212221
yield Error(
213222
name="TypeScriptCompilerError",
214-
value=compile_result.stderr.decode(),
223+
value=str(e),
215224
traceback="",
216225
)
217226
return
218227

219-
code = compile_result.stdout.decode()
220-
221228
logger.info(code)
222229
request = self._get_execute_request(message_id, code, False)
223230

template/test.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ RUN pip install --no-cache-dir -r requirements.txt && ipython kernel install --n
2626
RUN npm install -g --unsafe-perm ijavascript
2727
RUN ijsinstall --install=global
2828

29-
## TypeScript support
29+
## TypeScript compiler
3030
RUN npm install -g @swc/cli @swc/core
31-
COPY ./template/.ts.swcrc /root/.ts.swcrc
31+
COPY ./template/.ts.swcrc $SERVER_PATH/.ts.swcrc
3232

3333
# Deno Kernel
3434
COPY --from=denoland/deno:bin-2.0.4 /deno /usr/bin/deno

0 commit comments

Comments
 (0)