From 4d0c7e56e17c5f7917bbde00a38a75f494ead152 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 7 Aug 2023 19:03:23 +0100 Subject: [PATCH 1/2] Utilising esbuild for the CLI to bundle in backend-core and types as required. --- packages/cli/package.json | 6 +++--- packages/cli/tsconfig.build.json | 7 ++++++- packages/cli/tsconfig.json | 7 +------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index cb59bf7c69..76780acf30 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -2,16 +2,16 @@ "name": "@budibase/cli", "version": "0.0.0", "description": "Budibase CLI, for developers, self hosting and migrations.", - "main": "dist/src/index.js", + "main": "dist/index.js", "bin": { - "budi": "dist/src/index.js" + "budi": "dist/index.js" }, "author": "Budibase", "license": "GPL-3.0", "scripts": { "prebuild": "rm -rf prebuilds 2> /dev/null && cp -r ../../node_modules/leveldown/prebuilds prebuilds", "rename": "renamer --find .node --replace .fake 'prebuilds/**'", - "tsc": "tsc -p tsconfig.build.json", + "tsc": "node ../../scripts/build.js", "pkg": "pkg . --out-path build --no-bytecode --public --public-packages \"*\" -C GZip", "build": "yarn prebuild && yarn rename && yarn tsc && yarn pkg && yarn postbuild", "check:types": "tsc -p tsconfig.json --noEmit --paths null", diff --git a/packages/cli/tsconfig.build.json b/packages/cli/tsconfig.build.json index 8b2d44aec8..34a89f54c3 100644 --- a/packages/cli/tsconfig.build.json +++ b/packages/cli/tsconfig.build.json @@ -10,7 +10,12 @@ "incremental": true, "types": [ "node", "jest" ], "outDir": "dist", - "skipLibCheck": true + "skipLibCheck": true, + "paths": { + "@budibase/types": ["../types/src"], + "@budibase/backend-core": ["../backend-core/src"], + "@budibase/backend-core/*": ["../backend-core/*"] + } }, "include": [ "src/**/*" diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index c2935129a8..6ca641e214 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -5,12 +5,7 @@ "declaration": true, "sourceMap": true, "baseUrl": ".", - "resolveJsonModule": true, - "paths": { - "@budibase/types": ["../types/src"], - "@budibase/backend-core": ["../backend-core/src"], - "@budibase/backend-core/*": ["../backend-core/*"] - } + "resolveJsonModule": true }, "ts-node": { "require": ["tsconfig-paths/register"], From cb1cec27746f29b441d07df544736a1785087464 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 7 Aug 2023 20:21:36 +0100 Subject: [PATCH 2/2] Fixing pkg built CLI after using esbuild. --- packages/cli/package.json | 7 +++---- packages/cli/src/prebuilds.ts | 15 +++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 76780acf30..99771adbd3 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -19,12 +19,11 @@ }, "pkg": { "targets": [ - "node16-linux", - "node16-win", - "node16-macos" + "node18-linux", + "node18-win", + "node18-macos" ], "assets": [ - "node_modules/@budibase/backend-core/dist/**/*", "prebuilds/**/*" ], "outputPath": "build" diff --git a/packages/cli/src/prebuilds.ts b/packages/cli/src/prebuilds.ts index 17e084160a..21f3042274 100644 --- a/packages/cli/src/prebuilds.ts +++ b/packages/cli/src/prebuilds.ts @@ -5,7 +5,7 @@ import { error } from "./utils" const PREBUILDS = "prebuilds" const ARCH = `${os.platform()}-${os.arch()}` -const PREBUILD_DIR = join(process.execPath, "..", PREBUILDS, ARCH) +const PREBUILD_DIR = join(process.execPath, "..", "cli", PREBUILDS, ARCH) // running as built CLI pkg bundle if (!process.argv[0].includes("node")) { @@ -13,17 +13,19 @@ if (!process.argv[0].includes("node")) { } function checkForBinaries() { - const readDir = join(__filename, "..", "..", "..", PREBUILDS, ARCH) + const readDir = join(__filename, "..", "..", "..", "cli", PREBUILDS, ARCH) if (fs.existsSync(PREBUILD_DIR) || !fs.existsSync(readDir)) { return } const natives = fs.readdirSync(readDir) if (fs.existsSync(readDir)) { - fs.mkdirSync(PREBUILD_DIR, { recursive: true }) + const writePath = join(process.execPath, PREBUILDS, ARCH) + fs.mkdirSync(writePath, { recursive: true }) for (let native of natives) { const filename = `${native.split(".fake")[0]}.node` - fs.cpSync(join(readDir, native), join(PREBUILD_DIR, filename)) + fs.cpSync(join(readDir, native), join(writePath, filename)) } + console.log("copied something") } } @@ -39,8 +41,9 @@ function cleanup(evt?: number) { ) console.error(error(evt)) } - if (fs.existsSync(PREBUILD_DIR)) { - fs.rmSync(PREBUILD_DIR, { recursive: true }) + const path = join(process.execPath, PREBUILDS) + if (fs.existsSync(path)) { + fs.rmSync(path, { recursive: true }) } }