Elffuss BraidHub

kikocis/continue public

Merge pull request #6022 from uinstinct/speedup-builds

chore: speedup builds for binary and prepackage
Changeset280dc5ce026ed077480d101c06d0fbd43d1872b399cfb28ad223a70853f4d755
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-06-26 21:04 -07:00
CommitterGitHub <noreply@github.com> · 2025-06-26 21:04 -07:00
Parentsabb85586e095, e2e21eef33bd

Browse the files at this changeset

12 files changed

modified .vscode/tasks.json +3 −0
@@ -103,6 +103,9 @@
103103 "clear": true
104104 },
105105 "options": {
106+ "env": {
107+ "SKIP_INSTALLS": "true"
108+ },
106109 "cwd": "${workspaceFolder}/extensions/vscode"
107110 }
108111 },
modified binary/build.js +26 −144
@@ -3,13 +3,13 @@
33 const path = require("path");
44 const ncp = require("ncp").ncp;
55 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");
127 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");
1313
1414 const bin = path.join(__dirname, "bin");
1515 const out = path.join(__dirname, "out");
@@ -29,8 +29,6 @@
2929 const esbuildOutputFile = "out/index.js";
3030 let targets = [...ALL_TARGETS];
3131
32-const [currentPlatform, currentArch] = autodetectPlatformAndArch();
33-
3432 const assetBackups = [
3533 "node_modules/win-ca/lib/crypt32-ia32.node.bak",
3634 "node_modules/win-ca/lib/crypt32-x64.node.bak",
@@ -78,85 +76,6 @@
7876 });
7977 }
8078
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-
16079 (async () => {
16180 if (esbuildOnly) {
16281 await buildWithEsbuild();
@@ -181,16 +100,21 @@
181100 ),
182101 );
183102
184- console.log("[info] Downloading prebuilt lancedb...");
103+ const copyLanceDBPromises = [];
185104 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;
192107 }
108+ console.log(`[info] Downloading for ${target}...`);
109+ copyLanceDBPromises.push(
110+ installAndCopyNodeModules(TARGET_TO_LANCEDB[target], "@lancedb"),
111+ );
193112 }
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");
194118
195119 // tree-sitter-wasm
196120 const treeSitterWasmsDir = path.join(out, "tree-sitter-wasms");
@@ -252,59 +176,16 @@
252176 "out/llamaTokenizerWorkerPool.mjs",
253177 );
254178
179+ const buildBinaryPromises = [];
255180 console.log("[info] Building binaries with pkg...");
256181 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));
307183 }
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");
308189
309190 // Cleanup - this is needed when running locally
310191 fs.rmSync("out/package.json");
@@ -331,4 +212,5 @@
331212 validateFilesPresent(pathsToVerify);
332213
333214 console.log("[info] Done!");
215+ process.exit(0);
334216 })();
added binary/utils/bundle-binary.js +103 −0
@@ -0,0 +1,103 @@
1+/**
2+ * @file Builds the binary for the specified target. It is also intended to run as a child process.
3+ */
4+
5+const {
6+ execCmdSync,
7+ autodetectPlatformAndArch,
8+} = require("../../scripts/util");
9+const { downloadRipgrep } = require("./ripgrep");
10+const { TARGET_TO_LANCEDB } = require("../utils/targets");
11+const fs = require("fs");
12+const {
13+ downloadSqlite,
14+} = require("../../extensions/vscode/scripts/download-copy-sqlite-esbuild");
15+const { fork } = require("child_process");
16+
17+async function downloadNodeSqlite(target, targetDir) {
18+ const [currentPlatform, currentArch] = autodetectPlatformAndArch();
19+
20+ // Download and unzip prebuilt sqlite3 binary for the target
21+ console.log("[info] Downloading node-sqlite3");
22+
23+ await downloadSqlite(target, `${targetDir}/build.tar.gz`);
24+
25+ execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
26+
27+ // Copy to build directory for testing
28+ try {
29+ const [platform, arch] = target.split("-");
30+ if (platform === currentPlatform && arch === currentArch) {
31+ fs.copyFileSync(
32+ `${targetDir}/build/Release/node_sqlite3.node`,
33+ `build/node_sqlite3.node`,
34+ );
35+ }
36+ } catch (error) {
37+ console.log("[warn] Could not copy node_sqlite to build");
38+ console.log(error);
39+ }
40+ fs.unlinkSync(`${targetDir}/build.tar.gz`);
41+}
42+
43+/**
44+ * @param {string} target the platform to build for
45+ */
46+async function bundleForBinary(target) {
47+ const targetDir = `bin/${target}`;
48+ fs.mkdirSync(targetDir, { recursive: true });
49+ console.log(`[info] Building ${target}...`);
50+ execCmdSync(
51+ `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`,
52+ );
53+
54+ // copy @lancedb to bin folders
55+ console.log("[info] Copying @lancedb files to bin");
56+ fs.copyFileSync(
57+ `node_modules/${TARGET_TO_LANCEDB[target]}/index.node`,
58+ `${targetDir}/index.node`,
59+ );
60+
61+ const downloadPromises = [];
62+ downloadPromises.push(downloadRipgrep(target, targetDir));
63+ downloadPromises.push(downloadNodeSqlite(target, targetDir));
64+ await Promise.all(downloadPromises);
65+
66+ // Informs the `continue-binary` of where to look for node_sqlite3.node
67+ // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found
68+ fs.writeFileSync(`${targetDir}/package.json`, "");
69+}
70+
71+process.on("message", (msg) => {
72+ bundleForBinary(msg.payload.target)
73+ .then(() => process.send({ done: true }))
74+ .catch((error) => {
75+ console.error(error); // show the error in the parent process
76+ process.send({ error: true });
77+ });
78+});
79+
80+/**
81+ * @param {string} target the platform to bundle for
82+ */
83+async function bundleBinary(target) {
84+ const child = fork(__filename, { stdio: "inherit" });
85+ child.send({
86+ payload: {
87+ target,
88+ },
89+ });
90+ return new Promise((resolve, reject) => {
91+ child.on("message", (msg) => {
92+ if (msg.error) {
93+ reject();
94+ } else {
95+ resolve();
96+ }
97+ });
98+ });
99+}
100+
101+module.exports = {
102+ bundleBinary,
103+};
modified extensions/vscode/.gitignore +1 −0
@@ -9,6 +9,7 @@
99 exe
1010 bin
1111 assets
12+tmp
1213
1314 gui/**
1415
added extensions/vscode/scripts/download-copy-sqlite-esbuild.js +191 −0
@@ -0,0 +1,191 @@
1+const { fork } = require("child_process");
2+const fs = require("fs");
3+const https = require("https");
4+const path = require("path");
5+
6+const { rimrafSync } = require("rimraf");
7+
8+const { execCmdSync } = require("../../../scripts/util");
9+
10+/**
11+ * download a file using nodejs http
12+ * @param {string} url
13+ * @param {string} outputPath
14+ * @param {number} maxRedirects
15+ */
16+async function downloadFile(url, outputPath, maxRedirects = 5) {
17+ return new Promise((resolve, reject) => {
18+ const downloadWithRedirects = (currentUrl, redirectCount = 0) => {
19+ if (redirectCount > maxRedirects) {
20+ return reject(new Error(`Too many redirects (${maxRedirects})`));
21+ }
22+
23+ const request = https.get(currentUrl, (response) => {
24+ if (
25+ response.statusCode >= 300 &&
26+ response.statusCode < 400 &&
27+ response.headers.location
28+ ) {
29+ return downloadWithRedirects(
30+ response.headers.location,
31+ redirectCount + 1,
32+ );
33+ }
34+
35+ if (response.statusCode !== 200) {
36+ return reject(
37+ new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`),
38+ );
39+ }
40+
41+ const outputDir = path.dirname(outputPath);
42+ if (!fs.existsSync(outputDir)) {
43+ fs.mkdirSync(outputDir, { recursive: true });
44+ }
45+
46+ const writeStream = fs.createWriteStream(outputPath);
47+
48+ const totalSize = parseInt(response.headers["content-length"], 10);
49+ let downloadedSize = 0;
50+
51+ response.on("data", (chunk) => {
52+ downloadedSize += chunk.length;
53+ if (totalSize) {
54+ const percent = ((downloadedSize / totalSize) * 100).toFixed(1);
55+ process.stdout.write(
56+ `\rDownloading: ${percent}% (${downloadedSize}/${totalSize} bytes)`,
57+ );
58+ }
59+ });
60+
61+ response.pipe(writeStream);
62+
63+ writeStream.on("finish", () => {
64+ console.log(`\nDownload completed: ${outputPath}`);
65+ resolve(outputPath);
66+ });
67+
68+ writeStream.on("error", reject);
69+ response.on("error", reject);
70+ });
71+
72+ request.on("error", reject);
73+ request.setTimeout(30000, () => {
74+ request.destroy();
75+ reject(new Error("Request timeout"));
76+ });
77+ };
78+
79+ downloadWithRedirects(url);
80+ });
81+}
82+
83+/**
84+ *
85+ * @param {string} target platform specific target
86+ * @param {string} targetDir the directory to download into
87+ */
88+async function downloadSqlite(target, targetDir) {
89+ const downloadUrl =
90+ // node-sqlite3 doesn't have a pre-built binary for win32-arm64
91+ target === "win32-arm64"
92+ ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz"
93+ : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
94+ target
95+ }.tar.gz`;
96+ await downloadFile(downloadUrl, targetDir);
97+}
98+
99+async function installAndCopySqlite(target) {
100+ // Replace the installed with pre-built
101+ console.log("[info] Downloading pre-built sqlite3 binary");
102+ rimrafSync("../../core/node_modules/sqlite3/build");
103+ await downloadSqlite(target, "../../core/node_modules/sqlite3/build.tar.gz");
104+ execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz");
105+ fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz");
106+}
107+
108+async function installAndCopyEsbuild(target) {
109+ // Download and unzip esbuild
110+ console.log("[info] Downloading pre-built esbuild binary");
111+ rimrafSync("node_modules/@esbuild");
112+ fs.mkdirSync("node_modules/@esbuild", { recursive: true });
113+ await downloadFile(
114+ `https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`,
115+ "node_modules/@esbuild/esbuild.zip",
116+ );
117+ execCmdSync("cd node_modules/@esbuild && unzip esbuild.zip");
118+ fs.unlinkSync("node_modules/@esbuild/esbuild.zip");
119+}
120+
121+process.on("message", (msg) => {
122+ const { operation, target } = msg.payload;
123+ if (operation === "sqlite") {
124+ installAndCopySqlite(target)
125+ .then(() => process.send({ done: true }))
126+ .catch((error) => {
127+ console.error(error); // show the error in the parent process
128+ process.send({ error: true });
129+ });
130+ }
131+ if (operation === "esbuild") {
132+ installAndCopyEsbuild(target)
133+ .then(() => process.send({ done: true }))
134+ .catch((error) => {
135+ console.error(error); // show the error in the parent process
136+ process.send({ error: true });
137+ });
138+ }
139+});
140+
141+/**
142+ * @param {string} target the platform to build for
143+ */
144+async function copySqlite(target) {
145+ const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() });
146+ child.send({
147+ payload: {
148+ operation: "sqlite",
149+ target,
150+ },
151+ });
152+
153+ return new Promise((resolve, reject) => {
154+ child.on("message", (msg) => {
155+ if (msg.error) {
156+ reject();
157+ } else {
158+ resolve();
159+ }
160+ });
161+ });
162+}
163+
164+/**
165+ * @param {string} target the platform to build for
166+ */
167+async function copyEsbuild(target) {
168+ const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() });
169+ child.send({
170+ payload: {
171+ operation: "esbuild",
172+ target,
173+ },
174+ });
175+
176+ return new Promise((resolve, reject) => {
177+ child.on("message", (msg) => {
178+ if (msg.error) {
179+ reject();
180+ } else {
181+ resolve();
182+ }
183+ });
184+ });
185+}
186+
187+module.exports = {
188+ downloadSqlite,
189+ copySqlite,
190+ copyEsbuild,
191+};
modified extensions/vscode/scripts/esbuild.js +2 −1
@@ -1,4 +1,5 @@
11 const fs = require("fs");
2+
23 const { writeBuildTimestamp } = require("./utils");
34
45 const esbuild = require("esbuild");
@@ -49,7 +50,7 @@
4950 ],
5051 };
5152
52-(async () => {
53+void (async () => {
5354 // Create .buildTimestamp.js before starting the first build
5455 writeBuildTimestamp();
5556 // Bundles the extension into one file
added extensions/vscode/scripts/generate-copy-config.js +126 −0
@@ -0,0 +1,126 @@
1+/**
2+ * @file Generate config.yaml file from template. Also intended to run as a child process.
3+ */
4+
5+const { fork } = require("child_process");
6+const fs = require("fs");
7+const path = require("path");
8+
9+const { execCmdSync } = require("../../../scripts/util");
10+
11+const { continueDir } = require("./utils");
12+
13+async function generateConfigYamlSchema() {
14+ process.chdir(path.join(continueDir, "packages", "config-yaml"));
15+ execCmdSync("npm install");
16+ execCmdSync("npm run build");
17+ execCmdSync("npm run generate-schema");
18+ fs.copyFileSync(
19+ path.join("schema", "config-yaml-schema.json"),
20+ path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"),
21+ );
22+ console.log("[info] Generated config.yaml schema");
23+}
24+
25+async function copyConfigSchema() {
26+ process.chdir(path.join(continueDir, "extensions", "vscode"));
27+ // Modify and copy for .continuerc.json
28+ const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8"));
29+ schema.$defs.SerializedContinueConfig.properties.mergeBehavior = {
30+ type: "string",
31+ enum: ["merge", "overwrite"],
32+ default: "merge",
33+ title: "Merge behavior",
34+ markdownDescription:
35+ "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.",
36+ "x-intellij-html-description":
37+ "<p>If set to <code>merge</code>, <code>.continuerc.json</code> will be applied on top of <code>config.json</code> (arrays and objects are merged). If set to <code>overwrite</code>, then every top-level property of <code>.continuerc.json</code> will overwrite that property from <code>config.json</code>.</p>",
38+ };
39+ fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2));
40+
41+ // Copy config schemas to intellij
42+ fs.copyFileSync(
43+ "config_schema.json",
44+ path.join(
45+ "..",
46+ "intellij",
47+ "src",
48+ "main",
49+ "resources",
50+ "config_schema.json",
51+ ),
52+ );
53+ fs.copyFileSync(
54+ "continue_rc_schema.json",
55+ path.join(
56+ "..",
57+ "intellij",
58+ "src",
59+ "main",
60+ "resources",
61+ "continue_rc_schema.json",
62+ ),
63+ );
64+}
65+
66+process.on("message", (msg) => {
67+ const { operation } = msg.payload;
68+ if (operation === "generate") {
69+ generateConfigYamlSchema()
70+ .then(() => process.send({ done: true }))
71+ .catch((error) => {
72+ console.error(error); // show the error in the parent process
73+ process.send({ error: true });
74+ });
75+ }
76+ if (operation === "copy") {
77+ copyConfigSchema()
78+ .then(() => process.send({ done: true }))
79+ .catch((error) => {
80+ console.error(error); // show the error in the parent process
81+ process.send({ error: true });
82+ });
83+ }
84+});
85+
86+async function generateAndCopyConfigYamlSchema() {
87+ // Generate and copy over config-yaml-schema.json
88+ const generateConfigYamlChild = fork(
89+ path.join(__dirname, "generate-copy-config.js"),
90+ {
91+ stdio: "inherit",
92+ },
93+ );
94+ generateConfigYamlChild.send({ payload: { operation: "generate" } });
95+
96+ await new Promise((resolve, reject) => {
97+ generateConfigYamlChild.on("message", (msg) => {
98+ if (msg.error) {
99+ reject();
100+ }
101+ resolve();
102+ });
103+ });
104+
105+ // Copy config schemas to intellij
106+ const copyConfigSchemaChild = fork(
107+ path.join(__dirname, "generate-copy-config.js"),
108+ {
109+ stdio: "inherit",
110+ },
111+ );
112+ copyConfigSchemaChild.send({ payload: { operation: "copy" } });
113+
114+ await new Promise((resolve, reject) => {
115+ copyConfigSchemaChild.on("message", (msg) => {
116+ if (msg.error) {
117+ reject();
118+ }
119+ resolve();
120+ });
121+ });
122+}
123+
124+module.exports = {
125+ generateAndCopyConfigYamlSchema,
126+};
added extensions/vscode/scripts/install-copy-nodemodule.js +113 −0
@@ -0,0 +1,113 @@
1+/**
2+ * @file Copy lancedb to the current directory. It is also intended to run as a child process.
3+ */
4+
5+const { fork } = require("child_process");
6+const fs = require("fs");
7+const path = require("path");
8+
9+const ncp = require("ncp").ncp;
10+
11+const { execCmdSync } = require("../../../scripts/util");
12+
13+async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
14+ console.log(`Copying ${packageName} to ${toCopy}`);
15+ // This is a way to install only one package without npm trying to install all the dependencies
16+ // Create a temporary directory for installing the package
17+ const adjustedName = packageName.replace(/@/g, "").replace("/", "-");
18+ const currentDir = process.cwd();
19+ const tempDir = path.join(
20+ currentDir,
21+ "tmp",
22+ `continue-node_modules-${adjustedName}`,
23+ );
24+
25+ // // Remove the dir we will be copying to
26+ // rimrafSync(`node_modules/${toCopy}`);
27+
28+ // // Ensure the temporary directory exists
29+ fs.mkdirSync(tempDir, { recursive: true });
30+
31+ try {
32+ // Move to the temporary directory
33+ process.chdir(tempDir);
34+
35+ // Initialize a new package.json and install the package
36+ execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`);
37+
38+ console.log(
39+ `Contents of: ${packageName}`,
40+ fs.readdirSync(path.join(tempDir, "node_modules", toCopy)),
41+ );
42+
43+ // Without this it seems the file isn't completely written to disk
44+ await new Promise((resolve) => setTimeout(resolve, 2000));
45+
46+ // Copy the installed package back to the current directory
47+ await new Promise((resolve, reject) => {
48+ ncp(
49+ path.join(tempDir, "node_modules", toCopy),
50+ path.join(currentDir, "node_modules", toCopy),
51+ { dereference: true },
52+ (error) => {
53+ if (error) {
54+ console.error(
55+ `[error] Error copying ${packageName} package`,
56+ error,
57+ );
58+ reject(error);
59+ } else {
60+ resolve();
61+ }
62+ },
63+ );
64+ });
65+ } finally {
66+ // Clean up the temporary directory
67+ // rimrafSync(tempDir);
68+
69+ // Return to the original directory
70+ process.chdir(currentDir);
71+ }
72+}
73+
74+process.on("message", (msg) => {
75+ installNodeModuleInTempDirAndCopyToCurrent(
76+ msg.payload.packageName,
77+ msg.payload.toCopy,
78+ )
79+ .then(() => process.send({ done: true }))
80+ .catch((error) => {
81+ console.error(error); // show the error in the parent process
82+ process.send({ error: true });
83+ });
84+});
85+
86+/**
87+ * invoke a child process to install a node module into temporary directory and copy it over into node modules
88+ * @param {string} packageName the module to install and copy
89+ * @param {string} toCopy directory to copy into inside node modules
90+ */
91+async function installAndCopyNodeModules(packageName, toCopy) {
92+ const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() });
93+ child.send({
94+ payload: {
95+ packageName,
96+ toCopy,
97+ },
98+ });
99+
100+ return new Promise((resolve, reject) => {
101+ child.on("message", (msg) => {
102+ if (msg.error) {
103+ reject();
104+ } else {
105+ resolve();
106+ }
107+ });
108+ });
109+}
110+
111+module.exports = {
112+ installAndCopyNodeModules,
113+};
added extensions/vscode/scripts/npm-install.js +79 −0
@@ -0,0 +1,79 @@
1+/**
2+ * @file Install node modules for the VS Code extension and gui. This is also intended to run as a child process.
3+ */
4+
5+const { fork } = require("child_process");
6+const path = require("path");
7+
8+const { execCmdSync } = require("../../../scripts/util");
9+
10+const { continueDir } = require("./utils");
11+
12+async function installNodeModulesInGui() {
13+ process.chdir(path.join(continueDir, "gui"));
14+ execCmdSync("npm install");
15+ console.log("[info] npm install in gui completed");
16+}
17+
18+async function installNodeModulesInVscode() {
19+ process.chdir(path.join(continueDir, "extensions", "vscode"));
20+ execCmdSync("npm install");
21+ console.log("[info] npm install in extensions/vscode completed");
22+}
23+
24+process.on("message", (msg) => {
25+ const { targetDir } = msg.payload;
26+ if (targetDir === "gui") {
27+ installNodeModulesInGui()
28+ .then(() => process.send({ done: true }))
29+ .catch((error) => {
30+ console.error(error); // show the error in the parent process
31+ process.send({ error: true });
32+ });
33+ } else if (targetDir === "vscode") {
34+ installNodeModulesInVscode()
35+ .then(() => process.send({ done: true }))
36+ .catch((error) => {
37+ console.error(error); // show the error in the parent process
38+ process.send({ error: true });
39+ });
40+ }
41+});
42+
43+async function npmInstall() {
44+ const installVscodeChild = fork(__filename, {
45+ stdio: "inherit",
46+ });
47+ installVscodeChild.send({ payload: { targetDir: "vscode" } });
48+
49+ const installGuiChild = fork(__filename, {
50+ stdio: "inherit",
51+ });
52+ installGuiChild.send({ payload: { targetDir: "gui" } });
53+
54+ await Promise.all([
55+ new Promise((resolve, reject) => {
56+ installVscodeChild.on("message", (msg) => {
57+ if (msg.error) {
58+ reject();
59+ }
60+ resolve();
61+ });
62+ }),
63+ new Promise((resolve, reject) => {
64+ installGuiChild.on("message", (msg) => {
65+ if (msg.error) {
66+ reject();
67+ }
68+ resolve();
69+ });
70+ }),
71+ ]).catch((error) => {
72+ console.error(error);
73+ process.exit(1);
74+ });
75+}
76+
77+module.exports = {
78+ npmInstall,
79+};
modified extensions/vscode/scripts/prepackage.js +37 −137
@@ -10,11 +10,11 @@
1010 autodetectPlatformAndArch,
1111 } = require("../../../scripts/util/index");
1212
13-const {
14- copyConfigSchema,
15- writeBuildTimestamp,
16- generateConfigYamlSchema,
17-} = require("./utils");
13+const { copySqlite, copyEsbuild } = require("./download-copy-sqlite-esbuild");
14+const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config");
15+const { installAndCopyNodeModules } = require("./install-copy-nodemodule");
16+const { npmInstall } = require("./npm-install");
17+const { writeBuildTimestamp, continueDir } = require("./utils");
1818
1919 // Clear folders that will be packaged to ensure clean slate
2020 rimrafSync(path.join(__dirname, "..", "bin"));
@@ -27,6 +27,8 @@
2727 fs.mkdirSync(guiDist, { recursive: true });
2828 }
2929
30+const skipInstalls = process.env.SKIP_INSTALLS === "true";
31+
3032 // Get the target to package for
3133 let target = undefined;
3234 const args = process.argv;
@@ -36,10 +38,10 @@
3638
3739 let os;
3840 let arch;
39-if (!target) {
40- [os, arch] = autodetectPlatformAndArch();
41-} else {
41+if (target) {
4242 [os, arch] = target.split("-");
43+} else {
44+ [os, arch] = autodetectPlatformAndArch();
4345 }
4446
4547 if (os === "alpine") {
@@ -67,28 +69,14 @@
6769 void (async () => {
6870 console.log("[info] Packaging extension for target ", target);
6971
70- // Generate and copy over config-yaml-schema.json
71- generateConfigYamlSchema();
72-
73- // Copy config schemas to intellij
74- copyConfigSchema();
75-
76- if (!process.cwd().endsWith("vscode")) {
77- // This is sometimes run from root dir instead (e.g. in VS Code tasks)
78- process.chdir("extensions/vscode");
79- }
80-
8172 // Make sure we have an initial timestamp file
8273 writeBuildTimestamp();
8374
84- // Install node_modules //
85- execCmdSync("npm install");
86- console.log("[info] npm install in extensions/vscode completed");
87-
88- process.chdir("../../gui");
75+ if (!skipInstalls) {
76+ await Promise.all([generateAndCopyConfigYamlSchema(), npmInstall()]);
77+ }
8978
90- execCmdSync("npm install");
91- console.log("[info] npm install in gui completed");
79+ process.chdir(path.join(continueDir, "gui"));
9280
9381 if (isInGitHubAction) {
9482 execCmdSync("npm run build");
@@ -280,122 +268,32 @@
280268 );
281269 });
282270
283- async function installNodeModuleInTempDirAndCopyToCurrent(
284- packageName,
285- toCopy,
286- ) {
287- console.log(`Copying ${packageName} to ${toCopy}`);
288- // This is a way to install only one package without npm trying to install all the dependencies
289- // Create a temporary directory for installing the package
290- const adjustedName = packageName.replace(/@/g, "").replace("/", "-");
291-
292- const tempDir = `/tmp/continue-node_modules-${adjustedName}`;
293- const currentDir = process.cwd();
294-
295- // Remove the dir we will be copying to
296- rimrafSync(`node_modules/${toCopy}`);
297-
298- // Ensure the temporary directory exists
299- fs.mkdirSync(tempDir, { recursive: true });
300-
301- try {
302- // Move to the temporary directory
303- process.chdir(tempDir);
304-
305- // Initialize a new package.json and install the package
306- execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`);
307-
271+ if (!skipInstalls) {
272+ // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries
273+ // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions
274+ if (isArmTarget) {
275+ // lancedb binary
276+ const packageToInstall = {
277+ "darwin-arm64": "@lancedb/vectordb-darwin-arm64",
278+ "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
279+ "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc",
280+ }[target];
308281 console.log(
309- `Contents of: ${packageName}`,
310- fs.readdirSync(path.join(tempDir, "node_modules", toCopy)),
282+ "[info] Downloading pre-built lancedb binary: " + packageToInstall,
311283 );
312284
313- // Without this it seems the file isn't completely written to disk
314- // Ideally we validate file integrity in the validation at the end
315- await new Promise((resolve) => setTimeout(resolve, 2000));
316-
317- // Copy the installed package back to the current directory
318- await new Promise((resolve, reject) => {
319- ncp(
320- path.join(tempDir, "node_modules", toCopy),
321- path.join(currentDir, "node_modules", toCopy),
322- { dereference: true },
323- (error) => {
324- if (error) {
325- console.error(
326- `[error] Error copying ${packageName} package`,
327- error,
328- );
329- reject(error);
330- } else {
331- resolve();
332- }
333- },
334- );
335- });
336- } finally {
337- // Clean up the temporary directory
338- // rimrafSync(tempDir);
339-
340- // Return to the original directory
341- process.chdir(currentDir);
285+ await Promise.all([
286+ copyEsbuild(target),
287+ copySqlite(target),
288+ installAndCopyNodeModules(packageToInstall, "@lancedb"),
289+ ]);
290+ } else {
291+ // Download esbuild from npm in tmp and copy over
292+ console.log("[info] npm installing esbuild binary");
293+ await installAndCopyNodeModules("esbuild@0.17.19", "@esbuild");
342294 }
343295 }
344296
345- // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries
346- // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions
347- if (isArmTarget) {
348- // lancedb binary
349- const packageToInstall = {
350- "darwin-arm64": "@lancedb/vectordb-darwin-arm64",
351- "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
352- "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc",
353- }[target];
354- console.log(
355- "[info] Downloading pre-built lancedb binary: " + packageToInstall,
356- );
357-
358- await installNodeModuleInTempDirAndCopyToCurrent(
359- packageToInstall,
360- "@lancedb",
361- );
362-
363- // Replace the installed with pre-built
364- console.log("[info] Downloading pre-built sqlite3 binary");
365- rimrafSync("../../core/node_modules/sqlite3/build");
366- const downloadUrl = {
367- "darwin-arm64":
368- "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz",
369- "linux-arm64":
370- "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz",
371- // node-sqlite3 doesn't have a pre-built binary for win32-arm64
372- "win32-arm64":
373- "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz",
374- }[target];
375- execCmdSync(
376- `curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`,
377- );
378- execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz");
379- fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz");
380-
381- // Download and unzip esbuild
382- console.log("[info] Downloading pre-built esbuild binary");
383- rimrafSync("node_modules/@esbuild");
384- fs.mkdirSync("node_modules/@esbuild", { recursive: true });
385- execCmdSync(
386- `curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`,
387- );
388- execCmdSync(`cd node_modules/@esbuild && unzip esbuild.zip`);
389- fs.unlinkSync("node_modules/@esbuild/esbuild.zip");
390- } else {
391- // Download esbuild from npm in tmp and copy over
392- console.log("npm installing esbuild binary");
393- await installNodeModuleInTempDirAndCopyToCurrent(
394- "esbuild@0.17.19",
395- "@esbuild",
396- );
397- }
398-
399297 console.log("[info] Copying sqlite node binding from core");
400298 await new Promise((resolve, reject) => {
401299 ncp(
@@ -465,7 +363,7 @@
465363 );
466364
467365 // delete esbuild/bin because platform-specific @esbuild is downloaded
468- fs.rmdirSync(`out/node_modules/esbuild/bin`, { recursive: true });
366+ fs.rmSync(`out/node_modules/esbuild/bin`, { recursive: true });
469367
470368 console.log(`[info] Copied ${NODE_MODULES_TO_COPY.join(", ")}`);
471369
@@ -534,4 +432,6 @@
534432 `out/node_modules/@lancedb/vectordb-${target}${isWinTarget ? "-msvc" : ""}${isLinuxTarget ? "-gnu" : ""}/index.node`,
535433 `out/node_modules/esbuild/lib/main.js`,
536434 ]);
435+
436+ process.exit(0);
537437 })();
modified extensions/vscode/scripts/utils.js +6 −79
@@ -1,67 +1,12 @@
11 const fs = require("fs");
2-const ncp = require("ncp").ncp;
32 const path = require("path");
4-const { rimrafSync } = require("rimraf");
5-const {
6- validateFilesPresent,
7- execCmdSync,
8- autodetectPlatformAndArch,
9-} = require("../../../scripts/util/index");
103
11-const continueDir = path.join(__dirname, "..", "..", "..");
4+const ncp = require("ncp").ncp;
5+const { rimrafSync } = require("rimraf");
126
13-function generateConfigYamlSchema() {
14- process.chdir(path.join(continueDir, "packages", "config-yaml"));
15- execCmdSync("npm install");
16- execCmdSync("npm run build");
17- execCmdSync("npm run generate-schema");
18- fs.copyFileSync(
19- path.join("schema", "config-yaml-schema.json"),
20- path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"),
21- );
22- console.log("[info] Generated config.yaml schema");
23-}
7+const { execCmdSync } = require("../../../scripts/util/index");
248
25-function copyConfigSchema() {
26- process.chdir(path.join(continueDir, "extensions", "vscode"));
27- // Modify and copy for .continuerc.json
28- const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8"));
29- schema.$defs.SerializedContinueConfig.properties.mergeBehavior = {
30- type: "string",
31- enum: ["merge", "overwrite"],
32- default: "merge",
33- title: "Merge behavior",
34- markdownDescription:
35- "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.",
36- "x-intellij-html-description":
37- "<p>If set to <code>merge</code>, <code>.continuerc.json</code> will be applied on top of <code>config.json</code> (arrays and objects are merged). If set to <code>overwrite</code>, then every top-level property of <code>.continuerc.json</code> will overwrite that property from <code>config.json</code>.</p>",
38- };
39- fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2));
40-
41- // Copy config schemas to intellij
42- fs.copyFileSync(
43- "config_schema.json",
44- path.join(
45- "..",
46- "intellij",
47- "src",
48- "main",
49- "resources",
50- "config_schema.json",
51- ),
52- );
53- fs.copyFileSync(
54- "continue_rc_schema.json",
55- path.join(
56- "..",
57- "intellij",
58- "src",
59- "main",
60- "resources",
61- "continue_rc_schema.json",
62- ),
63- );
64-}
9+const continueDir = path.join(__dirname, "..", "..", "..");
6510
6611 function copyTokenizers() {
6712 fs.copyFileSync(
@@ -77,22 +22,6 @@
7722 console.log("[info] Copied llamaTokenizer");
7823 }
7924
80-function installNodeModules() {
81- // Make sure we are in the right directory
82- if (!process.cwd().endsWith("vscode")) {
83- process.chdir(path.join(continueDir, "extensions", "vscode"));
84- }
85-
86- // Install node_modules //
87- execCmdSync("npm install");
88- console.log("[info] npm install in extensions/vscode completed");
89-
90- process.chdir(path.join(continueDir, "gui"));
91-
92- execCmdSync("npm install");
93- console.log("[info] npm install in gui completed");
94-}
95-
9625 async function buildGui(isGhAction) {
9726 // Make sure we are in the right directory
9827 if (!process.cwd().endsWith("gui")) {
@@ -536,15 +465,13 @@
536465 // in the build
537466 function writeBuildTimestamp() {
538467 fs.writeFileSync(
539- "src/.buildTimestamp.ts",
468+ path.join(continueDir, "extensions/vscode", "src/.buildTimestamp.ts"),
540469 `export default "${new Date().toISOString()}";\n`,
541470 );
542471 }
543472
544473 module.exports = {
545- generateConfigYamlSchema,
546- copyConfigSchema,
547- installNodeModules,
474+ continueDir,
548475 buildGui,
549476 copyOnnxRuntimeFromNodeModules,
550477 copyTreeSitterWasms,
modified scripts/install-dependencies.sh +1 −1
@@ -57,7 +57,7 @@
5757 # This does way too many things inline but is the common denominator between many of the scripts
5858 npm install
5959 npm link @continuedev/core
60-npm run prepackage
60+# npm run prepackage # not required since npm run package has prescript of prepackage
6161 npm run package
6262 popd
6363