@@ -3,13 +3,13 @@ const fs = require("fs");
3
3
const path = require ( "path" ) ;
4
4
const ncp = require ( "ncp" ) . ncp ;
5
5
const { rimrafSync } = require ( "rimraf" ) ;
6
- const {
7
- validateFilesPresent,
8
- execCmdSync,
9
- autodetectPlatformAndArch,
10
- } = require ( "../scripts/util" ) ;
11
- const { downloadRipgrep } = require ( "./utils/ripgrep" ) ;
6
+ const { validateFilesPresent } = require ( "../scripts/util" ) ;
12
7
const { ALL_TARGETS , TARGET_TO_LANCEDB } = require ( "./utils/targets" ) ;
8
+ const { fork } = require ( "child_process" ) ;
9
+ const {
10
+ installAndCopyNodeModules,
11
+ } = require ( "../extensions/vscode/scripts/install-copy-nodemodule" ) ;
12
+ const { bundleBinary } = require ( "./utils/bundle-binary" ) ;
13
13
14
14
const bin = path . join ( __dirname , "bin" ) ;
15
15
const out = path . join ( __dirname , "out" ) ;
@@ -29,8 +29,6 @@ function cleanSlate() {
29
29
const esbuildOutputFile = "out/index.js" ;
30
30
let targets = [ ...ALL_TARGETS ] ;
31
31
32
- const [ currentPlatform , currentArch ] = autodetectPlatformAndArch ( ) ;
33
-
34
32
const assetBackups = [
35
33
"node_modules/win-ca/lib/crypt32-ia32.node.bak" ,
36
34
"node_modules/win-ca/lib/crypt32-x64.node.bak" ,
@@ -78,85 +76,6 @@ async function buildWithEsbuild() {
78
76
} ) ;
79
77
}
80
78
81
- async function installNodeModuleInTempDirAndCopyToCurrent ( packageName , toCopy ) {
82
- console . log ( `Copying ${ packageName } to ${ toCopy } ` ) ;
83
- // This is a way to install only one package without npm trying to install all the dependencies
84
- // Create a temporary directory for installing the package
85
- const adjustedName = packageName . replace ( / @ / g, "" ) . replace ( "/" , "-" ) ;
86
- const tempDir = path . join (
87
- __dirname ,
88
- "tmp" ,
89
- `continue-node_modules-${ adjustedName } ` ,
90
- ) ;
91
- const currentDir = process . cwd ( ) ;
92
-
93
- // // Remove the dir we will be copying to
94
- // rimrafSync(`node_modules/${toCopy}`);
95
-
96
- // // Ensure the temporary directory exists
97
- fs . mkdirSync ( tempDir , { recursive : true } ) ;
98
-
99
- try {
100
- // Move to the temporary directory
101
- process . chdir ( tempDir ) ;
102
-
103
- // Initialize a new package.json and install the package
104
- execCmdSync ( `npm init -y && npm i -f ${ packageName } --no-save` ) ;
105
-
106
- console . log (
107
- `Contents of: ${ packageName } ` ,
108
- fs . readdirSync ( path . join ( tempDir , "node_modules" , toCopy ) ) ,
109
- ) ;
110
-
111
- // Without this it seems the file isn't completely written to disk
112
- await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
113
-
114
- // Copy the installed package back to the current directory
115
- await new Promise ( ( resolve , reject ) => {
116
- ncp (
117
- path . join ( tempDir , "node_modules" , toCopy ) ,
118
- path . join ( currentDir , "node_modules" , toCopy ) ,
119
- { dereference : true } ,
120
- ( error ) => {
121
- if ( error ) {
122
- console . error (
123
- `[error] Error copying ${ packageName } package` ,
124
- error ,
125
- ) ;
126
- reject ( error ) ;
127
- } else {
128
- resolve ( ) ;
129
- }
130
- } ,
131
- ) ;
132
- } ) ;
133
- } finally {
134
- // Clean up the temporary directory
135
- // rimrafSync(tempDir);
136
-
137
- // Return to the original directory
138
- process . chdir ( currentDir ) ;
139
- }
140
- }
141
-
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
-
160
79
( async ( ) => {
161
80
if ( esbuildOnly ) {
162
81
await buildWithEsbuild ( ) ;
@@ -181,16 +100,21 @@ async function downloadRipgrepForTarget(target, targetDir) {
181
100
) ,
182
101
) ;
183
102
184
- console . log ( "[info] Downloading prebuilt lancedb..." ) ;
103
+ const copyLanceDBPromises = [ ] ;
185
104
for ( const target of targets ) {
186
- if ( TARGET_TO_LANCEDB [ target ] ) {
187
- console . log ( `[info] Downloading for ${ target } ...` ) ;
188
- await installNodeModuleInTempDirAndCopyToCurrent (
189
- TARGET_TO_LANCEDB [ target ] ,
190
- "@lancedb" ,
191
- ) ;
105
+ if ( ! TARGET_TO_LANCEDB [ target ] ) {
106
+ continue ;
192
107
}
108
+ console . log ( `[info] Downloading for ${ target } ...` ) ;
109
+ copyLanceDBPromises . push (
110
+ installAndCopyNodeModules ( TARGET_TO_LANCEDB [ target ] , "@lancedb" ) ,
111
+ ) ;
193
112
}
113
+ await Promise . all ( copyLanceDBPromises ) . catch ( ( ) => {
114
+ console . error ( "[error] Failed to copy LanceDB" ) ;
115
+ process . exit ( 1 ) ;
116
+ } ) ;
117
+ console . log ( "[info] Copied all LanceDB" ) ;
194
118
195
119
// tree-sitter-wasm
196
120
const treeSitterWasmsDir = path . join ( out , "tree-sitter-wasms" ) ;
@@ -252,59 +176,16 @@ async function downloadRipgrepForTarget(target, targetDir) {
252
176
"out/llamaTokenizerWorkerPool.mjs" ,
253
177
) ;
254
178
179
+ const buildBinaryPromises = [ ] ;
255
180
console . log ( "[info] Building binaries with pkg..." ) ;
256
181
for ( const target of targets ) {
257
- const targetDir = `bin/${ target } ` ;
258
- fs . mkdirSync ( targetDir , { recursive : true } ) ;
259
- console . log ( `[info] Building ${ target } ...` ) ;
260
- execCmdSync (
261
- `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${ target } --out-path ${ targetDir } ` ,
262
- ) ;
263
-
264
- // Download and unzip prebuilt sqlite3 binary for the target
265
- console . log ( "[info] Downloading node-sqlite3" ) ;
266
-
267
- const downloadUrl =
268
- // node-sqlite3 doesn't have a pre-built binary for win32-arm64
269
- target === "win32-arm64"
270
- ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz"
271
- : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
272
- target
273
- } .tar.gz`;
274
-
275
- execCmdSync ( `curl -L -o ${ targetDir } /build.tar.gz ${ downloadUrl } ` ) ;
276
- execCmdSync ( `cd ${ targetDir } && tar -xvzf build.tar.gz` ) ;
277
-
278
- // Copy to build directory for testing
279
- try {
280
- const [ platform , arch ] = target . split ( "-" ) ;
281
- if ( platform === currentPlatform && arch === currentArch ) {
282
- fs . copyFileSync (
283
- `${ targetDir } /build/Release/node_sqlite3.node` ,
284
- `build/node_sqlite3.node` ,
285
- ) ;
286
- }
287
- } catch ( error ) {
288
- console . log ( "[warn] Could not copy node_sqlite to build" ) ;
289
- console . log ( error ) ;
290
- }
291
-
292
- fs . unlinkSync ( `${ targetDir } /build.tar.gz` ) ;
293
-
294
- // copy @lancedb to bin folders
295
- console . log ( "[info] Copying @lancedb files to bin" ) ;
296
- fs . copyFileSync (
297
- `node_modules/${ TARGET_TO_LANCEDB [ target ] } /index.node` ,
298
- `${ targetDir } /index.node` ,
299
- ) ;
300
-
301
- // Download and install ripgrep for the target
302
- await downloadRipgrepForTarget ( target , targetDir ) ;
303
-
304
- // Informs the `continue-binary` of where to look for node_sqlite3.node
305
- // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found
306
- fs . writeFileSync ( `${ targetDir } /package.json` , "" ) ;
182
+ buildBinaryPromises . push ( bundleBinary ( target ) ) ;
307
183
}
184
+ await Promise . all ( buildBinaryPromises ) . catch ( ( ) => {
185
+ console . error ( "[error] Failed to build binaries" ) ;
186
+ process . exit ( 1 ) ;
187
+ } ) ;
188
+ console . log ( "[info] All binaries built" ) ;
308
189
309
190
// Cleanup - this is needed when running locally
310
191
fs . rmSync ( "out/package.json" ) ;
@@ -331,4 +212,5 @@ async function downloadRipgrepForTarget(target, targetDir) {
331
212
validateFilesPresent ( pathsToVerify ) ;
332
213
333
214
console . log ( "[info] Done!" ) ;
215
+ process . exit ( 0 ) ;
334
216
} ) ( ) ;
0 commit comments