(defaultCwd: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean)
| 326 | } |
| 327 | |
| 328 | export async function plainPtyExec(defaultCwd: string | undefined, loadNativeModule: <T>(moduleName: string) => Promise<T | undefined>, allowInheritTTY: boolean): Promise<PtyExecFunction> { |
| 329 | const pty = await loadNativeModule<typeof ptyType>('node-pty'); |
| 330 | if (!pty) { |
| 331 | const plain = plainExec(defaultCwd); |
| 332 | return plainExecAsPtyExec(plain, allowInheritTTY); |
| 333 | } |
| 334 | |
| 335 | return async function (params: PtyExecParameters): Promise<PtyExec> { |
| 336 | const { cmd, args, output } = params; |
| 337 | |
| 338 | const text = `Run: ${cmd} ${(args || []).join(' ').replace(/\n.*/g, '')}`; |
| 339 | const start = output.start(text); |
| 340 | |
| 341 | const useConpty = false; // TODO: Investigate using a shell with ConPTY. https://github.com/Microsoft/vscode-remote/issues/1234#issuecomment-485501275 |
| 342 | const cwd = params.cwd || defaultCwd; |
| 343 | const env = params.env ? { ...process.env, ...params.env } : process.env; |
| 344 | const exec = await findLocalWindowsExecutable(cmd, cwd, env, output); |
| 345 | const p = pty.spawn(exec, args || [], { |
| 346 | cwd, |
| 347 | env: env as any, |
| 348 | cols: output.dimensions?.columns, |
| 349 | rows: output.dimensions?.rows, |
| 350 | useConpty, |
| 351 | }); |
| 352 | const subs = [ |
| 353 | output.onDidChangeDimensions && output.onDidChangeDimensions(e => p.resize(e.columns, e.rows)) |
| 354 | ]; |
| 355 | |
| 356 | return { |
| 357 | onData: p.onData.bind(p), |
| 358 | write: p.write.bind(p), |
| 359 | resize: p.resize.bind(p), |
| 360 | exit: new Promise(resolve => { |
| 361 | p.onExit(({ exitCode, signal }) => { |
| 362 | subs.forEach(sub => sub?.dispose()); |
| 363 | output.stop(text, start); |
| 364 | resolve({ code: exitCode, signal }); |
| 365 | if (process.platform === 'win32') { |
| 366 | try { |
| 367 | // In some cases the process hasn't cleanly exited on Windows and the winpty-agent gets left around |
| 368 | // https://github.com/microsoft/node-pty/issues/333 |
| 369 | p.kill(); |
| 370 | } catch { |
| 371 | } |
| 372 | } |
| 373 | }); |
| 374 | }), |
| 375 | async terminate() { |
| 376 | p.kill('SIGKILL'); |
| 377 | } |
| 378 | }; |
| 379 | }; |
| 380 | } |
| 381 | |
| 382 | export function plainExecAsPtyExec(plain: ExecFunction, allowInheritTTY: boolean): PtyExecFunction { |
| 383 | return async function (params: PtyExecParameters): Promise<PtyExec> { |
no test coverage detected