1
/** Select source or built bootstrap assets in the mounted execution world. */2
import { dirname, resolve } from 'node:path'3
import { fileURLToPath, pathToFileURL } from 'node:url'4
import type { FileSystem } from '@deepseek-ai/dsh-fs'6
/** Deployment-owned Node executable and optional preinstalled built bootstrap. */7
export interface LaunchConfig {8
/** Executable in the subprocess world; defaults to the current Node executable. */9
nodeExecutable?: string10
/** Absolute preinstalled built bootstrap in the execution world. */11
bootstrapPath?: string12
}14
/**15
* Select explicit arguments without inheriting host loader or inspector flags.16
* @param fs - Filesystem mapping host bootstrap assets into the process world.17
* @param config - Optional preinstalled built bootstrap.18
* @param maxMessageBytes - Validated frame and queued-write limit.19
* @returns Arguments following the resolved Node executable.20
*/21
export function bootstrapArgs(fs: FileSystem, config: LaunchConfig, maxMessageBytes: number): string[] {22
if (config.bootstrapPath !== undefined) return [config.bootstrapPath, String(maxMessageBytes)]23
if ('pkg' in process) return [String(maxMessageBytes)]24
const mapped = (path: string): string => {25
const result = fs.processPathFromHostPath(path)26
if (result === undefined) throw new Error(`PTC runtime bootstrap is unavailable in the subprocess execution world: ${path}`)27
return result28
}29
/* v8 ignore next 3 -- built-lib.e2e.ts executes the bundled provider and sibling process.js under plain Node. */30
if (!new URL(import.meta.url).pathname.endsWith('.ts')) {31
return [mapped(fileURLToPath(new URL('./process.js', import.meta.url))), String(maxMessageBytes)]32
}33
const entry = mapped(fileURLToPath(new URL('./process.ts', import.meta.url)))34
const subprocess = dirname(fileURLToPath(import.meta.resolve('@deepseek-ai/dsh-subprocess/package.json')))35
const helper = mapped(resolve(subprocess, 'src/control.ts'))36
const source = `const {openInheritedControlChannel}=await import(${JSON.stringify(pathToFileURL(helper).href)});const {runNodeMain}=await import(${JSON.stringify(pathToFileURL(entry).href)});await runNodeMain(openInheritedControlChannel(),${maxMessageBytes},process);`37
return ['--input-type=module', '--eval', source]38
}