💚 move binary downloads to prepackage.js
This commit is contained in:
parent
1b8ea3a3eb
commit
fa1d027d23
2 changed files with 177 additions and 204 deletions
|
|
@ -1,29 +1,6 @@
|
|||
const esbuild = require("esbuild");
|
||||
const ncp = require("ncp").ncp;
|
||||
const fs = require("fs");
|
||||
const { execSync } = require("child_process");
|
||||
const { rimrafSync } = require("rimraf");
|
||||
const path = require("path");
|
||||
|
||||
function ghAction() {
|
||||
return process.env.target !== undefined;
|
||||
}
|
||||
|
||||
function isArm() {
|
||||
return (
|
||||
process.env.target === "darwin-arm64" ||
|
||||
process.env.target === "linux-arm64" ||
|
||||
process.env.target === "win32-arm64"
|
||||
);
|
||||
}
|
||||
|
||||
function isWin() {
|
||||
return process.env.target?.startsWith("win");
|
||||
}
|
||||
|
||||
(async () => {
|
||||
console.log("Bundling with esbuild for target ", process.env.target);
|
||||
|
||||
// Bundles the extension into one file
|
||||
await esbuild.build({
|
||||
entryPoints: ["src/extension.ts"],
|
||||
|
|
@ -43,68 +20,4 @@ function isWin() {
|
|||
inject: ["./importMetaUrl.js"],
|
||||
define: { "import.meta.url": "importMetaUrl" },
|
||||
});
|
||||
|
||||
// GitHub Actions doesn't support ARM, so we need to download pre-saved binaries
|
||||
if (ghAction() && isArm()) {
|
||||
// Neither lancedb nor sqlite3 have pre-built windows arm64 binaries
|
||||
if (!isWin()) {
|
||||
// lancedb binary
|
||||
console.log("Downloading pre-built lancedb binary");
|
||||
rimrafSync("node_modules/@lancedb");
|
||||
const packageToInstall = {
|
||||
"darwin-arm64": "@lancedb/vectordb-darwin-arm64",
|
||||
"linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
|
||||
}[process.env.target];
|
||||
execSync(`npm install -f ${packageToInstall}`);
|
||||
}
|
||||
|
||||
// Download and unzip esbuild
|
||||
console.log("Downloading pre-built esbuild binary");
|
||||
rimrafSync("node_modules/@esbuild");
|
||||
fs.mkdirSync("node_modules/@esbuild", { recursive: true });
|
||||
execSync(
|
||||
`curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${process.env.target}/esbuild.zip`
|
||||
);
|
||||
execSync(`cd node_modules/@esbuild && unzip esbuild.zip`);
|
||||
fs.unlinkSync("node_modules/@esbuild/esbuild.zip");
|
||||
}
|
||||
|
||||
if (ghAction()) {
|
||||
// sqlite3
|
||||
if (isArm() && !isWin()) {
|
||||
// Replace the installed with pre-built
|
||||
console.log("Downloading pre-built sqlite3 binary");
|
||||
rimrafSync("../../core/node_modules/sqlite3/build");
|
||||
const downloadUrl = {
|
||||
"darwin-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz",
|
||||
"linux-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz",
|
||||
}[process.env.target];
|
||||
execSync(
|
||||
`curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`
|
||||
);
|
||||
execSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz");
|
||||
fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz");
|
||||
}
|
||||
|
||||
ncp(
|
||||
path.join(__dirname, "../../core/node_modules/sqlite3/build"),
|
||||
path.join(__dirname, "out/build"),
|
||||
(error) => {
|
||||
if (error) console.warn("Error copying sqlite3 files", error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Copy node_modules for pre-built binaries
|
||||
const NODE_MODULES_TO_COPY = ["esbuild", "@esbuild", "@lancedb"];
|
||||
fs.mkdirSync("out/node_modules", { recursive: true });
|
||||
NODE_MODULES_TO_COPY.forEach((mod) => {
|
||||
ncp.ncp(`node_modules/${mod}`, `out/node_modules/${mod}`, function (err) {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -1,134 +1,194 @@
|
|||
const { exec } = require("child_process");
|
||||
const { execSync } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const ncp = require("ncp").ncp;
|
||||
const path = require("path");
|
||||
const { rimrafSync } = require("rimraf");
|
||||
|
||||
console.log("Packaging extension for target ", process.env.target);
|
||||
|
||||
if (!process.cwd().endsWith("vscode")) {
|
||||
// This is sometimes run from root dir instead (e.g. in VS Code tasks)
|
||||
process.chdir("extensions/vscode");
|
||||
}
|
||||
exec("npm install", async (error) => {
|
||||
if (error) throw error;
|
||||
console.log("npm install completed");
|
||||
|
||||
process.chdir("../../gui");
|
||||
// Install node_modules //
|
||||
execSync("npm install");
|
||||
console.log("npm install in extensions/vscode completed");
|
||||
|
||||
exec("npm install", (error) => {
|
||||
if (error) throw error;
|
||||
console.log("npm install in gui completed");
|
||||
process.chdir("../../gui");
|
||||
|
||||
exec("npm run build", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log("Error running npm run build in gui");
|
||||
console.log("stdout: ", stdout);
|
||||
console.log("stderr: ", stderr);
|
||||
throw error;
|
||||
}
|
||||
execSync("npm install");
|
||||
console.log("npm install in gui completed");
|
||||
|
||||
// Copy over native / wasm modules
|
||||
execSync("npm run build");
|
||||
|
||||
// onnxruntime-node
|
||||
ncp(
|
||||
path.join(__dirname, "../../../core/node_modules/onnxruntime-node/bin"),
|
||||
path.join(__dirname, "../bin"),
|
||||
(error) => {
|
||||
if (error)
|
||||
console.warn("Error copying onnxruntime-node files", error);
|
||||
}
|
||||
);
|
||||
if (process.env.target) {
|
||||
// If building for production, only need the binaries for current platform
|
||||
if (!process.env.target.startsWith("darwin")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/darwin"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
if (!process.env.target.startsWith("linux")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/linux"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
if (!process.env.target.startsWith("win")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/win32"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Copy over native / wasm modules //
|
||||
|
||||
// tree-sitter-wasms
|
||||
ncp(
|
||||
path.join(
|
||||
__dirname,
|
||||
"../../../core/node_modules/tree-sitter-wasms/out"
|
||||
),
|
||||
path.join(__dirname, "../out/tree-sitter-wasms"),
|
||||
(error) => {
|
||||
if (error)
|
||||
console.warn("Error copying tree-sitter-wasms files", error);
|
||||
}
|
||||
);
|
||||
|
||||
fs.copyFileSync(
|
||||
path.join(__dirname, "../../../core/vendor/tree-sitter.wasm"),
|
||||
path.join(__dirname, "../out/tree-sitter.wasm")
|
||||
);
|
||||
|
||||
// Then copy over the dist folder to the Intellij extension
|
||||
const intellijExtensionWebviewPath = path.join(
|
||||
"..",
|
||||
"extensions",
|
||||
"intellij",
|
||||
"src",
|
||||
"main",
|
||||
"resources",
|
||||
"webview"
|
||||
);
|
||||
const indexHtmlPath = path.join(
|
||||
intellijExtensionWebviewPath,
|
||||
"index.html"
|
||||
);
|
||||
fs.copyFileSync(indexHtmlPath, path.join("tmp_index.html"));
|
||||
fs.rmSync(intellijExtensionWebviewPath, { recursive: true });
|
||||
fs.mkdirSync(intellijExtensionWebviewPath, { recursive: true });
|
||||
|
||||
ncp("dist", intellijExtensionWebviewPath, (error) => {
|
||||
if (error) {
|
||||
console.log(
|
||||
"Error copying React app build to Intellij extension: ",
|
||||
error
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (fs.existsSync(indexHtmlPath)) {
|
||||
fs.rmSync(indexHtmlPath, {});
|
||||
}
|
||||
fs.copyFileSync("tmp_index.html", indexHtmlPath);
|
||||
fs.unlinkSync("tmp_index.html");
|
||||
console.log("Copied gui build to Intellij extension");
|
||||
});
|
||||
|
||||
// Then copy over the dist folder to the VSCode extension
|
||||
const vscodeGuiPath = path.join("../extensions/vscode/gui");
|
||||
fs.mkdirSync(vscodeGuiPath, { recursive: true });
|
||||
ncp("dist", vscodeGuiPath, (error) => {
|
||||
if (error) {
|
||||
console.log(
|
||||
"Error copying React app build to VSCode extension: ",
|
||||
error
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
console.log("Copied gui build to VSCode extension");
|
||||
});
|
||||
|
||||
if (!fs.existsSync(path.join("dist", "assets", "index.js"))) {
|
||||
throw new Error("gui build did not produce index.js");
|
||||
}
|
||||
if (!fs.existsSync(path.join("dist", "assets", "index.css"))) {
|
||||
throw new Error("gui build did not produce index.css");
|
||||
}
|
||||
console.log("npm run build in gui completed");
|
||||
// onnxruntime-node
|
||||
ncp(
|
||||
path.join(__dirname, "../../../core/node_modules/onnxruntime-node/bin"),
|
||||
path.join(__dirname, "../bin"),
|
||||
(error) => {
|
||||
if (error) console.warn("Error copying onnxruntime-node files", error);
|
||||
}
|
||||
);
|
||||
if (process.env.target) {
|
||||
// If building for production, only need the binaries for current platform
|
||||
if (!process.env.target.startsWith("darwin")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/darwin"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
if (!process.env.target.startsWith("linux")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/linux"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
if (!process.env.target.startsWith("win")) {
|
||||
fs.rmdirSync(path.join(__dirname, "../bin/napi-v3/win32"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// tree-sitter-wasms
|
||||
ncp(
|
||||
path.join(__dirname, "../../../core/node_modules/tree-sitter-wasms/out"),
|
||||
path.join(__dirname, "../out/tree-sitter-wasms"),
|
||||
(error) => {
|
||||
if (error) console.warn("Error copying tree-sitter-wasms files", error);
|
||||
}
|
||||
);
|
||||
|
||||
fs.copyFileSync(
|
||||
path.join(__dirname, "../../../core/vendor/tree-sitter.wasm"),
|
||||
path.join(__dirname, "../out/tree-sitter.wasm")
|
||||
);
|
||||
|
||||
function ghAction() {
|
||||
return process.env.target !== undefined;
|
||||
}
|
||||
|
||||
function isArm() {
|
||||
return (
|
||||
process.env.target === "darwin-arm64" ||
|
||||
process.env.target === "linux-arm64" ||
|
||||
process.env.target === "win32-arm64"
|
||||
);
|
||||
}
|
||||
|
||||
function isWin() {
|
||||
return process.env.target?.startsWith("win");
|
||||
}
|
||||
|
||||
// GitHub Actions doesn't support ARM, so we need to download pre-saved binaries
|
||||
if (ghAction() && isArm()) {
|
||||
// Neither lancedb nor sqlite3 have pre-built windows arm64 binaries
|
||||
if (!isWin()) {
|
||||
// lancedb binary
|
||||
console.log("Downloading pre-built lancedb binary");
|
||||
rimrafSync("node_modules/@lancedb");
|
||||
const packageToInstall = {
|
||||
"darwin-arm64": "@lancedb/vectordb-darwin-arm64",
|
||||
"linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
|
||||
}[process.env.target];
|
||||
execSync(`npm install -f ${packageToInstall}`);
|
||||
}
|
||||
|
||||
// Download and unzip esbuild
|
||||
console.log("Downloading pre-built esbuild binary");
|
||||
rimrafSync("node_modules/@esbuild");
|
||||
fs.mkdirSync("node_modules/@esbuild", { recursive: true });
|
||||
execSync(
|
||||
`curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${process.env.target}/esbuild.zip`
|
||||
);
|
||||
execSync(`cd node_modules/@esbuild && unzip esbuild.zip`);
|
||||
fs.unlinkSync("node_modules/@esbuild/esbuild.zip");
|
||||
}
|
||||
|
||||
if (ghAction()) {
|
||||
// sqlite3
|
||||
if (isArm() && !isWin()) {
|
||||
// Replace the installed with pre-built
|
||||
console.log("Downloading pre-built sqlite3 binary");
|
||||
rimrafSync("../../core/node_modules/sqlite3/build");
|
||||
const downloadUrl = {
|
||||
"darwin-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz",
|
||||
"linux-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz",
|
||||
}[process.env.target];
|
||||
execSync(
|
||||
`curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`
|
||||
);
|
||||
execSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz");
|
||||
fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz");
|
||||
}
|
||||
|
||||
ncp(
|
||||
path.join(__dirname, "../../core/node_modules/sqlite3/build"),
|
||||
path.join(__dirname, "out/build"),
|
||||
(error) => {
|
||||
if (error) console.warn("Error copying sqlite3 files", error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Copy node_modules for pre-built binaries
|
||||
const NODE_MODULES_TO_COPY = ["esbuild", "@esbuild", "@lancedb"];
|
||||
fs.mkdirSync("out/node_modules", { recursive: true });
|
||||
NODE_MODULES_TO_COPY.forEach((mod) => {
|
||||
ncp.ncp(`node_modules/${mod}`, `out/node_modules/${mod}`, function (err) {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Then copy over the dist folder to the Intellij extension //
|
||||
const intellijExtensionWebviewPath = path.join(
|
||||
"..",
|
||||
"extensions",
|
||||
"intellij",
|
||||
"src",
|
||||
"main",
|
||||
"resources",
|
||||
"webview"
|
||||
);
|
||||
const indexHtmlPath = path.join(intellijExtensionWebviewPath, "index.html");
|
||||
fs.copyFileSync(indexHtmlPath, path.join("tmp_index.html"));
|
||||
fs.rmSync(intellijExtensionWebviewPath, { recursive: true });
|
||||
fs.mkdirSync(intellijExtensionWebviewPath, { recursive: true });
|
||||
|
||||
ncp("dist", intellijExtensionWebviewPath, (error) => {
|
||||
if (error) {
|
||||
console.log("Error copying React app build to Intellij extension: ", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (fs.existsSync(indexHtmlPath)) {
|
||||
fs.rmSync(indexHtmlPath, {});
|
||||
}
|
||||
fs.copyFileSync("tmp_index.html", indexHtmlPath);
|
||||
fs.unlinkSync("tmp_index.html");
|
||||
console.log("Copied gui build to Intellij extension");
|
||||
});
|
||||
|
||||
// Then copy over the dist folder to the VSCode extension //
|
||||
const vscodeGuiPath = path.join("../extensions/vscode/gui");
|
||||
fs.mkdirSync(vscodeGuiPath, { recursive: true });
|
||||
ncp("dist", vscodeGuiPath, (error) => {
|
||||
if (error) {
|
||||
console.log("Error copying React app build to VSCode extension: ", error);
|
||||
throw error;
|
||||
}
|
||||
console.log("Copied gui build to VSCode extension");
|
||||
});
|
||||
|
||||
if (!fs.existsSync(path.join("dist", "assets", "index.js"))) {
|
||||
throw new Error("gui build did not produce index.js");
|
||||
}
|
||||
if (!fs.existsSync(path.join("dist", "assets", "index.css"))) {
|
||||
throw new Error("gui build did not produce index.css");
|
||||
}
|
||||
console.log("npm run build in gui completed");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue