diff --git a/forge.config.ts b/forge.config.ts index 81eaff2..0879cf7 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -69,6 +69,44 @@ const config: ForgeConfig = { env: { ...process.env, npm_config_nodedir: '' }, }); + // vectordb uses platform-specific optional deps (@lancedb/vectordb---*). + // npm install on Linux only pulls the Linux variant. Force-install the target's. + const platformNativePackages: Record> = { + 'win32-x64': { + '@lancedb/vectordb-win32-x64-msvc': '', + }, + 'linux-x64': { + '@lancedb/vectordb-linux-x64-gnu': '', + }, + 'darwin-x64': { + '@lancedb/vectordb-darwin-x64': '', + }, + 'darwin-arm64': { + '@lancedb/vectordb-darwin-arm64': '', + }, + }; + const targetKey = `${platform}-${arch}`; + const nativePkgs = platformNativePackages[targetKey]; + if (nativePkgs) { + // Remove wrong-platform lancedb native packages + const nmPath = path.join(buildPath, 'node_modules', '@lancedb'); + if (fs.existsSync(nmPath)) { + for (const entry of fs.readdirSync(nmPath)) { + if (entry.startsWith('vectordb-') && !Object.keys(nativePkgs).includes(`@lancedb/${entry}`)) { + fs.rmSync(path.join(nmPath, entry), { recursive: true, force: true }); + console.log(`[forge] Removed non-target native package: @lancedb/${entry}`); + } + } + } + // Install correct platform packages + const pkgsToInstall = Object.keys(nativePkgs).join(' '); + console.log(`[forge] Installing platform-specific packages for ${targetKey}: ${pkgsToInstall}`); + execSync(`npm install ${pkgsToInstall} --omit=dev --no-save`, { + cwd: buildPath, + stdio: 'inherit', + }); + } + // Remove cross-platform prebuilt binaries that don't match the target. // Packages like @github/copilot ship prebuilds for all platforms; // keeping foreign-arch .node files breaks rpmbuild's strip step.