Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Yarn Workspaces + Lerna with pnpm #803

Merged
merged 30 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7e696b9
chore: add watch script to build core
raulfdm Oct 10, 2021
86a9388
chore: adapt workflow for using pnpm
raulfdm Oct 22, 2021
2fa6d89
chore: delete yarn.lock
raulfdm Oct 22, 2021
b2cb70a
feat: setup base pnpm config
raulfdm Oct 22, 2021
05bfbc1
chore: remove lerna
raulfdm Oct 22, 2021
413ff55
chore(temp): comment out workflows
raulfdm Oct 22, 2021
547c92f
chore: remove root scripts
raulfdm Oct 22, 2021
b986e0c
chore: regen lock file
raulfdm Oct 22, 2021
2668400
refactor: cms side
raulfdm Oct 22, 2021
0ade79a
ci: install deps via shamefully-hoist
raulfdm Oct 22, 2021
e445f8d
chore: commit .npmrc
raulfdm Oct 22, 2021
cf42f16
refactor(lambdas): scripts
raulfdm Oct 22, 2021
dd3c507
ci: remove temp branch
raulfdm Oct 22, 2021
31fd3cb
chore(cms): install with frozen lockfile
raulfdm Oct 22, 2021
3b457f8
chore: add phantom dependency
raulfdm Oct 22, 2021
6b083f6
refactor: website workflow
raulfdm Oct 23, 2021
383e410
ci: remove build package
raulfdm Oct 23, 2021
565e81f
ci: add missing install deps step
raulfdm Oct 23, 2021
501896a
ci: build dependencies of website
raulfdm Oct 23, 2021
c8acd0d
chore: remove tsc from website lint
raulfdm Oct 23, 2021
a35fcba
refactor: adjust packages workflow
raulfdm Oct 23, 2021
b945d57
ci: install missing deps
raulfdm Oct 23, 2021
ca8f160
chore: clean up yarn/lerna
raulfdm Oct 23, 2021
49c1065
chore: add missing package
raulfdm Oct 23, 2021
fbcf28e
chore: remove npmrc sample
raulfdm Oct 23, 2021
d9d5c5e
chore: add changeset
raulfdm Oct 23, 2021
5d31438
chore: remove semantic release packages in favor of changesets
raulfdm Oct 23, 2021
784016c
chore: add back release steps
raulfdm Oct 23, 2021
8e526a8
chore: add watch script to build core
raulfdm Oct 10, 2021
387d466
Merge branch 'main' into test-pnpm-workspace
raulfdm Oct 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
10 changes: 10 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://unpkg.com/@changesets/config@1.6.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
6 changes: 4 additions & 2 deletions .github/workflows/cms-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ on:
- main
paths:
- 'apps/cms/**'
- 'scripts/**'
- 'config/**'
- '.github/workflows/cms-deploy.yml'
- package.json
- pnpm-lock.yaml

jobs:
deploy:
Expand Down Expand Up @@ -51,7 +51,9 @@ jobs:
run: |
echo "machine api.heroku.com\n login melo.raulf@gmail.com\n password $HEROKU_API_KEY\nmachine git.heroku.com\n login melo.raulf@gmail.com\n password $HEROKU_API_KEY" >> ~/.netrc

yarn global add heroku
npm install -g heroku
npm install -g pnpm

heroku container:login

docker tag raulfdm/raulmelo.dev-cms:latest registry.heroku.com/raulmelo-dev-server/web
Expand Down
25 changes: 15 additions & 10 deletions .github/workflows/lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
paths:
- 'apps/lambdas/**'
- 'scripts/**'
- 'config/**'
- '.github/workflows/lambdas.yml'
- .eslintignore
Expand All @@ -23,25 +22,31 @@ jobs:
with:
node-version: '14'

- name: Install lerna and netlify
run: yarn global add lerna netlify-cli
- name: Install pnpm and netlify
run: npm install -g netlify-cli pnpm

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Cache pnpm modules
uses: actions/cache@v2
with:
useRollingCache: true
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-

- name: Install dependencies
run: pnpm i --frozen-lockfile

- name: Lint Projects
run: yarn lint --scope=lambdas
run: pnpm run lint --filter lambdas

- name: Test Projects
run: yarn test --scope=lambdas
run: pnpm run test --filter lambdas

- name: Build Projects
run: yarn build --scope=lambdas
run: pnpm run build --filter lambdas...

- name: Deploy
run: yarn deploy --scope=lambdas
run: pnpm run deploy --filter lambdas
if: contains('refs/heads/main', github.ref)
env:
NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}}
Expand Down
85 changes: 63 additions & 22 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,87 @@ on:
- package.json
- commitlint.config.js

env:
CI: true
PNPM_CACHE_FOLDER: .pnpm-store

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: 0

- name: Use Node
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install lerna and netlify
run: yarn global add lerna netlify-cli
- name: Install pnpm
run: npm install -g pnpm

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Cache pnpm modules
uses: actions/cache@v2
with:
useRollingCache: true
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-

- name: Install dependencies
run: pnpm i --frozen-lock --filter {packages/}

- name: Lint Projects
run: yarn lint --scope=mdx-prism-2 --scope=@raulfdm/core
run: pnpm run lint --filter {packages/}

- name: Test Projects
run: yarn test --scope=mdx-prism-2 --scope=@raulfdm/core
run: pnpm run test --filter {packages/}

- name: Build Projects
run: yarn build --scope=mdx-prism-2 --scope=@raulfdm/core

- name: Release Packages
run: |
git config --global user.name "Raul Melo"
git config --global user.email "melo.raulf@gmail.com"
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ./.npmrc
git reset --hard
yarn release
if: github.ref == 'refs/heads/main'
run: pnpm run build --filter {packages/}

release:
if: github.ref == 'refs/heads/main'
needs: [build]
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: setup node.js
uses: actions/setup-node@v2
with:
node-version: 14

- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-

- name: install pnpm
run: npm i pnpm@latest -g

- name: Setup npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc

- name: setup pnpm config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER

- name: install dependencies
run: pnpm install --frozen-lock --filter mdx-prism-2

- name: create and publish versions
uses: changesets/action@master
with:
version: pnpm ci:version
commit: 'chore: update versions'
title: 'chore: update versions'
publish: pnpm ci:publish
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
GH_TOKEN: ${{secrets.GH_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 15 additions & 10 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ jobs:
with:
node-version: '14'

- name: Install lerna
run: yarn global add lerna
- name: Install pnpm
run: npm install -g pnpm

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Cache pnpm modules
uses: actions/cache@v2
with:
useRollingCache: true
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-

# Necessary because it's being used in the code
- name: Build packages
run: yarn build --scope=@raulfdm/core
- name: Install dependencies
run: pnpm i --frozen-lockfile

- name: Build dependents packages
run: pnpm run build --filter "website^..."

- name: Lint Projects
run: yarn lint --scope=website
run: pnpm run lint --filter website

- name: Test Projects
run: yarn test --scope=website
run: pnpm run test --filter website
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
node_modules
.history/
yarn-error.log
lerna-debug.log

.npmrc
.env

.vercel
5 changes: 0 additions & 5 deletions .husky/commit-msg

This file was deleted.

2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

. "$(dirname "$0")/_/husky.sh"

yarn pretty-quick --staged
pnpm pretty-quick --staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist​=true
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ apps/cms/api/**/*.json
apps/cms/extensions/**/*.json
apps/cms/config/**/*.json
apps/cms/components/**/*.json
apps/cms/exports/graphql/schema.graphql
apps/cms/exports/graphql/schema.graphql

## PNPM
pnpm-lock.yaml
25 changes: 0 additions & 25 deletions .releaserc.js

This file was deleted.

11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ Each project/package uses different technologies because they have different pur

For the root level I'm using:

- [Lerna](https://lerna.js.org/) + [Yarn Workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) - Maintain this Monorepo
- [TypeScript](https://www.typescriptlang.org/) - core programming language
- [scripty](https://www.npmjs.com/package/scripty) - Run npm scripts with bash files
- [Babel](https://babeljs.io/) - Parse and bundle together with TSC
- [commitlint](https://commitlint.js.org/#/) - Ensure commit consistency
- [pnpm + pnp workspaces](https://pnpm.io/) - Maintain this Monorepo;
- [changesets](https://github.com/atlassian/changesets) - Automation for package release and changelog;
- [TypeScript](https://www.typescriptlang.org/) - core programming language;
- [scripty](https://www.npmjs.com/package/scripty) - Run npm scripts with bash files;

## Structure

Expand All @@ -34,8 +33,6 @@ I might need to run a specific workflow for each package/app. Doing that with np

This helper allows me to use an executable file (e.g. `bash` or `node exec`) to determine what needs to happen.

In that sense, I have workspace level scripts which are most scripts that call `lerna` to run `build`, `lint`, etc. In general, commands would be generic for everyone.

Then I have per package/app script which calls whatever they need in other to make it work (e.g. `nextjs cli`, `tsdx cli`, etc.). For some commands, they can refer to a common script (e.g. `lint` and `test`) in the root level script if they don't need to do anything special for these commands.

## Pipeline
Expand Down
13 changes: 7 additions & 6 deletions apps/cms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ WORKDIR /app
EXPOSE 1337

COPY package.json .
COPY yarn.lock .
COPY lerna.json .
COPY scripts/ ./scripts/
COPY pnpm-lock.yaml .
COPY pnpm-workspace.yaml .
COPY apps/cms ./apps/cms

RUN yarn
RUN npm install -g pnpm

RUN yarn build --scope=cms
RUN pnpm i --frozen-lockfile --shamefully-hoist --filter cms

RUN pnpm run build --filter cms

VOLUME [ "${PWD}/apps/cms/build:/app/build" ]

CMD [ "yarn", "start", "--scope=cms" ]
CMD [ "pnpm", "run", "start", "--filter", "cms" ]
2 changes: 1 addition & 1 deletion apps/cms/Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: yarn start
web: pnpm run start --filter cms
2 changes: 1 addition & 1 deletion apps/cms/admin/admin.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
webpack: (config) => {
/**
* This workaround is necessary because within lerna/monorepo setup,
* This workaround is necessary because within monorepo setup,
* some dependencies could not being resolved naturally like:
*
* strapi-admin/node_modules/formik.
Expand Down
3 changes: 0 additions & 3 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"name": "cms",
"private": true,
"version": "1.0.0",
"engines": {
"yarn": "1.x"
},
"scripts": {
"build": "scripty",
"clean": "scripty",
Expand Down
4 changes: 2 additions & 2 deletions apps/cms/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

echo "Building..."
yarn strapi build
echo "Building CMS"
pnpm strapi build
4 changes: 2 additions & 2 deletions apps/cms/scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

echo "Dev server..."
yarn strapi develop
echo "Starting CMS dev server"
pnpm strapi develop
Loading