From 32bffe36fed3daeafe054ec691bf5b3f19472e85 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 1 May 2025 09:44:39 +0200 Subject: [PATCH] add esbuild conifguration for dht-node and database --- .github/workflows/test_database.yml | 2 +- .github/workflows/test_dht_node.yml | 4 ++-- database/esbuild.config.ts | 28 ++++++++++++++++++++++++++++ database/package.json | 14 +++++++------- dht-node/Dockerfile | 2 +- dht-node/esbuild.config.ts | 13 +++++++++++++ dht-node/package.json | 13 +++++++------ 7 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 database/esbuild.config.ts create mode 100644 dht-node/esbuild.config.ts diff --git a/.github/workflows/test_database.yml b/.github/workflows/test_database.yml index a412390c4..641f7f459 100644 --- a/.github/workflows/test_database.yml +++ b/.github/workflows/test_database.yml @@ -82,4 +82,4 @@ jobs: run: cd out && yarn install --frozen-lockfile --production=false - name: Database | Lint - run: cd out && turbo lint \ No newline at end of file + run: cd out && turbo lint build typecheck \ No newline at end of file diff --git a/.github/workflows/test_dht_node.yml b/.github/workflows/test_dht_node.yml index 9ff2e9121..b475dbcf4 100644 --- a/.github/workflows/test_dht_node.yml +++ b/.github/workflows/test_dht_node.yml @@ -65,10 +65,10 @@ jobs: - name: Wait for MariaDB to be ready run: docker run --rm --network gradido_internal-net busybox sh -c 'until nc -z mariadb 3306; do echo waiting for db; sleep 1; done;' - - name: run unit test & lint & build + - name: run unit test & lint & build & typecheck id: test run: | - cd out && turbo dht-node#lint dht-node#test + cd out && turbo dht-node#lint dht-node#test dht-node#build dht-node#typecheck echo "success=$([ $? -eq 0 ] && echo true || echo false)" >> $GITHUB_OUTPUT lint: diff --git a/database/esbuild.config.ts b/database/esbuild.config.ts new file mode 100644 index 000000000..ebdb10e2a --- /dev/null +++ b/database/esbuild.config.ts @@ -0,0 +1,28 @@ +import { build } from 'esbuild' +import fs from 'node:fs' +import { latestDbVersion } from './src/config/detectLastDBVersion' + +build({ + entryPoints: ['entity/index.ts'], + bundle: true, + target: 'node18.20.7', + platform: 'node', + packages: 'external', + outdir: './build', + plugins: [ + { + // hardcode last db version string into index.ts, before parsing + name: 'replace-latest-db-version-import', + setup(build) { + build.onLoad({ filter: /index\.ts$/ }, async (args) => { + let source = await fs.promises.readFile(args.path, 'utf8') + source = source.replace( + /import\s*\{\s*latestDbVersion\s*\}\s*from\s*['"][^'"]+['"]/, + `const latestDbVersion = "${latestDbVersion}";`, + ) + return { contents: source, loader: 'ts' } + }) + }, + }, + ], +}) diff --git a/database/package.json b/database/package.json index 713841f3b..85b641433 100644 --- a/database/package.json +++ b/database/package.json @@ -2,12 +2,12 @@ "name": "database", "version": "2.5.2", "description": "Gradido Database Tool to execute database migrations", - "main": "./build/entity/index.js", - "types": "./build/entity/index.d.ts", + "main": "./build/index.js", + "types": "./entity/index.ts", "exports": { ".": { - "import": "./build/entity/index.js", - "require": "./build/entity/index.js" + "import": "./build/index.js", + "require": "./build/index.js" } }, "repository": "https://github.com/gradido/gradido/database", @@ -15,8 +15,8 @@ "license": "Apache-2.0", "private": false, "scripts": { - "build": "mkdirp build/src/config/ && ncp src/config build/src/config && tsc --build", - "clean": "tsc --build --clean", + "build": "tsx ./esbuild.config.ts", + "typecheck": "tsc --noEmit", "up": "cross-env TZ=UTC tsx src/index.ts up", "down": "cross-env TZ=UTC tsx src/index.ts down", "reset": "cross-env TZ=UTC tsx src/index.ts reset", @@ -32,10 +32,10 @@ "@types/faker": "^5.5.9", "@types/geojson": "^7946.0.13", "@types/node": "^17.0.21", + "esbuild": "^0.25.2", "mkdirp": "^3.0.1", "ncp": "^2.0.0", "prettier": "^2.8.7", - "ts-node": "^10.9.2", "tsx": "^4.19.3", "typescript": "^4.9.5" }, diff --git a/dht-node/Dockerfile b/dht-node/Dockerfile index 7f132b451..00e781ec4 100644 --- a/dht-node/Dockerfile +++ b/dht-node/Dockerfile @@ -77,7 +77,7 @@ RUN yarn install --frozen-lockfile --production=false \ # Build the project COPY --chown=app:app --from=builder /app/out/full/ . -RUN turbo build +RUN turbo build typecheck ################################################################################## # TEST ########################################################################### diff --git a/dht-node/esbuild.config.ts b/dht-node/esbuild.config.ts new file mode 100644 index 000000000..ae8fb1ade --- /dev/null +++ b/dht-node/esbuild.config.ts @@ -0,0 +1,13 @@ +import { build } from 'esbuild' + +build({ + entryPoints: ['src/index.ts'], + outdir: 'build', + platform: 'node', + target: 'node18.20.7', + bundle: true, + keepNames: true, + // legalComments: 'inline', + external: ['udx-native', 'sodium-native'], + minify: true, +}) diff --git a/dht-node/package.json b/dht-node/package.json index c24ea2998..850b59bb7 100644 --- a/dht-node/package.json +++ b/dht-node/package.json @@ -8,10 +8,10 @@ "license": "Apache-2.0", "private": false, "scripts": { - "build": "tsc --build", - "clean": "tsc --build --clean", - "start": "cross-env TZ=UTC TS_NODE_BASEURL=./build node -r tsconfig-paths/register build/src/index.js", - "dev": "cross-env TZ=UTC nodemon -w src --ext ts --exec ts-node -r dotenv/config -r tsconfig-paths/register src/index.ts", + "build": "tsx esbuild.config.ts", + "start": "cross-env TZ=UTC node build/index.js", + "dev": "cross-env TZ=UTC tsx watch src/index.ts", + "typecheck": "tsc --noEmit", "lint": "biome check --error-on-warnings .", "lint:fix": "biome check --error-on-warnings . --write", "test": "cross-env TZ=UTC NODE_ENV=development DB_DATABASE=gradido_test_dht jest --runInBand --forceExit --detectOpenHandles" @@ -33,13 +33,14 @@ "@types/jest": "27.5.1", "@types/node": "^17.0.21", "@types/uuid": "^8.3.4", - "jest": "27.5.1", "@biomejs/biome": "1.9.4", "@types/dotenv": "^8.2.0", "@types/joi": "^17.2.3", + "esbuild": "^0.25.2", + "jest": "27.5.1", "prettier": "^2.8.7", + "tsx": "^4.19.3", "ts-jest": "27.1.4", - "ts-node": "^10.9.2", "typescript": "^4.9.4" }, "engines": {