From 112bdcb0ef0d068663271111cf47cbd34f30751a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:29:00 +0530 Subject: [PATCH] move copy-lancedb to root scripts/util --- binary/build.js | 39 +++---------------- package.json | 1 + .../utils => scripts/util}/copy-lancedb.js | 36 +++++++++++++++-- 3 files changed, 38 insertions(+), 38 deletions(-) rename {binary/utils => scripts/util}/copy-lancedb.js (76%) diff --git a/binary/build.js b/binary/build.js index 713ed6dc0..c88ac82cc 100644 --- a/binary/build.js +++ b/binary/build.js @@ -4,9 +4,12 @@ const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); const { validateFilesPresent } = require("../scripts/util"); -const { downloadRipgrep } = require("./utils/ripgrep"); const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); const { fork } = require("child_process"); +const { + copyLanceDBFilePath, + copyLanceDB, +} = require("../scripts/util/copy-lancedb"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -73,24 +76,6 @@ async function buildWithEsbuild() { }); } -/** - * Downloads and installs ripgrep binaries for the specified target - * - * @param {string} target - Target platform-arch (e.g., 'darwin-x64') - * @param {string} targetDir - Directory to install ripgrep to - * @returns {Promise} - */ -async function downloadRipgrepForTarget(target, targetDir) { - console.log(`[info] Downloading ripgrep for ${target}...`); - try { - await downloadRipgrep(target, targetDir); - console.log(`[info] Successfully installed ripgrep for ${target}`); - } catch (error) { - console.error(`[error] Failed to download ripgrep for ${target}:`, error); - throw error; - } -} - (async () => { if (esbuildOnly) { await buildWithEsbuild(); @@ -121,22 +106,8 @@ async function downloadRipgrepForTarget(target, targetDir) { continue; } console.log(`[info] Downloading for ${target}...`); - const child = fork("./utils/copy-lancedb.js", { stdio: "inherit" }); - child.send({ - payload: { - packageName: TARGET_TO_LANCEDB[target], - toCopy: "@lancedb", - }, - }); copyLanceDBPromises.push( - new Promise((resolve, reject) => { - child.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), + copyLanceDB(TARGET_TO_LANCEDB[target], "@lancedb"), ); } await Promise.all(copyLanceDBPromises).catch(() => { diff --git a/package.json b/package.json index 79e522af1..9100ad0cd 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@typescript-eslint/parser": "^7.8.0", "concurrently": "^9.1.2", "eslint-plugin-import": "^2.29.1", + "ncp": "^2.0.0", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "typescript": "^5.6.3" diff --git a/binary/utils/copy-lancedb.js b/scripts/util/copy-lancedb.js similarity index 76% rename from binary/utils/copy-lancedb.js rename to scripts/util/copy-lancedb.js index 75c728020..dc520a483 100644 --- a/binary/utils/copy-lancedb.js +++ b/scripts/util/copy-lancedb.js @@ -5,20 +5,20 @@ const fs = require("fs"); const path = require("path"); const ncp = require("ncp").ncp; -const { execCmdSync } = require("../../scripts/util"); +const { execCmdSync } = require("."); +const { fork } = require("child_process"); async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { console.log(`Copying ${packageName} to ${toCopy}`); // This is a way to install only one package without npm trying to install all the dependencies // Create a temporary directory for installing the package const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); + const currentDir = process.cwd(); const tempDir = path.join( - __dirname, - "..", + currentDir, "tmp", `continue-node_modules-${adjustedName}`, ); - const currentDir = process.cwd(); // // Remove the dir we will be copying to // rimrafSync(`node_modules/${toCopy}`); @@ -80,3 +80,31 @@ process.on("message", (msg) => { process.send({ error: true }); }); }); + +/** + * invoke a child process to install and copy lancedb into node modules + * @param {string} packageName the lancedb platform to install and copy + * @param {string} toCopy directory to copy into inside node modules + */ +async function copyLanceDB(packageName, toCopy) { + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); + child.send({ + payload: { + packageName, + toCopy, + }, + }); + + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + copyLanceDB, +};