返回源码地图

packages/ptc-runtime/ptc-runtime-node/src/launch.ts

main snapshot · da00f7f5358f · 正文引用章节 11;完整原文可核对,不声称全文件人工逐行审计

完整原文供逐行核对;页面收录不代表每行都经过人工语义审核。MIT 许可见 许可证。

1/** Select source or built bootstrap assets in the mounted execution world. */
2import { dirname, resolve } from 'node:path'
3import { fileURLToPath, pathToFileURL } from 'node:url'
4import type { FileSystem } from '@deepseek-ai/dsh-fs'
5
6/** Deployment-owned Node executable and optional preinstalled built bootstrap. */
7export interface LaunchConfig {
8 /** Executable in the subprocess world; defaults to the current Node executable. */
9 nodeExecutable?: string
10 /** Absolute preinstalled built bootstrap in the execution world. */
11 bootstrapPath?: string
12}
13
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 */
21export 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 result
28 }
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}