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

Function planBinaryRemoval

src/upgrade/remove-binary.ts:134–208  ·  view source on GitHub ↗
(p: RemoveBinaryProbes)

Source from the content-addressed store, hash-verified

132}
133
134export function planBinaryRemoval(p: RemoveBinaryProbes): BinaryRemovalPlan {
135 const P = pathFor(p.platform);
136 const plan: BinaryRemovalPlan = {
137 paths: [],
138 npmGlobal: false,
139 npmRoot: null,
140 sourceRoot: null,
141 summary: [],
142 };
143
144 const method = detectInstallMethod({
145 filename: p.filename,
146 platform: p.platform,
147 cwd: p.cwd,
148 exists: p.exists,
149 });
150 if (method.kind === 'source') {
151 plan.sourceRoot = method.root;
152 }
153
154 // --- Bundle install(s) ----------------------------------------------------
155 const installDirs: string[] = [];
156 for (const dir of installDirCandidates(p)) {
157 // A dir counts as a bundle install only when it carries install artifacts.
158 const artifacts = ['versions', 'current']
159 .map((a) => P.join(dir, a))
160 .filter((a) => p.exists(a) || p.readlink(a) !== null); // `current` is a symlink on unix
161 if (artifacts.length === 0) continue;
162 installDirs.push(dir);
163 if (P.resolve(dir) === P.resolve(stateDir(p))) {
164 // Shared with machine-level state: remove artifacts only.
165 plan.paths.push(...artifacts);
166 plan.summary.push(`bundle install at ${dir} (versions/ and current — state files kept)`);
167 } else {
168 plan.paths.push(dir);
169 plan.summary.push(`bundle install at ${dir}`);
170 }
171 }
172
173 // --- Bin-dir shim (unix installer's symlink) --------------------------------
174 const binDir = p.env.CODEGRAPH_BIN_DIR
175 ?? (p.platform === 'win32' ? null : P.join(p.homedir, '.local', 'bin'));
176 if (binDir) {
177 const shim = P.join(binDir, 'codegraph');
178 const target = p.readlink(shim);
179 // Only when the link demonstrably points into a bundle install dir —
180 // resolved against the link's own directory, since install.sh links an
181 // absolute target but a hand-made relative link must still verify.
182 if (target !== null) {
183 const resolved = P.resolve(binDir, target);
184 const ours = installDirs.some((d) => resolved.startsWith(P.resolve(d) + P.sep))
185 || resolved.includes(`${P.sep}.codegraph${P.sep}`);
186 if (ours) {
187 plan.paths.push(shim);
188 plan.summary.push(`launcher link at ${shim}`);
189 }
190 }
191 }

Callers 2

runUninstallerFunction · 0.85

Calls 7

detectInstallMethodFunction · 0.90
npmInvocationFunction · 0.90
pathForFunction · 0.85
installDirCandidatesFunction · 0.85
stateDirFunction · 0.85
resolveMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected