Skip to content

Commit

Permalink
chore: switching to bun
Browse files Browse the repository at this point in the history
  • Loading branch information
jpb06 committed Jul 15, 2024
1 parent 5eca570 commit 8bb2c2d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 6,015 deletions.
133 changes: 96 additions & 37 deletions .github/workflows/tests-scan.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,123 @@
name: tests and sonarcloud scan
name: ⚡ Integration checks

on:
push:
branches:
- main

pull_request:
types: [opened, ready_for_review, synchronize, converted_to_draft]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: read

jobs:
tests:
lint:
name: ⬣ ESLint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]

- name: Check out repository code
uses: actions/checkout@v3
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 📦 Setup bun
uses: oven-sh/setup-bun@v2

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
node-version-file: '.node-version'
# cache: 'bun'
cache-dependency-path: ./package.json

- name: 📥 Install deps
run: bun install --frozen-lockfile

- name: 🔬 Lint
run: bun run lint

typecheck:
name: ʦ TypeScript
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]

- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: 📦 Setup bun
uses: oven-sh/setup-bun@v2

- name: Caching node_modules
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version-file: '.node-version'
# cache: 'bun'
cache-dependency-path: ./package.json

- name: 📥 Install deps
run: bun install --frozen-lockfile

- name: 🔎 Type check
run: bun run type-check

test:
name: 🎯 Tests
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]

- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
- name: 📦 Setup bun
uses: oven-sh/setup-bun@v2

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
# cache: 'bun'
cache-dependency-path: ./package.json

- name: 📥 Install deps
run: bun install --frozen-lockfile

- name: Setting yarn version
run: yarn policies set-version 1.22.19
- name: 🧪 Tests
run: bun run test:ci

- name: Install dependencies
run: yarn install --prefer-offline
- name: 💾 Uploading coverage artifact
uses: actions/upload-artifact@v4
with:
name: lcov
path: ./coverage/lcov.info

- name: Linting
run: yarn lint
sonar:
name: 🛰️ Sonar
runs-on: ubuntu-latest
needs: [lint, typecheck, test]
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]

- name: Types check
run: yarn type-check
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: Tests
run: yarn test:ci
- name: 👀 Get coverage artifact
uses: actions/download-artifact@v4
with:
name: lcov
path: ./coverage

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
- name: 📡 SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ Here is the POC of a monorepo built with nestjs and prisma used to expose severa

<!-- readme-package-icons start -->

<p align="left"><a href="https://docs.github.com/en/actions" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/GithubActions-Dark.svg" /></a>&nbsp;<a href="https://www.typescriptlang.org/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/TypeScript.svg" /></a>&nbsp;<a href="https://nodejs.org/en/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/NodeJS-Dark.svg" /></a>&nbsp;<a href="https://yarnpkg.com/api/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Yarn-Dark.svg" /></a>&nbsp;<a href="https://docs.docker.com" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Docker.svg" /></a>&nbsp;<a href="https://www.postgresql.org/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/PostgreSQL-Dark.svg" /></a>&nbsp;<a href="https://github.com/motdotla/dotenv#readme" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Dotenv-Dark.svg" /></a>&nbsp;<a href="https://eslint.org/docs/latest/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Eslint-Dark.svg" /></a>&nbsp;<a href="https://expressjs.com/en/starter/installing.html" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/ExpressJS-Dark.svg" /></a>&nbsp;<a href="https://jestjs.io/docs/getting-started" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Jest.svg" /></a>&nbsp;<a href="https://docs.nestjs.com" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/NestJS-Dark.svg" /></a>&nbsp;<a href="https://prettier.io/docs/en/index.html" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Prettier-Dark.svg" /></a>&nbsp;<a href="https://www.prisma.io/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Prisma.svg" /></a>&nbsp;<a href="https://rxjs.dev/guide/overview" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Rxjs-Dark.svg" /></a>&nbsp;<a href="https://swagger.io" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Swagger-Dark.svg" /></a>&nbsp;<a href="https://swc.rs/docs/getting-started" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Swc-Dark.svg" /></a>&nbsp;<a href="https://github.com/typestack" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/TypeStack-Dark.svg" /></a>&nbsp;<a href="https://webpack.js.org/concepts/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Webpack-Dark.svg" /></a></p>
<p align="left"><a href="https://docs.github.com/en/actions" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/GithubActions-Dark.svg" /></a>&nbsp;<a href="https://www.typescriptlang.org/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/TypeScript.svg" /></a>&nbsp;<a href="https://nodejs.org/en/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/NodeJS-Dark.svg" /></a>&nbsp;<a href="https://bun.sh/docs" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Bun-Dark.svg" /></a>&nbsp;<a href="https://docs.docker.com" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Docker.svg" /></a>&nbsp;<a href="https://www.postgresql.org/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/PostgreSQL-Dark.svg" /></a>&nbsp;<a href="https://github.com/motdotla/dotenv#readme" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Dotenv-Dark.svg" /></a>&nbsp;<a href="https://eslint.org/docs/latest/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Eslint-Dark.svg" /></a>&nbsp;<a href="https://expressjs.com/en/starter/installing.html" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/ExpressJS-Dark.svg" /></a>&nbsp;<a href="https://jestjs.io/docs/getting-started" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Jest.svg" /></a>&nbsp;<a href="https://docs.nestjs.com" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/NestJS-Dark.svg" /></a>&nbsp;<a href="https://prettier.io/docs/en/index.html" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Prettier-Dark.svg" /></a>&nbsp;<a href="https://www.prisma.io/docs/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Prisma.svg" /></a>&nbsp;<a href="https://rxjs.dev/guide/overview" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Rxjs-Dark.svg" /></a>&nbsp;<a href="https://swagger.io" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Swagger-Dark.svg" /></a>&nbsp;<a href="https://swc.rs/docs/getting-started" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Swc-Dark.svg" /></a>&nbsp;<a href="https://github.com/typestack" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/TypeStack-Dark.svg" /></a>&nbsp;<a href="https://webpack.js.org/concepts/" target="_blank"><img height="50" src="https://raw.githubusercontent.com/jpb06/jpb06/master/icons/Webpack-Dark.svg" /></a></p>

