🚧 smaller binary, multiple platforms

This commit is contained in:
Nate Sesti 2024-02-17 22:27:40 -08:00
parent e231abb095
commit 1cab82b6bf
12 changed files with 170 additions and 9 deletions

2
core/vendor/package-lock.json generated vendored
View file

@ -7,7 +7,7 @@
"": {
"name": "vendor",
"version": "1.0.0",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {
"@xenova/transformers": "^2.14.0"
}

View file

@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {
"@xenova/transformers": "^2.14.0"
}

7
pkg/README.md Normal file
View file

@ -0,0 +1,7 @@
# Continue Core Binary
The purpose of this folder is to package Typescript code in a way that can be run from any IDE or platform. We first bundle with `esbuild` and then package into binaries with `pkg`.
The `pkgJson/package.json` contains instructions for building with pkg, and needs to be in a separte folder because there is no CLI flag for the assets option (it must be in a package.json), and pkg doesn't recognize any name other than package.json, but if we use the same package.json with dependencies in it, pkg will automatically include these, significantly increasing the binary size.
The build process is otherwise defined entirely in `build.js`.

View file

@ -21,16 +21,17 @@ for (let i = 2; i < process.argv.length; i++) {
const DYNAMIC_IMPORTS = [
"esbuild",
"@esbuild",
"@lancedb",
// "@lancedb",
"posthog-node",
"@octokit",
];
fs.mkdirSync("out/node_modules", { recursive: true });
fs.mkdirSync("bin/node_modules", { recursive: true });
await Promise.all(
DYNAMIC_IMPORTS.map(
(mod) =>
new Promise((resolve, reject) =>
new Promise((resolve, reject) => {
ncp(
`node_modules/${mod}`,
`out/node_modules/${mod}`,
@ -42,8 +43,20 @@ for (let i = 2; i < process.argv.length; i++) {
resolve();
}
}
)
)
);
ncp(
`node_modules/${mod}`,
`bin/node_modules/${mod}`,
function (error) {
if (error) {
console.error(`[error] Error copying ${mod}`, error);
reject(error);
} else {
resolve();
}
}
);
})
)
);
console.log(`[info] Copied ${DYNAMIC_IMPORTS.join(", ")}`);
@ -74,6 +87,9 @@ for (let i = 2; i < process.argv.length; i++) {
}
console.log("[info] Building binary with pkg...");
execSync("npx pkg .");
execSync(`npx pkg pkgJson/darwin-arm64`);
// execSync(
// `npx pkg out/index.js --target node18-darwin-arm64 --no-bytecode --public-packages "*" --public -o bin/pkg`
// );
console.log("[info] Done!");
})();

2
pkg/package-lock.json generated
View file

@ -7,7 +7,7 @@
"": {
"name": "pkg",
"version": "1.0.0",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {
"@octokit/rest": "^20.0.2",
"commander": "^12.0.0",

View file

@ -27,7 +27,7 @@
"esbuild": "node build.js --esbuild-only"
},
"author": "",
"license": "ISC",
"license": "Apache-2.0",
"devDependencies": {
"@types/follow-redirects": "^1.14.4",
"@types/uuid": "^9.0.8",

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/vectordb-darwin-arm64/index.node",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-macos-arm64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/**/*",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-macos-x64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/**/*",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-linux-arm64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/**/*",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-linux-x64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/**/*",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-win-arm64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}

View file

@ -0,0 +1,23 @@
{
"name": "pkg",
"version": "1.0.0",
"description": "",
"bin": "../../out/index.js",
"pkg": {
"scripts": [
"node_modules/axios/**/*"
],
"assets": [
"../../../core/node_modules/sqlite3/**/*",
"../../node_modules/@lancedb/**/*",
"../../out/tree-sitter.wasm",
"../../out/tree-sitter-wasms/*"
],
"targets": [
"node18-win-x64"
],
"outputPath": "bin"
},
"author": "",
"license": "Apache-2.0"
}