Skip to content

withConfigSandbox

withConfigSandbox<R>(options, run): Promise<R>

Defined in: cli/datapad/src/with-config-sandbox/with-config-sandbox.ts:27

Runs run with a throwaway directory prepared for loadConfigFromContent’s dir, and removes it afterwards (also when run throws).

The directory is made for a TS/JS config that imports packages:

  • node_modules is a symlink to options.nodeModules, so those imports resolve as if the config sat next to that directory.
  • A package.json of {"type":"module"} is written into it. Node decides whether a .ts/.js file is ESM or CommonJS from the nearest ancestor package.json’s type, defaulting to CommonJS — and tsx’s loader, correctly honouring that, would then require() a pure-ESM dependency such as @theholocron/cli’s dist/index.mjs, which Node rejects outright (“require() of ES Module … not supported”).

The directory lives under the OS temp dir by default rather than inside any package: read-only deployments (Vercel’s Node.js Functions ship the bundle read-only under /var/task) can’t create a directory there.

R

ConfigSandboxOptions

(dir) => Promise<R>

Promise<R>