<!-- readme-package-icons end -->

## ⚡ Requirements

You will need the following to use this POC :

| Item | Description | Documentation |
| -------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------- |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/nodejs/nodejs-original.svg" /> nodejs | Duh! | <https://nodejs.org/en/> |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/docker/docker-original.svg" /> Docker | we will use docker to launch a postgres instance | <https://www.docker.com/get-started> |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/yarn/yarn-original.svg" /> yarn | We will use yarn as the package manager for this project | <https://yarnpkg.com/getting-started/install> |
| Item | Description | Documentation |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------ |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/nodejs/nodejs-original.svg" /> nodejs | Duh! | <https://nodejs.org/en/> |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/docker/docker-original.svg" /> Docker | we will use docker to launch a postgres instance | <https://www.docker.com/get-started> |
| <img height="20" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/bun/bun-original.svg" /> bun | We will use bun as the package manager for this project | <https://bun.sh/docs> |

## ⚡ How to start

Expand All @@ -45,22 +45,22 @@ chmod +x docker/pg-init-scripts/create-multiple-db.sh
Let's then use docker compose :

```bash
yarn docker
bun docker
```

### 🔶 Then we can migrate our schemas and seed the databases

```bash
yarn dev:db
bun dev:db
```

### 🔶 Launching our backends in dev mode

```bash
# Hiking app (port 5001)
yarn dev hiking-app
bun dev hiking-app
# Projects app (port 5002)
yarn dev projects-app
bun dev projects-app
```

### 🔶 Accessing apps swaggers
Expand All @@ -73,7 +73,7 @@ Now we can access the swaggers of our apps using the following urls:
### 🔶 Building our apps for production

```bash
yarn build
bun run build
```

## ⚡ Project structure
Expand Down
Binary file added bun.lockb
Binary file not shown.
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
"author": "jpb06 <[email protected]>",
"license": "MIT",
"scripts": {
"update-deps": "bunx npm-check-updates --root --format group -i",
"prebuild": "rimraf dist",
"build": "yarn build:hiking-app && yarn build:projects-app",
"build": "bun build:hiking-app && bun build:projects-app",
"build:hiking-app": "nest build hiking-app ",
"build:projects-app": "nest build projects-app",
"prisma:gen": "yarn prisma:gen:users && yarn prisma:gen:projects && yarn prisma:gen:hiking",
"prisma:migrate": "yarn prisma:migrate:users && yarn prisma:migrate:projects && yarn prisma:migrate:hiking",
"prisma:gen": "bun prisma:gen:users && bun prisma:gen:projects && bun prisma:gen:hiking",
"prisma:migrate": "bun prisma:migrate:users && bun prisma:migrate:projects && bun prisma:migrate:hiking",
"prisma:gen:users": "prisma generate --schema prisma/users/users-schema.prisma",
"prisma:gen:projects": "prisma generate --schema prisma/projects/projects-schema.prisma",
"prisma:gen:hiking": "prisma generate --schema prisma/hiking/hiking-schema.prisma",
"prisma:migrate:users": "prisma migrate dev --schema prisma/users/users-schema.prisma",
"prisma:migrate:projects": "prisma migrate dev --schema prisma/projects/projects-schema.prisma",
"prisma:migrate:hiking": "prisma migrate dev --schema prisma/hiking/hiking-schema.prisma",
"postinstall": "yarn prisma:gen",
"postinstall": "bun prisma:gen",
"docker": "docker compose down && docker compose up postgres",
"db:seed": "prisma db seed",
"dev": "nest start --watch",
"dev:db": "yarn prisma:migrate && yarn db:seed",
"dev:db": "bun prisma:migrate && bun db:seed",
"start": "nest start",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
Expand All @@ -36,7 +37,7 @@
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"type-check": "tsc --noEmit",
"sync-icons": "yarn generateReadmeIcons -h 50"
"sync-icons": "bun generateReadmeIcons -h 50"
},
"dependencies": {
"@nestjs/common": "^10.3.10",
Expand All @@ -57,8 +58,8 @@
"@nestjs/testing": "^10.3.10",
"@swc/core": "^1.6.13",
"@swc/jest": "^0.2.36",
"@types/dotenv-flow": "^3.2.0",
"@types/express": "^4.17.17",
"@types/dotenv-flow": "^3.3.3",
"@types/express": "^4.17.21",
"@types/jest": "29.5.12",
"@types/node": "^20.14.10",
"@types/supertest": "^6.0.2",
Expand All @@ -67,28 +68,28 @@
"date-fns": "^3.6.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.1.3",
"express": "^4.19.2",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.7",
"prettier": "^3.3.3",
"prisma": "^5.16.2",
"readme-package-icons": "^1.1.14",
"rimraf": "^6.0.1",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"ts-paths-transform": "^2.0.4",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.3",
"webpack": "^5.93.0"
},
"engines": {
"node": "20.x",
"yarn": "1.22.x"
"bun": "1.1.x"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
Expand Down
Loading

0 comments on commit 8bb2c2d

Please sign in to comment.