MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / main

Function main

scripts/npm-shim.js:44–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42});
43
44async function main() {
45 // Happy path: the npm-installed optional dependency. Fall back to a download
46 // when the registry didn't deliver it.
47 var resolved = resolveInstalledBundle() || (await selfHealBundle());
48 // Thread the MCP host's pid (our parent) down to the bundled server so its
49 // orphan watchdog can poll the host directly. Without this, the server can
50 // only watch THIS shim — and a shim killed during the server's first ~100ms
51 // of startup used to leave the server orphaned forever (issue #1185). An
52 // already-set value (an outer launcher) wins.
53 var env = Object.assign({}, process.env);
54 if (!env.CODEGRAPH_HOST_PPID) env.CODEGRAPH_HOST_PPID = String(process.ppid);
55 var res = childProcess.spawnSync(resolved.command, resolved.args, { stdio: 'inherit', windowsHide: true, env: env });
56 if (res.error) {
57 process.stderr.write('codegraph: ' + res.error.message + '\n');
58 process.exit(1);
59 }
60 if (res.signal) {
61 // The bundled runtime was killed by a signal, most often the kernel's
62 // out-of-memory killer. Say so and exit as a shell would, 128 plus the
63 // signal's number (137 for SIGKILL), so a script can tell a kill from a
64 // failure; a bare exit 1 said neither (issue #3277). The CLI's own
65 // relaunch (src/extraction/wasm-runtime-flags.ts) does the same.
66 process.stderr.write(res.signal === 'SIGKILL'
67 ? 'codegraph: the process was killed by SIGKILL; the system may have run out of memory.\n'
68 : 'codegraph: the process was stopped by ' + res.signal + '.\n');
69 var signo = os.constants.signals[res.signal];
70 process.exit(typeof signo === 'number' ? 128 + signo : 1);
71 }
72 process.exit(res.status === null ? 1 : res.status);
73}
74
75// Resolve the launcher from the installed per-platform optionalDependency.
76// Returns {command, args} or null if the package isn't installed.

Callers 1

npm-shim.jsFile · 0.70

Calls 4

resolveInstalledBundleFunction · 0.85
selfHealBundleFunction · 0.85
exitMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected