diff --git a/binary/build.js b/binary/build.js index 56c27b2bd..c2431333c 100644 --- a/binary/build.js +++ b/binary/build.js @@ -9,6 +9,7 @@ const { fork } = require("child_process"); const { installAndCopyNodeModules, } = require("../extensions/vscode/scripts/install-copy-nodemodule"); +const { bundleBinary } = require("./utils/bundle-binary"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -178,22 +179,7 @@ async function buildWithEsbuild() { const buildBinaryPromises = []; console.log("[info] Building binaries with pkg..."); for (const target of targets) { - const child = fork("./utils/bundle-binary.js", { stdio: "inherit" }); - child.send({ - payload: { - target, - }, - }); - buildBinaryPromises.push( - new Promise((resolve, reject) => { - child.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), - ); + buildBinaryPromises.push(bundleBinary(target)); } await Promise.all(buildBinaryPromises).catch(() => { console.error("[error] Failed to build binaries"); diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index 50f34f647..0a778f5b0 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -1,6 +1,7 @@ /** - * @file Builds the binary for the specified target. It is intended to run as a child process. + * @file Builds the binary for the specified target. It is also intended to run as a child process. */ + const { execCmdSync, autodetectPlatformAndArch, @@ -11,6 +12,7 @@ const fs = require("fs"); const { downloadSqlite, } = require("../../extensions/vscode/scripts/download-copy-sqlite-esbuild"); +const { fork } = require("child_process"); async function downloadNodeSqlite(target, targetDir) { const [currentPlatform, currentArch] = autodetectPlatformAndArch(); @@ -74,3 +76,27 @@ process.on("message", (msg) => { process.send({ error: true }); }); }); + +/** + * @param {string} target the platform to bundle for + */ +async function bundleBinary(target) { + const child = fork(__filename, { stdio: "inherit" }); + child.send({ + payload: { + target, + }, + }); + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + bundleBinary, +};