Skip to content

Commit

Permalink
chore: migrate from npm to pnpm (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
fityannugroho authored Nov 20, 2024
1 parent 5117b80 commit 769dd47
Show file tree
Hide file tree
Showing 8 changed files with 4,644 additions and 11,371 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install modules
run: npm ci
run: pnpm install

- name: Check code formatting
run: npm run lint
run: pnpm run lint

- name: Generate Prisma Client
run: npm run prisma:gen
run: pnpm run prisma:gen

- name: Build
run: npm run build
run: pnpm run build

- name: Run unit tests
run: npm run test
run: pnpm run test
20 changes: 13 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Cache Node.js modules
uses: actions/cache@v4
Expand All @@ -76,22 +82,22 @@ jobs:
${{ runner.os }}-node-${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
run: pnpm install

- name: Run linting
run: npm run lint
run: pnpm run lint

- name: Run database migrations
run: npm run db:migrate
run: pnpm run db:migrate

- name: Run database seed
run: npm run db:seed
run: pnpm run db:seed

- name: Build the app
run: npm run build
run: pnpm run build

- name: Run unit tests
run: npm run test
run: pnpm run test

- name: Run e2e tests
run: npm run test:e2e
run: pnpm run test:e2e
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
To ensure consistency throughout the source code, keep these rules in mind as you are working:

- All features or bug fixes must be tested by one or more specs (unit-tests).
- We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html), but wrap all code at 100 characters. An automated formatter is available (`npm run lint:fix`).
- We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html), but wrap all code at 100 characters. An automated formatter is available (`pnpm run lint:fix`).

## Commit Message Guidelines

Expand Down
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
# Use an official Node.js runtime as the base image
FROM node:18 AS builder

# Install pnpm
RUN npm install -g pnpm

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Copy package.json and pnpm-lock.yaml to the working directory
COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma/

# Install the app dependencies
RUN npm install
RUN pnpm install

# Copy the rest of the application code
COPY . .

# Run the prisma generator
RUN npm run prisma:gen
RUN pnpm run prisma:gen

# Build the application
RUN npm run build
RUN pnpm run build

# Stage 2: A minimal Docker image with node and compiled app
FROM node:18

# Install pnpm
RUN npm install -g pnpm

# Set the working directory inside the container
WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/tsconfig.* ./
Expand All @@ -37,4 +44,4 @@ COPY --from=builder /app/common ./common
EXPOSE 3000

# Start the application in production mode
CMD ["npm", "run", "start:prod"]
CMD ["pnpm", "run", "start:prod"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
env_file:
- .env
# Run migrations after the app is ready
command: sh -c "npm run db:migrate && npm run db:seed && npm run start:prod"
command: sh -c "pnpm run db:migrate && pnpm run db:seed && pnpm run start:prod"

db:
image: postgres:14
Expand Down
16 changes: 8 additions & 8 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
## Prerequisite

- [Node.js](https://nodejs.org/en) (version 18 or higher)
- [npm](https://www.npmjs.com)
- [pnpm](https://pnpm.io)
- Database provider you want to use. We currently support MongoDB, PostgreSQL, MySQL, and SQLite.

## Installation Steps
Expand All @@ -23,7 +23,7 @@

1. Install the dependencies

Use `npm install` command, to install all the dependencies.
Use `pnpm install` command, to install all the dependencies.

1. Configure the environment variables

Expand All @@ -47,18 +47,18 @@
1. Generate the database

Run **`npm run db:migrate`** command to generate the database.
Run **`pnpm run db:migrate`** command to generate the database.

> You can use `npx prisma migrate deploy` command to run migration in **non-development environments** and if you are using any database providers **other than MongoDB**.
> See the details [here](https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-deploy).
1. Seed the data

Run **`npm run db:seed`** command to seed the data.
Run **`pnpm run db:seed`** command to seed the data.

1. Run the app

Use `npm run start` command, to run the app.
Use `pnpm run start` command, to run the app.

### Installation with Docker

Expand All @@ -82,11 +82,11 @@ To run the test, you can use the following command:

```shell
# Run unit tests
npm run test
pnpm run test

# Run e2e test
npm run test:e2e
pnpm run test:e2e

# Run coverage test
npm run test:cov
pnpm run test:cov
```
Loading

0 comments on commit 769dd47

Please sign in to comment.