From 291f8f5dd2efec7a53e49cc7e2a1b7e6a0833466 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 10 Dec 2025 10:39:42 -0800 Subject: [PATCH] fix: ensure cross-target LanceDB binaries are correctly copied (#9100) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: install lancedb binary for cross-target builds * chore: add temporary darwin build workflow * chore: remove temporary darwin workflow * fix: prettier formatting in prepackage.js Co-authored-by: nate * fix: ensure cross-target LanceDB binaries copied * fix: retain target lancedb binary in vsix * Update prepackage.js * fix: install LanceDB packages sequentially in binary build The previous code ran installAndCopyNodeModules in parallel for all targets, but they all write to node_modules/@lancedb. This caused race conditions where files could be partially written or empty. Changed to sequential installation to prevent file corruption. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * chore: add diagnostic logging for lancedb copy * chore: add detailed diagnostics to install-copy-nodemodule * fix: remove cached lancedb before fresh copy ncp's clobber option doesn't reliably overwrite cached files. Delete destination directory before copying to ensure fresh install. * chore: clean up diagnostic code, keep fix for cached lancedb Root cause: ncp doesn't reliably overwrite cached files. Fix: Remove destination directory before copying fresh lancedb binaries. --------- Co-authored-by: continue[bot] Co-authored-by: nate Co-authored-by: Claude --- binary/build.js | 21 ++++++++++--------- .../vscode/scripts/install-copy-nodemodule.js | 13 ++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) 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(