Skip to content

Commit

Permalink
refactor: rewrote js loader to uniform with the others
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Jan 18, 2025
1 parent efa8aaf commit 9291287
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
9 changes: 6 additions & 3 deletions dyana/loaders/js/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM node:23-slim
FROM python:3.12-slim

RUN apt-get update && apt-get install -y nodejs npm

WORKDIR /app

COPY main.js .
COPY dyana.py .
COPY main.py .

ARG EXTRA_REQUIREMENTS
RUN if [ -n "$EXTRA_REQUIREMENTS" ]; then npm install $EXTRA_REQUIREMENTS; fi

ENTRYPOINT ["node", "main.js"]
ENTRYPOINT ["python3", "-W", "ignore", "main.py"]
2 changes: 0 additions & 2 deletions dyana/loaders/js/Makefile

This file was deleted.

32 changes: 0 additions & 32 deletions dyana/loaders/js/main.js

This file was deleted.

27 changes: 27 additions & 0 deletions dyana/loaders/js/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import argparse
import json
import os
import subprocess

from dyana import Profiler # type: ignore[attr-defined]

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run an Javascript file")
parser.add_argument("--script", help="Path to Javascript file", required=True)
args = parser.parse_args()
profiler: Profiler = Profiler()

if not os.path.exists(args.script):
profiler.track_error("js", "Javascript file not found")
else:
try:
result = subprocess.run(["node", args.script], capture_output=True, text=True)

profiler.track_memory("after_execution")
profiler.track("exit_code", result.returncode)
profiler.track("stdout", result.stdout)
profiler.track("stderr", result.stderr)
except Exception as e:
profiler.track_error("js", str(e))

print(json.dumps(profiler.as_dict()))

0 comments on commit 9291287

Please sign in to comment.