From d7c12676f5b8225f468853bf054a685980707b03 Mon Sep 17 00:00:00 2001 From: jango-blockchained Date: Mon, 3 Feb 2025 19:02:42 +0100 Subject: [PATCH] feat: migrate project to Bun runtime with comprehensive configuration updates - Updated Dockerfile to use Bun 1.0.26 as base image - Replaced npm/yarn scripts with Bun equivalents in package.json - Modernized .dockerignore with expanded file and directory exclusions - Simplified jest.config.cjs to use Bun's native testing framework - Added new ha-analyzer-cli.ts and health-check.ts utility scripts - Configured package manager to use Bun 1.0.26 --- .dockerignore | 77 +++++++++++++++---- Dockerfile | 15 ++-- .../ha-analyzer-cli.ts | 0 jest.config.cjs | 13 +--- package.json | 22 +++--- src/health-check.ts | 16 ++++ 6 files changed, 95 insertions(+), 48 deletions(-) rename ha-analyzer-cli.ts => extra/ha-analyzer-cli.ts (100%) create mode 100644 src/health-check.ts diff --git a/.dockerignore b/.dockerignore index b28efc8..77ad3c9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,31 +1,76 @@ # Dependencies -node_modules -npm-debug.log -yarn-debug.log -yarn-error.log +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* +package-lock.json +yarn.lock +pnpm-lock.yaml +bun.lockb # Build output -dist +dist/ +build/ +*.egg-info/ +__pycache__/ +*.py[cod] +*$py.class +*.so # Environment files -.env* +.env +.env.* !.env.example +venv/ +ENV/ +env/ -# Git -.git +# Version control +.git/ .gitignore +.gitattributes -# IDE -.vscode -.idea +# IDE and editor files +.idea/ +.vscode/ +*.swp +*.swo +.DS_Store +Thumbs.db # Test files -coverage -__tests__ +coverage/ +__tests__/ jest.config.* *.test.ts +.nyc_output + +# Logs +logs/ +*.log + +# Documentation +*.md +docs/ +CHANGELOG +LICENSE + +# Docker +docker-compose*.yml +docker-compose*.yaml +Dockerfile* + +# Temporary files +tmp/ +temp/ +.tmp/ +*.tmp # Misc -*.md -.DS_Store -*.log \ No newline at end of file +.cursorrules +.mypy_cache/ +.storage/ +.cloud/ +*.db +*.db-* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 20e8c12..efd68ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,20 @@ -# Use Node.js 20 as the base image -FROM node:20-slim - -# Install curl for healthcheck -RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* +# Use Bun as the base image +FROM oven/bun:1.0.26 # Set working directory WORKDIR /app -# Copy source code first +# Copy source code COPY . . # Install dependencies -RUN npm install +RUN bun install # Build TypeScript -RUN npm run build +RUN bun run build # Expose the port the app runs on EXPOSE 3000 # Start the application -CMD ["node", "dist/src/index.js"] \ No newline at end of file +CMD ["bun", "run", "start"] \ No newline at end of file diff --git a/ha-analyzer-cli.ts b/extra/ha-analyzer-cli.ts similarity index 100% rename from ha-analyzer-cli.ts rename to extra/ha-analyzer-cli.ts diff --git a/jest.config.cjs b/jest.config.cjs index 448a653..007ccb4 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,18 +1,7 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} */ +/** @type {import('bun:test').BunTestConfig} */ module.exports = { - preset: 'ts-jest', testEnvironment: 'node', - resolver: './jest-resolver.cjs', moduleFileExtensions: ['ts', 'js', 'json', 'node'], - transform: { - '^.+\\.ts$': ['ts-jest', { - useESM: true, - tsconfig: 'tsconfig.json' - }] - }, - moduleNameMapper: { - '^(\\.{1,2}/.*)\\.js$': '$1' - }, testMatch: ['**/__tests__/**/*.test.ts'], collectCoverage: true, coverageDirectory: 'coverage', diff --git a/package.json b/package.json index 23563b7..409968b 100644 --- a/package.json +++ b/package.json @@ -5,19 +5,19 @@ "type": "module", "main": "dist/index.js", "scripts": { - "build": "npx tsc", - "start": "node dist/src/index.js", - "dev": "tsx watch src/index.ts", - "test": "NODE_OPTIONS=--experimental-vm-modules jest --config=jest.config.cjs", - "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --config=jest.config.cjs --coverage", - "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --config=jest.config.cjs --watch", - "test:openai": "tsx openai_test.ts", + "build": "bun run tsc", + "start": "bun run dist/src/index.js", + "dev": "bun --watch src/index.ts", + "test": "bun test", + "test:coverage": "bun test --coverage", + "test:watch": "bun test --watch", + "test:openai": "bun run openai_test.ts", "lint": "eslint src --ext .ts", "lint:fix": "eslint src --ext .ts --fix", - "prepare": "npm run build", + "prepare": "bun run build", "clean": "rimraf dist", "types:check": "tsc --noEmit", - "types:install": "npm install --save-dev @types/node @types/jest" + "types:install": "bun add -d @types/node @types/jest" }, "dependencies": { "@digital-alchemy/core": "^24.11.4", @@ -62,5 +62,5 @@ }, "author": "Jango Blockchained", "license": "MIT", - "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" -} + "packageManager": "bun@1.0.26" +} \ No newline at end of file diff --git a/src/health-check.ts b/src/health-check.ts new file mode 100644 index 0000000..c53fb1a --- /dev/null +++ b/src/health-check.ts @@ -0,0 +1,16 @@ +const check = async () => { + try { + const response = await fetch('http://localhost:3000/health'); + if (!response.ok) { + console.error('Health check failed:', response.status); + process.exit(1); + } + console.log('Health check passed'); + process.exit(0); + } catch (error) { + console.error('Health check failed:', error); + process.exit(1); + } +}; + +check(); \ No newline at end of file