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

Function upgrade

__tests__/windows-powershell-module-path.test.ts:216–235  ·  view source on GitHub ↗

* Run the upgrade script CodeGraph ships against the stand-in, into an * install that holds an older version. `edit` changes the script first.

(name: string, env: NodeJS.ProcessEnv, edit: (script: string) => string = (s) => s)

Source from the content-addressed store, hash-verified

214 * install that holds an older version. `edit` changes the script first.
215 */
216 async function upgrade(name: string, env: NodeJS.ProcessEnv, edit: (script: string) => string = (s) => s) {
217 const current = path.join(dir, name, 'current');
218 fs.mkdirSync(path.join(current, 'bin'), { recursive: true });
219 fs.writeFileSync(path.join(current, 'node.exe'), 'old');
220 fs.writeFileSync(path.join(current, 'bin', 'codegraph.cmd'), '@echo old\r\n');
221 const shipped = buildWindowsUpgradeScript(current, 'v9.9.9', arch);
222 const url = `https://github.com/${REPO}/releases/download/v9.9.9/codegraph-win32-${arch}.zip`;
223 expect(shipped).toContain(url);
224 const script = edit(shipped.replace(url, `${base}/bundle.zip`));
225 const encoded = Buffer.from(script, 'utf16le').toString('base64');
226 const ran = await new Promise<{ code: number; stdout: string; stderr: string }>((resolve) => {
227 execFile(
228 'powershell.exe',
229 ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', encoded],
230 { windowsHide: true, timeout: 120_000, env },
231 (err, stdout, stderr) => resolve({ code: err ? (typeof err.code === 'number' ? err.code : 1) : 0, stdout, stderr }),
232 );
233 });
234 return { ...ran, installed: fs.readFileSync(path.join(current, 'node.exe'), 'utf8') };
235 }
236
237 /** The script as it was before: no line that loads the Archive module. */
238 const withoutOwnModule = (script: string) => {

Calls 4

fromMethod · 0.80
resolveFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected