Elffuss BraidHub

kikocis/continue public

main · 5.7 KiBRawPermalink
1/**
2 * This is an experimental copy of `prepackage.js` that will attempt to build the extension in a fully cross-platform way.
3 * This is not what we use for real builds.
4 * It is also not complete. Current status is that it is just beginning to be refactored.
5 */
6
7const fs = require("fs");
8const path = require("path");
9
10const { rimrafSync } = require("rimraf");
11
12const {
13 validateFilesPresent,
14 autodetectPlatformAndArch,
15} = require("../../../scripts/util/index");
16
17const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config");
18const { npmInstall } = require("./npm-install");
19const {
20 buildGui,
21 copyOnnxRuntimeFromNodeModules,
22 copyTreeSitterWasms,
23 copyTreeSitterTagQryFiles,
24 copyNodeModules,
25 downloadEsbuildBinary,
26 downloadRipgrepBinary,
27 copySqliteBinary,
28 installNodeModuleInTempDirAndCopyToCurrent,
29 downloadSqliteBinary,
30 copyTokenizers,
31 copyScripts,
32} = require("./utils");
33
34// Clear folders that will be packaged to ensure clean slate
35rimrafSync(path.join(__dirname, "..", "bin"));
36rimrafSync(path.join(__dirname, "..", "out"));
37fs.mkdirSync(path.join(__dirname, "..", "out", "node_modules"), {
38 recursive: true,
39});
40const guiDist = path.join(__dirname, "..", "..", "..", "gui", "dist");
41if (!fs.existsSync(guiDist)) {
42 fs.mkdirSync(guiDist, { recursive: true });
43}
44
45// Get the target to package for
46let target = undefined;
47const args = process.argv;
48if (args[2] === "--target") {
49 target = args[3];
50}
51
52let os;
53let arch;
54if (target) {
55 [os, arch] = target.split("-");
56} else {
57 [os, arch] = autodetectPlatformAndArch();
58}
59
60if (os === "alpine") {
61 os = "linux";
62}
63if (arch === "armhf") {
64 arch = "arm64";
65}
66target = `${os}-${arch}`;
67console.log("[info] Using target: ", target);
68
69const exe = os === "win32" ? ".exe" : "";
70
71console.log("[info] Using target: ", target);
72
73function ghAction() {
74 return !!process.env.GITHUB_ACTIONS;
75}
76
77async function package(target, os, arch, exe) {
78 console.log("[info] Packaging extension for target ", target);
79
80 // Copy config_schema to intellij
81 await generateAndCopyConfigYamlSchema();
82
83 // Install node_modules
84 await npmInstall();
85
86 // Build gui and copy to extensions
87 await buildGui(ghAction());
88
89 // Assets
90 // Copy tree-sitter-wasm files
91 await copyTreeSitterWasms();
92
93 // Copy tree-sitter tag query files
94 await copyTreeSitterTagQryFiles();
95
96 // Install and copy over native modules
97 // *** onnxruntime-node ***
98 await copyOnnxRuntimeFromNodeModules(target);
99
100 // copy llama tokenizers to out
101 copyTokenizers();
102
103 // Copy Linux scripts
104 await copyScripts();
105
106 // *** Install @lancedb binary ***
107 const lancePackageToInstall = {
108 "darwin-arm64": "@lancedb/vectordb-darwin-arm64",
109 "darwin-x64": "@lancedb/vectordb-darwin-x64",
110 "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
111 "linux-x64": "@lancedb/vectordb-linux-x64-gnu",
112 "win32-x64": "@lancedb/vectordb-win32-x64-msvc",
113 "win32-arm64": "@lancedb/vectordb-win32-x64-msvc", // they don't have a win32-arm64 build
114 }[target];
115 await installNodeModuleInTempDirAndCopyToCurrent(
116 lancePackageToInstall,
117 "@lancedb",
118 );
119 // *** esbuild ***
120 // await installNodeModuleInTempDirAndCopyToCurrent(
121 // "esbuild@0.17.19",
122 // "@esbuild",
123 // );
124 await downloadEsbuildBinary(target);
125
126 // *** sqlite ***
127 await downloadSqliteBinary(target);
128 await copySqliteBinary();
129
130 await downloadRipgrepBinary(target);
131
132 // copy node_modules to out/node_modules
133 await copyNodeModules();
134
135 // Copy over any worker files
136 fs.cpSync(
137 "node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js",
138 "out/xhr-sync-worker.js",
139 );
140
141 // Validate the all of the necessary files are present
142 validateFilesPresent([
143 // Queries used to create the index for @code context provider
144 "tree-sitter/code-snippet-queries/c_sharp.scm",
145
146 // Queries used for @outline and @highlights context providers
147 "tag-qry/tree-sitter-c_sharp-tags.scm",
148
149 // onnx runtime bindngs
150 `bin/napi-v3/${os}/${arch}/onnxruntime_binding.node`,
151 `bin/napi-v3/${os}/${arch}/${
152 os === "darwin"
153 ? "libonnxruntime.1.14.0.dylib"
154 : os === "linux"
155 ? "libonnxruntime.so.1.14.0"
156 : "onnxruntime.dll"
157 }`,
158
159 // Code/styling for the sidebar
160 "gui/assets/index.js",
161 "gui/assets/index.css",
162
163 // Tutorial
164 "media/move-chat-panel-right.md",
165 "continue_tutorial.py",
166 "config_schema.json",
167
168 // Embeddings model
169 "models/all-MiniLM-L6-v2/config.json",
170 "models/all-MiniLM-L6-v2/special_tokens_map.json",
171 "models/all-MiniLM-L6-v2/tokenizer_config.json",
172 "models/all-MiniLM-L6-v2/tokenizer.json",
173 "models/all-MiniLM-L6-v2/vocab.txt",
174 "models/all-MiniLM-L6-v2/onnx/model_quantized.onnx",
175
176 // node_modules (it's a bit confusing why this is necessary)
177 `node_modules/@vscode/ripgrep/bin/rg${exe}`,
178
179 // out directory (where the extension.js lives)
180 // "out/extension.js", This is generated afterward by vsce
181 // web-tree-sitter
182 "out/tree-sitter.wasm",
183 // Worker required by jsdom
184 "out/xhr-sync-worker.js",
185 // SQLite3 Node native module
186 "out/build/Release/node_sqlite3.node",
187
188 // out/node_modules (to be accessed by extension.js)
189 `out/node_modules/@vscode/ripgrep/bin/rg${exe}`,
190 `out/node_modules/@esbuild/${
191 target === "win32-arm64"
192 ? "esbuild.exe"
193 : target === "win32-x64"
194 ? "win32-x64/esbuild.exe"
195 : `${target}/bin/esbuild`
196 }`,
197 `out/node_modules/@lancedb/vectordb-${
198 os === "win32"
199 ? "win32-x64-msvc"
200 : `${target}${os === "linux" ? "-gnu" : ""}`
201 }/index.node`,
202 `out/node_modules/esbuild/lib/main.js`,
203 ]);
204}
205
206void (async () => {
207 await package(target, os, arch, exe);
208 process.exit(0);
209})();