Skip to content

Commit 6953fc8

Browse files
Merge pull request #5582 from continuedev/pe/ripgrep-download
feat: manual ripgrep downloads for JB
2 parents c2478d4 + e37c709 commit 6953fc8

File tree

13 files changed

+443
-173
lines changed

13 files changed

+443
-173
lines changed

binary/build.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const {
88
execCmdSync,
99
autodetectPlatformAndArch,
1010
} = require("../scripts/util");
11+
const { downloadRipgrep } = require("./utils/ripgrep");
12+
const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets");
1113

1214
const bin = path.join(__dirname, "bin");
1315
const out = path.join(__dirname, "out");
1416
const build = path.join(__dirname, "build");
1517

1618
function cleanSlate() {
17-
// Clean slate
19+
// Clean slate
1820
rimrafSync(bin);
1921
rimrafSync(out);
2022
rimrafSync(build);
@@ -25,13 +27,7 @@ function cleanSlate() {
2527
}
2628

2729
const esbuildOutputFile = "out/index.js";
28-
let targets = [
29-
"darwin-x64",
30-
"darwin-arm64",
31-
"linux-x64",
32-
"linux-arm64",
33-
"win32-x64",
34-
];
30+
let targets = [...ALL_TARGETS];
3531

3632
const [currentPlatform, currentArch] = autodetectPlatformAndArch();
3733

@@ -50,15 +46,6 @@ for (let i = 2; i < process.argv.length; i++) {
5046
}
5147
}
5248

53-
const targetToLanceDb = {
54-
"darwin-arm64": "@lancedb/vectordb-darwin-arm64",
55-
"darwin-x64": "@lancedb/vectordb-darwin-x64",
56-
"linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
57-
"linux-x64": "@lancedb/vectordb-linux-x64-gnu",
58-
"win32-x64": "@lancedb/vectordb-win32-x64-msvc",
59-
"win32-arm64": "@lancedb/vectordb-win32-arm64-msvc",
60-
};
61-
6249
// Bundles the extension into one file
6350
async function buildWithEsbuild() {
6451
console.log("[info] Building with esbuild...");
@@ -89,7 +76,6 @@ async function buildWithEsbuild() {
8976
inject: ["./importMetaUrl.js"],
9077
define: { "import.meta.url": "importMetaUrl" },
9178
});
92-
9379
}
9480

9581
async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
@@ -153,13 +139,31 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
153139
}
154140
}
155141

142+
/**
143+
* Downloads and installs ripgrep binaries for the specified target
144+
*
145+
* @param {string} target - Target platform-arch (e.g., 'darwin-x64')
146+
* @param {string} targetDir - Directory to install ripgrep to
147+
* @returns {Promise<void>}
148+
*/
149+
async function downloadRipgrepForTarget(target, targetDir) {
150+
console.log(`[info] Downloading ripgrep for ${target}...`);
151+
try {
152+
await downloadRipgrep(target, targetDir);
153+
console.log(`[info] Successfully installed ripgrep for ${target}`);
154+
} catch (error) {
155+
console.error(`[error] Failed to download ripgrep for ${target}:`, error);
156+
throw error;
157+
}
158+
}
159+
156160
(async () => {
157161
if (esbuildOnly) {
158162
await buildWithEsbuild();
159163
return;
160164
}
161165

162-
cleanSlate()
166+
cleanSlate();
163167

164168
// Informs of where to look for node_sqlite3.node https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found
165169
// This is only needed for our `pkg` command at build time
@@ -179,10 +183,10 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
179183

180184
console.log("[info] Downloading prebuilt lancedb...");
181185
for (const target of targets) {
182-
if (targetToLanceDb[target]) {
186+
if (TARGET_TO_LANCEDB[target]) {
183187
console.log(`[info] Downloading for ${target}...`);
184188
await installNodeModuleInTempDirAndCopyToCurrent(
185-
targetToLanceDb[target],
189+
TARGET_TO_LANCEDB[target],
186190
"@lancedb",
187191
);
188192
}
@@ -290,10 +294,13 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
290294
// copy @lancedb to bin folders
291295
console.log("[info] Copying @lancedb files to bin");
292296
fs.copyFileSync(
293-
`node_modules/${targetToLanceDb[target]}/index.node`,
297+
`node_modules/${TARGET_TO_LANCEDB[target]}/index.node`,
294298
`${targetDir}/index.node`,
295299
);
296300

301+
// Download and install ripgrep for the target
302+
await downloadRipgrepForTarget(target, targetDir);
303+
297304
// Informs the `continue-binary` of where to look for node_sqlite3.node
298305
// https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found
299306
fs.writeFileSync(`${targetDir}/package.json`, "");
@@ -310,6 +317,7 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
310317
`${targetDir}/continue-binary${exe}`,
311318
`${targetDir}/index.node`, // @lancedb
312319
`${targetDir}/build/Release/node_sqlite3.node`,
320+
`${targetDir}/rg${exe}`, // ripgrep binary
313321
);
314322
}
315323

binary/package-lock.json

Lines changed: 91 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

binary/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"dependencies": {
4444
"@octokit/rest": "^20.0.2",
45+
"adm-zip": "^0.5.16",
4546
"commander": "^12.0.0",
4647
"core": "file:../core",
4748
"follow-redirects": "^1.15.5",
@@ -50,6 +51,7 @@
5051
"node-fetch": "^3.3.2",
5152
"posthog-node": "^3.6.3",
5253
"system-ca": "^1.0.2",
54+
"tar": "^7.4.3",
5355
"uuid": "^9.0.1",
5456
"vectordb": "^0.4.20",
5557
"win-ca": "^3.5.1"

0 commit comments

Comments
 (0)