| 341 | } |
| 342 | |
| 343 | export function dockerExecFunction(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, allocatePtyIfPossible = false): ExecFunction { |
| 344 | return async function (execParams: ExecParameters): Promise<Exec> { |
| 345 | const { exec, cmd, args, env } = toExecParameters(params); |
| 346 | // Spawning without node-pty: `docker exec` only accepts -t if stdin is a TTY. (https://github.com/devcontainers/cli/issues/606) |
| 347 | const canAllocatePty = allocatePtyIfPossible && process.stdin.isTTY && execParams.stdio?.[0] === 'inherit'; |
| 348 | const { argsPrefix, args: execArgs } = toDockerExecArgs(containerName, user, execParams, canAllocatePty); |
| 349 | return exec({ |
| 350 | cmd, |
| 351 | args: (args || []).concat(execArgs), |
| 352 | env, |
| 353 | stdio: execParams.stdio, |
| 354 | output: replacingDockerExecLog(execParams.output, cmd, argsPrefix), |
| 355 | }); |
| 356 | }; |
| 357 | } |
| 358 | |
| 359 | export async function dockerPtyExecFunction(params: PartialPtyExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<PtyExecFunction> { |
| 360 | const pty = await loadNativeModule<typeof ptyType>('node-pty'); |