MCPcopy Index your code
hub / github.com/devcontainers/cli / launch

Function launch

src/spec-common/shellServer.ts:21–125  ·  view source on GitHub ↗
(remoteExec: ExecFunction | Exec, output: Log, agentSessionId?: string, platform: NodeJS.Platform = 'linux', hostName: 'Host' | 'Container' = 'Container')

Source from the content-addressed store, hash-verified

19export const EOT = '\u2404';
20
21export async function launch(remoteExec: ExecFunction | Exec, output: Log, agentSessionId?: string, platform: NodeJS.Platform = 'linux', hostName: 'Host' | 'Container' = 'Container'): Promise<ShellServer> {
22 const isExecFunction = typeof remoteExec === 'function';
23 const isWindows = platform === 'win32';
24 const p = isExecFunction ? await remoteExec({
25 env: agentSessionId ? { VSCODE_REMOTE_CONTAINERS_SESSION: agentSessionId } : {},
26 cmd: isWindows ? 'powershell' : '/bin/sh',
27 args: isWindows ? ['-NoProfile', '-Command', '-'] : [],
28 output,
29 }) : remoteExec;
30 if (!isExecFunction) {
31 // TODO: Pass in agentSessionId.
32 const stdinText = isWindows
33 ? `powershell -NoProfile -Command "powershell -NoProfile -Command -"\n` // Nested PowerShell (for some reason) avoids the echo of stdin on stdout.
34 : `/bin/sh -c 'echo ${EOT}; /bin/sh'\n`;
35 p.stdin.write(stdinText);
36 const eot = new Promise<void>(resolve => {
37 let stdout = '';
38 const stdoutDecoder = new StringDecoder();
39 p.stdout.on('data', function eotListener(chunk: Buffer) {
40 stdout += stdoutDecoder.write(chunk);
41 if (stdout.includes(stdinText)) {
42 p.stdout.off('data', eotListener);
43 resolve();
44 }
45 });
46 });
47 await eot;
48 }
49
50 const monitor = monitorProcess(p);
51
52 let lastExec: Promise<any> | undefined;
53 async function exec(cmd: PlatformSwitch<string>, options?: { logLevel?: LogLevel; logOutput?: boolean | 'continuous' | 'silent'; stdin?: Buffer }) {
54 const currentExec = lastExec = (async () => {
55 try {
56 await lastExec;
57 } catch (err) {
58 // ignore
59 }
60 return _exec(platformDispatch(platform, cmd), options);
61 })();
62 try {
63 return await Promise.race([currentExec, monitor.unexpectedExit]);
64 } finally {
65 monitor.disposeStdioListeners();
66 if (lastExec === currentExec) {
67 lastExec = undefined;
68 }
69 }
70 }
71
72 async function _exec(cmd: string, options?: { logLevel?: LogLevel; logOutput?: boolean | 'continuous' | 'silent'; stdin?: Buffer }) {
73 const text = `Run in ${hostName.toLowerCase()}: ${cmd.replace(/\n.*/g, '')}`;
74 let start: number;
75 if (options?.logOutput !== 'silent') {
76 start = output.start(text, options?.logLevel);
77 }
78 if (p.stdin.destroyed) {

Callers 4

getContainerPropertiesFunction · 0.90
runUserEnvProbeFunction · 0.90
launchShellServerFunction · 0.90

Calls 5

platformDispatchFunction · 0.90
resolveFunction · 0.85
monitorProcessFunction · 0.85
onMethod · 0.80
writeMethod · 0.65

Tested by 1

launchShellServerFunction · 0.72