diff --git a/binary/build.js b/binary/build.js index 839bbb281..a87139611 100644 --- a/binary/build.js +++ b/binary/build.js @@ -101,21 +101,22 @@ async function buildWithEsbuild() { ), ); - const copyLanceDBPromises = []; + // Install LanceDB packages sequentially to avoid race conditions + // when multiple packages copy to the same node_modules/@lancedb directory for (const target of targets) { if (!TARGET_TO_LANCEDB[target]) { continue; } - console.log(`[info] Downloading for ${target}...`); - copyLanceDBPromises.push( - installAndCopyNodeModules(TARGET_TO_LANCEDB[target], "@lancedb"), - ); + console.log(`[info] Downloading LanceDB for ${target}...`); + try { + await installAndCopyNodeModules(TARGET_TO_LANCEDB[target], "@lancedb"); + console.log(`[info] Copied LanceDB for ${target}`); + } catch (err) { + console.error(`[error] Failed to copy LanceDB for ${target}:`, err); + process.exit(1); + } } - await Promise.all(copyLanceDBPromises).catch(() => { - console.error("[error] Failed to copy LanceDB"); - process.exit(1); - }); - console.log("[info] Copied all LanceDB"); + console.log("[info] All LanceDB packages installed"); // tree-sitter-wasm const treeSitterWasmsDir = path.join(out, "tree-sitter-wasms"); diff --git a/extensions/vscode/scripts/install-copy-nodemodule.js b/extensions/vscode/scripts/install-copy-nodemodule.js index 9f32e91d8..c5a51f073 100644 --- a/extensions/vscode/scripts/install-copy-nodemodule.js +++ b/extensions/vscode/scripts/install-copy-nodemodule.js @@ -44,6 +44,19 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { // Without this it seems the file isn't completely written to disk await new Promise((resolve) => setTimeout(resolve, 2000)); + // Remove existing destination directory to ensure fresh copy + // ncp's clobber option doesn't reliably overwrite cached files + const packageSubdir = packageName.replace("@lancedb/", ""); + const destDir = path.join( + currentDir, + "node_modules", + toCopy, + packageSubdir, + ); + if (fs.existsSync(destDir)) { + rimrafSync(destDir); + } + // Copy the installed package back to the current directory await new Promise((resolve, reject) => { ncp(