Class: Daytona::SandboxTsCodeToolbox

Inherits:
Object
  • Object
show all
Defined in:
lib/daytona/code_toolbox/sandbox_ts_code_toolbox.rb

Instance Method Summary collapse

Instance Method Details

#get_run_command(code, params = nil) ⇒ String

Get the run command for executing TypeScript code

Parameters:

  • code (String)

    The TypeScript code to execute

  • params (Daytona::CodeRunParams, nil) (defaults to: nil)

    Optional parameters for code execution

Returns:

  • (String)

    The command to run the TypeScript code



12
13
14
15
16
17
18
19
20
21
# File 'lib/daytona/code_toolbox/sandbox_ts_code_toolbox.rb', line 12

def get_run_command(code, params = nil)
  encoded_code = Base64.encode64(code)

  argv = params&.argv&.join(' ') || ''

  # Execute TypeScript code using ts-node with ESM support
  " sh -c 'echo #{encoded_code} | base64 --decode | npx ts-node -O " \
    "\"{\\\"module\\\":\\\"CommonJS\\\"}\" -e \"$(cat)\" x #{argv} 2>&1 | grep -vE " \
    "\"npm notice\"' "
end