diff --git a/binary/build.js b/binary/build.js index 6e3039cd5..045fb64f2 100644 --- a/binary/build.js +++ b/binary/build.js @@ -1,15 +1,3 @@ -/** - * NOTE: The `--esbuild-only` flag is currently not working due to - * issues with sqlite bindings looking for a package.json - * - * Example usage - * - * node build.js # Full build - * node build.js --esbuild-only --os darwin # Only runs esbuild step for darwin - * node build.js --os linux # Full build for linux only - * node build.js --esbuild-only # Only runs esbuild step for all platforms - */ - const esbuild = require("esbuild"); const fs = require("fs"); const path = require("path"); @@ -50,28 +38,12 @@ const assetBackups = [ ]; let esbuildOnly = false; -let specificOs = null; - -// Parse command line arguments -const args = process.argv.slice(2); - -for (let i = 0; i < args.length; i++) { - if (args[i] === "--esbuild-only") { +for (let i = 2; i < process.argv.length; i++) { + if (process.argv[i] === "--esbuild-only") { esbuildOnly = true; } - if (args[i] === "--target" && args[i + 1]) { - targets = [args[i + 1]]; - i++; // Skip the next argument since we've consumed it - } - if (args[i] === "--os" && args[i + 1]) { - const os = args[i + 1].toLowerCase(); - specificOs = os; - targets = targets.filter((target) => target.startsWith(os)); - if (targets.length === 0) { - console.error(`[error] No targets found for OS: ${os}`); - process.exit(1); - } - i++; // Skip the next argument since we've consumed it + if (process.argv[i - 1] === "--target") { + targets = [process.argv[i]]; } } @@ -146,22 +118,6 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { } (async () => { - // Informs of where to look for node_sqlite3.node https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found - // This is only needed for our `pkg` command - fs.writeFileSync( - "out/package.json", - JSON.stringify( - { - name: "binary", - version: "1.0.0", - author: "Continue Dev, Inc", - license: "Apache-2.0", - }, - undefined, - 2, - ), - ); - console.log("[info] Downloading prebuilt lancedb..."); for (const target of targets) { if (targetToLanceDb[target]) { @@ -237,6 +193,8 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { format: "cjs", platform: "node", sourcemap: true, + minify: true, + treeShaking: true, loader: { // eslint-disable-next-line @typescript-eslint/naming-convention ".node": "file", @@ -302,22 +260,19 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { `node_modules/${targetToLanceDb[target]}/index.node`, `${targetDir}/index.node`, ); + + // Informs the `continue-binary` of where to look for node_sqlite3.node + // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found + fs.writeFileSync(`${targetDir}/package.json`, ""); } - // Our dummy `package.json` is no longer needed so we can remove it. - // If it isn't removed, then running locally via `node out/index.js` will fail - // with a `Failed to locate bindings` error - fs.unlinkSync("out/package.json"); - const pathsToVerify = []; - for (const target of targets) { const exe = target.startsWith("win") ? ".exe" : ""; const targetDir = `bin/${target}`; pathsToVerify.push( `${targetDir}/continue-binary${exe}`, `${targetDir}/index.node`, // @lancedb - "package.json", // Informs of where to look for node_sqlite3.node https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found `${targetDir}/build/Release/node_sqlite3.node`, ); }