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
22
23
24
25
26
27
28
# File 'lib/daytona/code_toolbox/sandbox_ts_code_toolbox.rb', line 12

def get_run_command(code, params = nil)
  # Prepend argv fix: ts-node places the script path at argv[1]; splice it out to match legacy node -e behaviour
  encoded_code = Base64.strict_encode64("process.argv.splice(1, 1);\n" + code)

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

  # Pipe the base64-encoded code via stdin to avoid OS ARG_MAX limits on large payloads
  # ts-node does not support - for stdin; use shell PID ($$) for the temp file — each code_run spawns its own
  # shell process so $$ is unique across concurrent calls; cleaned up before exit
  # npm_config_loglevel=error suppresses npm notice/warn output at source, preserving streaming and real errors
  '_f=/tmp/dtn_$$.ts; ' \
    "printf '%s' '#{encoded_code}' | base64 -d > \"$_f\"; " \
    "npm_config_loglevel=error npx ts-node -T --ignore-diagnostics 5107 -O '{\"module\":\"CommonJS\"}' \"$_f\" #{argv}; " \
    '_dtn_ec=$?; ' \
    'rm -f "$_f"; ' \
    'exit $_dtn_ec'
end