add esbuild conifguration for dht-node and database

This commit is contained in:
einhornimmond 2025-05-01 09:44:39 +02:00
parent 0e4e5af6ed
commit 32bffe36fe
7 changed files with 59 additions and 17 deletions

View File

@ -82,4 +82,4 @@ jobs:
run: cd out && yarn install --frozen-lockfile --production=false
- name: Database | Lint
run: cd out && turbo lint
run: cd out && turbo lint build typecheck

View File

@ -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:

View File

@ -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' }
})
},
},
],
})

View File

@ -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"
},

View File

@ -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 ###########################################################################

View File

@ -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,
})

View File

@ -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": {