Skip to content

Added TypeScript support to the code interpreter #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 2, 2025

Conversation

mishushakov
Copy link
Member

  • Adds TypeScript support with SWC pre-compilation step
  • Bump Node v20
  • This does not add: top-level async/await, ES Modules

@mishushakov mishushakov added the feature New feature or request label Apr 25, 2025
@mishushakov mishushakov self-assigned this Apr 25, 2025
Copy link

linear bot commented Apr 25, 2025

Copy link
Contributor

@0div 0div left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty neat compiler, some questions/considerations:

  • it seems like it accepts different module import types and targets most useful ECMAScripts, would it be possible/make sense to make it parameterizable from the SDK request?
  • what's the resource footprint of calling this on each code execution? do you have any js vs ts benchmark test results?
  • how do compilation errors look like to the end user?
  • did you check if there's a way to run swc as a server of sorts, similar to how it can watch? that way we do not need to create a process each time?

@mishushakov
Copy link
Member Author

hey

  • the problem is that the ijavascript kernel only supports commonjs format, so if you try loading ES Module or any other format, the compiler should throw an error
  • here's my benchmark code
node_modules/@swc/cli/bin/swc.js --config-file .ts.swcrc --filename index.ts  0.06s user 0.02s system 99% cpu 0.084 total

script:

const a: number = 1;
console.log(a)
  • errors are regular ExecutionError
Execution {
  results: [],
  logs: {
    stdout: [],
    stderr: [],
  },
  error: ExecutionError {
    name: "TypeScriptCompilerError",
    value: "[Error:   x 'import', and 'export' cannot be used outside of module code\n   ,-[index.ts:2:1]\n 1 | \n 2 |     import test from \"module\";\n   :     ^^^^^^\n 3 |     console.log(x)\n   `----\n\n\nCaused by:\n    Syntax Error] {\n  code: 'GenericFailure'\n}\n",
    traceback: "",
  },
  executionCount: undefined,
  text: [Getter],
  toJSON: [Function: toJSON],
}
  • not out of the box, I can wrap it in a server but it makes little sense - instead of starting new process we will be starting new http request which will be starting new process

@wong2
Copy link

wong2 commented Apr 28, 2025

Why not Node.js 22? It's the latest LTS version

@mishushakov
Copy link
Member Author

mishushakov commented Apr 28, 2025

@wong2 some native ijavascript dependencies didn't compile on v22

@mishushakov mishushakov requested a review from 0div April 30, 2025 15:35
@mishushakov mishushakov merged commit 95163ce into main May 2, 2025
4 checks passed
@mishushakov mishushakov deleted the support-tsjs-natively-in-code-interpreter-e2b-1315 branch May 2, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants