Skip to content

Commit

Permalink
build: Migrate from yarn to pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Feb 26, 2024
1 parent 3fe20dd commit 4ffa87a
Show file tree
Hide file tree
Showing 16 changed files with 8,701 additions and 10,678 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 21
cache: "yarn"
cache-dependency-path: "yarn.lock"
cache: "pnpm"
- name: Install deps
env:
PUPPETEER_SKIP_DOWNLOAD: true
run: yarn install --immutable
- name: Lint
run: yarn lint
run: pnpm install
- name: Format
run: yarn format:check
run: pnpm format:check
- name: Lint
run: pnpm lint
- name: Build the workers package
working-directory: packages/workers
run: yarn typecheck
run: pnpm typecheck
- name: Build web app
working-directory: packages/web
run: yarn run build
run: pnpm run build
- name: Build the browser extension
working-directory: packages/browser-extension
run: yarn build
run: pnpm build
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ build
coverage
.vscode*
node_modules
dist
*.md
*.json
.env
.env.*
**/migrations/**

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ You can turnup the whole development environment with:

Or if you have nodejs installed locally, you can do:

- `yarn install` in the root of the repo.
- `yarn db:migrate` to run the db migrations.
- `yarn web` to start the web app.
- `pnpm install` in the root of the repo.
- `pnpm db:migrate` to run the db migrations.
- `pnpm web` to start the web app.
- Access it over `http://localhost:3000`.
- `yarn workers` to start the crawler and the openai worker.
- `pnpm workers` to start the crawler and the openai worker.
- You'll need to have redis running at `localhost:5379` (configurable with env variables).
- An easy way to get redis running is by using docker `docker run -p 5379:5379 redis`.
- You can run the web app without the workers, but link fetching and automatic tagging won't work.
Expand All @@ -106,4 +106,4 @@ Or if you have nodejs installed locally, you can do:

### Submitting PRs

- Before submitting PRs, you'll want to run `yarn format` and include its changes in the commit. Also make sure `yarn lint` is successful.
- Before submitting PRs, you'll want to run `pnpm format` and include its changes in the commit. Also make sure `pnpm lint` is successful.
65 changes: 28 additions & 37 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
################# The Web App ##############
################# Base Builder ##############
FROM node:21-alpine AS base

# Rebuild the source code only when needed
FROM node:21-alpine AS web_builder
WORKDIR /app
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app
COPY packages/db packages/db
COPY packages/web packages/web
COPY packages/shared packages/shared
COPY package.json yarn.lock .yarnrc.yml .
RUN apk add --no-cache libc6-compat make g++ py3-pip linux-headers

COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
ENV PUPPETEER_SKIP_DOWNLOAD true
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

################# The Web builder ##############

# Rebuild the source code only when needed
FROM base AS web_builder

WORKDIR /app/packages/web

RUN pnpm next experimental-compile

RUN corepack enable && \
cd /app/packages/web/ && \
yarn install --immutable && \
yarn next experimental-compile
################# The Web App ##############

FROM node:21-alpine AS web
WORKDIR /app
Expand Down Expand Up @@ -51,22 +56,9 @@ CMD ["node", "server.js"]

################# The workers builder ##############

FROM node:21-alpine AS workers_builder
WORKDIR /app

# Install chromium needed for puppeteer
RUN apk add --no-cache make g++ py3-pip linux-headers

COPY packages/db/package.json packages/db/package.json
COPY packages/shared/package.json packages/shared/package.json
COPY packages/workers/package.json packages/workers/package.json
COPY package.json yarn.lock .yarnrc.yml .
ENV PUPPETEER_SKIP_DOWNLOAD true

RUN corepack enable && \
cd /app/packages/workers && \
yarn workspaces focus --production
FROM base AS workers_builder

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm deploy --filter @hoarder/workers --prod /prod

################# The workers ##############

Expand All @@ -79,16 +71,15 @@ ENV CHROME_PATH "/usr/bin/chromium-browser"
ENV BROWSER_EXECUTABLE_PATH "/app/start-chrome.sh"
ENV BROWSER_USER_DATA_DIR="/tmp/chrome"

ADD docker/start-chrome.sh .
RUN chmod +x /app/start-chrome.sh
COPY --from=workers_builder /prod packages/workers

COPY packages/db packages/db
COPY packages/shared packages/shared
COPY packages/workers packages/workers
COPY package.json yarn.lock .yarnrc.yml .
COPY --from=workers_builder /app/node_modules /app/node_modules
RUN corepack enable

ADD docker/start-chrome.sh .
RUN chmod +x start-chrome.sh

WORKDIR /app/packages/workers

USER root

CMD ["yarn", "run", "start:prod"]
CMD ["pnpm", "run", "start:prod"]
6 changes: 3 additions & 3 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
REDIS_HOST: redis
DATABASE_URL: "file:/data/db.db"
command:
- yarn
- pnpm
- web
working_dir: /app
depends_on:
Expand All @@ -34,7 +34,7 @@ services:
DATABASE_URL: "file:/data/db.db"
# OPENAI_API_KEY: ...
command:
- yarn
- pnpm
- workers
depends_on:
prep:
Expand All @@ -51,7 +51,7 @@ services:
command:
- /bin/sh
- -c
- "corepack enable && yarn install --immutable && yarn run db:migrate"
- "corepack enable && pnpm install --frozen-lockfile && pnpm run db:migrate"

volumes:
redis:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
command:
- /bin/sh
- -c
- "cd /app/packages/db && yarn run migrate"
- "cd /app/packages/db && pnpm run migrate"

volumes:
redis:
Expand Down
4 changes: 0 additions & 4 deletions docker/yarn.lock

This file was deleted.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
"name": "hoarder",
"version": "0.1.0",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"format": "prettier . --write",
"format:check": "prettier . --check",
"lint": "eslint .",
"db:migrate": "yarn workspace @hoarder/db run migrate",
"db:studio": "yarn workspace @hoarder/db studio",
"workers": "yarn workspace @hoarder/workers run start",
"web": "yarn workspace @hoarder/web run dev"
"db:migrate": "pnpm --filter @hoarder/db run migrate",
"db:studio": "pnpm --filter @hoarder/db studio",
"workers": "pnpm --filter @hoarder/workers run start",
"web": "pnpm --filter @hoarder/web run dev"
},
"dependencies": {
"@next/eslint-plugin-next": "^14.1.0",
Expand All @@ -37,5 +34,5 @@
"prettier": "3.2.5",
"prettier-plugin-tailwindcss": "^0.5.11"
},
"packageManager": "yarn@4.1.0"
"packageManager": "pnpm@8.15.4+sha256.cea6d0bdf2de3a0549582da3983c70c92ffc577ff4410cbf190817ddc35137c2"
}
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"studio": "drizzle-kit studio"
},
"dependencies": {
"@auth/drizzle-adapter": "^0.7.0",
"@auth/core": "^0.27.0",
"@paralleldrive/cuid2": "^2.2.2",
"better-sqlite3": "^9.4.3",
"drizzle-orm": "^0.29.4"
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"winston": "^3.11.0"
"winston": "^3.11.0",
"zod": "^3.22.4"
},
"main": "index.ts"
}
3 changes: 3 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
},
"dependencies": {
"@hoarder/db": "0.1.0",
"@hoarder/shared": "0.1.0",
"@auth/drizzle-adapter": "^0.7.0",
"@hookform/resolvers": "^3.3.4",
"@next/eslint-plugin-next": "^14.1.0",
"@radix-ui/react-dialog": "^1.0.5",
Expand All @@ -27,6 +29,7 @@
"@trpc/react-query": "^11.0.0-next-beta.289",
"@trpc/server": "11.0.0-next-beta.274",
"bcrypt": "^5.1.1",
"better-sqlite3": "^9.4.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"drizzle-orm": "^0.29.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@hoarder/db": "0.1.0",
"@hoarder/shared": "0.1.0",
"@hoarder/db": "workspace:*",
"@hoarder/shared": "workspace:*",
"@tsconfig/node21": "^21.0.1",
"async-mutex": "^0.4.1",
"bullmq": "^5.1.9",
Expand Down
Loading

0 comments on commit 4ffa87a

Please sign in to comment.