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

Function findLocalWindowsExecutable

src/spec-common/commonUtils.ts:426–488  ·  view source on GitHub ↗
(command: string, cwd = process.cwd(), env: Record<string, string | undefined>, output: Log)

Source from the content-addressed store, hash-verified

424}
425
426async function findLocalWindowsExecutable(command: string, cwd = process.cwd(), env: Record<string, string | undefined>, output: Log): Promise<string> {
427 if (process.platform !== 'win32') {
428 return command;
429 }
430
431 // From terminalTaskSystem.ts.
432
433 // If we have an absolute path then we take it.
434 if (path.isAbsolute(command)) {
435 return await findLocalWindowsExecutableWithExtension(command) || command;
436 }
437 if (/[/\\]/.test(command)) {
438 // We have a directory and the directory is relative (see above). Make the path absolute
439 // to the current working directory.
440 const fullPath = path.join(cwd, command);
441 return await findLocalWindowsExecutableWithExtension(fullPath) || fullPath;
442 }
443 let pathValue: string | undefined = undefined;
444 let paths: string[] | undefined = undefined;
445 // The options can override the PATH. So consider that PATH if present.
446 if (env) {
447 // Path can be named in many different ways and for the execution it doesn't matter
448 for (let key of Object.keys(env)) {
449 if (key.toLowerCase() === 'path') {
450 const value = env[key];
451 if (typeof value === 'string') {
452 pathValue = value;
453 paths = value.split(path.delimiter)
454 .filter(Boolean);
455 paths.push(path.join(env.ProgramW6432 || 'C:\\Program Files', 'Docker\\Docker\\resources\\bin')); // Fall back when newly installed.
456 }
457 break;
458 }
459 }
460 }
461 // No PATH environment. Bail out.
462 if (paths === void 0 || paths.length === 0) {
463 output.write(`findLocalWindowsExecutable: No PATH to look up executable '${command}'.`);
464 const err = new Error(`No PATH to look up executable '${command}'.`);
465 (err as any).code = 'ENOENT';
466 throw err;
467 }
468 // We have a simple file name. We get the path variable from the env
469 // and try to find the executable on the path.
470 for (let pathEntry of paths) {
471 // The path entry is absolute.
472 let fullPath: string;
473 if (path.isAbsolute(pathEntry)) {
474 fullPath = path.join(pathEntry, command);
475 } else {
476 fullPath = path.join(cwd, pathEntry, command);
477 }
478 const withExtension = await findLocalWindowsExecutableWithExtension(fullPath);
479 if (withExtension) {
480 return withExtension;
481 }
482 }
483 // Not found in PATH. Bail out.

Callers 2

plainExecFunction · 0.85
plainPtyExecFunction · 0.85

Calls 2

writeMethod · 0.65

Tested by

no test coverage detected