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

Function deriveInstallDir

src/upgrade/index.ts:71–93  ·  view source on GitHub ↗
(
  bundleRoot: string,
  os: 'unix' | 'windows',
  exists: (p: string) => boolean
)

Source from the content-addressed store, hash-verified

69 * windows: <installDir>\current (bundleRoot) → <installDir>
70 */
71export function deriveInstallDir(
72 bundleRoot: string,
73 os: 'unix' | 'windows',
74 exists: (p: string) => boolean
75): string | null {
76 // Use the TARGET platform's path semantics (not the host's), so this is
77 // deterministic when reasoning about a Windows layout from a POSIX host (CI)
78 // and vice-versa. In production `os` always matches the running platform.
79 const P = os === 'windows' ? path.win32 : path.posix;
80 if (os === 'windows') {
81 if (P.basename(bundleRoot).toLowerCase() === 'current') {
82 return P.dirname(bundleRoot);
83 }
84 return null;
85 }
86 // unix: bundleRoot is <installDir>/versions/<version>
87 const parent = P.dirname(bundleRoot);
88 if (P.basename(parent) === 'versions') {
89 const installDir = P.dirname(parent);
90 return exists(installDir) ? installDir : P.dirname(parent);
91 }
92 return null;
93}
94
95export function detectInstallMethod(input: DetectInput): InstallMethod {
96 const exists = input.exists ?? fs.existsSync;

Callers 2

upgrade.test.tsFile · 0.90
detectInstallMethodFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected