MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main

Function main

pkg/npm/install.js:545–666  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

543}
544
545async function main() {
546 const platform = getPlatform();
547 const arch = getArch();
548 const ext = platform === 'windows' ? 'zip' : 'tar.gz';
549 // Package-manager shims are portable one-shot instances: one cached binary
550 // per platform, entered directly.
551 const binName = platform === 'windows'
552 ? WINDOWS_BINARY_NAME
553 : 'codebase-memory-mcp';
554 const binPath = path.join(BIN_DIR, binName);
555 const cacheNames = platform === 'windows'
556 ? [WINDOWS_BINARY_NAME]
557 : [binName];
558 const extractedNames = platform === 'windows'
559 ? [WINDOWS_BINARY_NAME]
560 : [binName];
561 const archiveNames = platform === 'windows'
562 ? WINDOWS_ARCHIVE_NAMES
563 : UNIX_ARCHIVE_NAMES;
564 const cachePaths = cacheNames.map((name) => path.join(BIN_DIR, name));
565
566 if (platform === 'windows' && windowsBinaryReady(BIN_DIR)) return;
567 if (platform !== 'windows' &&
568 cachePaths.every((candidate) => fs.existsSync(candidate))) {
569 try {
570 verifyCandidate(binPath);
571 return; // already installed and runnable, nothing to do
572 } catch (_) {
573 // Fall through and atomically replace the invalid binary.
574 }
575 }
576
577 fs.mkdirSync(BIN_DIR, { recursive: true });
578
579 // Linux ships a fully-static "-portable" build; the standard linux binary
580 // dynamically links glibc 2.38+ and fails on older distros. macOS/Windows
581 // have no such variant. Keep in sync with install.sh / pypi _cli.py / cli.c.
582 const variant = platform === 'linux' ? '-portable' : '';
583 // No UI/standard split since v0.10.0: one archive per platform, graph UI
584 // always embedded. The old CBM_VARIANT=ui opt-in pointed at ui-* archives
585 // that no longer exist, so honoring it could only 404 (#1538).
586 const archive = `codebase-memory-mcp-${platform}-${arch}${variant}.${ext}`;
587 const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archive}`;
588
589 process.stdout.write(`codebase-memory-mcp: downloading v${VERSION} for ${platform}/${arch}...\n`);
590
591 const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cbm-install-'));
592 const tmpArchive = path.join(tmpDir, `cbm.${ext}`);
593
594 try {
595 await download(url, tmpArchive);
596 await verifyChecksum(tmpArchive, archive);
597
598 // Validate the complete archive namespace, then extract only executables.
599 if (ext === 'tar.gz') {
600 extractExactTarArchive(
601 tmpArchive, tmpDir, archiveNames, binName,
602 );

Callers 1

install.jsFile · 0.70

Calls 10

getPlatformFunction · 0.85
getArchFunction · 0.85
windowsBinaryReadyFunction · 0.85
extractExactTarArchiveFunction · 0.85
extractZipOnWindowsFunction · 0.85
filesEqualSha256Function · 0.85
verifyCandidateFunction · 0.70
downloadFunction · 0.70
verifyChecksumFunction · 0.70

Tested by

no test coverage detected