Skip to content

Migrate from yarn to pnpm and drop lerna in the process#1931

Merged
tdeekens merged 24 commits intomasterfrom
yarn-to-pnpm
Mar 17, 2025
Merged

Migrate from yarn to pnpm and drop lerna in the process#1931
tdeekens merged 24 commits intomasterfrom
yarn-to-pnpm

Conversation

@tdeekens
Copy link
Contributor

@tdeekens tdeekens commented Mar 7, 2025

Summary

This migrates from yarn to pnpm which we adopted across repositories. It's speedier for installs are more strict about dependency resolution.

At the same time we can drop lerna in the process and replace it with manypkg which enforces dependency rules across the repository.

@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2025

🦋 Changeset detected

Latest commit: 8f7de67

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@commercetools/sdk-middleware-correlation-id Major
@commercetools/sdk-middleware-user-agent Major
@commercetools/csv-parser-discount-code Major
@commercetools/customer-groups-exporter Major
@commercetools/custom-objects-exporter Major
@commercetools/custom-objects-importer Major
@commercetools/discount-code-generator Major
@commercetools/discount-code-exporter Major
@commercetools/discount-code-importer Major
@commercetools/personal-data-erasure Major
@commercetools/sdk-middleware-logger Major
@commercetools/inventories-exporter Major
@commercetools/product-json-to-xlsx Major
@commercetools/sdk-middleware-queue Major
@commercetools/api-request-builder Major
@commercetools/product-json-to-csv Major
@commercetools/sdk-middleware-auth Major
@commercetools/sdk-middleware-http Major
@commercetools/category-exporter Major
@commercetools/csv-parser-orders Major
@commercetools/csv-parser-price Major
@commercetools/csv-parser-state Major
@commercetools/product-exporter Major
@commercetools/resource-deleter Major
@commercetools/get-credentials Major
@commercetools/http-user-agent Major
@commercetools/price-exporter Major
@commercetools/state-importer Major
@commercetools/sync-actions Major
@commercetools/sdk-client Major
@commercetools/sdk-types Major
@commercetools/sdk-auth Major
@commercetools/integration-tests Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines -6 to -42
- &restore_yarn_cache_node_18
keys:
- v1-yarn-cache-node_18-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v1-yarn-cache-node_18-{{ .Branch }}
- v1-yarn-cache-node_18

- &save_yarn_cache_node_18
key: v1-yarn-cache-node_18-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn


- &restore_yarn_cache_node_20
keys:
- v1-yarn-cache-node_20-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v1-yarn-cache-node_20-{{ .Branch }}
- v1-yarn-cache-node_20

- &save_yarn_cache_node_20
key: v1-yarn-cache-node_20-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn

- &restore_yarn_cache_node_22
keys:
- v1-yarn-cache-node_22-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v1-yarn-cache-node_22-{{ .Branch }}
- v1-yarn-cache-node_22

- &save_yarn_cache_node_22
key: v1-yarn-cache-node_22-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn

- &yarn_install
name: Installing
command: yarn --frozen-lockfile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify large parts of this:

  1. We don't need a cache per Node.js version. Package managers don't install differently based on Node.js versions
  2. We can migrate this into a command. That way it's native to CircleCI and validated by its language server also locally

working_directory: *working_directory

commands:
pnpm_install:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the command to replace everything above.

- run: *yarn_install
- save_cache: *save_yarn_cache_node_18
- pnpm_install
- run:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest not to build as a post install. It's not needed and frustrating. If we don't do that we must do it here.

Comment on lines -29 to -47
- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v2
- name: Install pnpm
uses: pnpm/action-setup@v4.1.0
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
run_install: false

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v4
- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v4
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large parts here can be offloaded to the action-setup.

@@ -0,0 +1 @@
pnpm commitlint --edit $1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Husky has to be updated in the process. It has now files here instead of a global config file.

"clean": "rm -rf coverage; manypkg exec rimraf lib dist node_modules; rm -rf node_modules",
"commit": "git-cz",
"build": "lerna run build --no-private",
"build": "pnpm --recursive run build",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnpm has this which allows us to drop lerna.

"packages/*"
],
"dependencies": {
"resolutions": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just formatting.

"chalk": "3.0.0"
},
"packageManager": "pnpm@9.15.6",
"devDependencies": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi important: root package.json files should not contain deps but devDeps. We use things in there for development.

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to maintain than an inline run script.

"target": "esnext",
"allowJs": false,
"baseUrl": ".",
"skipLibCheck": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed at the moment for one package. I don't see a major downside. I plan to enable this later again.

@tdeekens tdeekens force-pushed the yarn-to-pnpm branch 3 times, most recently from c17fb85 to 4269cf9 Compare March 7, 2025 12:51
@tdeekens tdeekens marked this pull request as ready for review March 7, 2025 12:57
Base automatically changed from nodejs-v18 to master March 7, 2025 13:20
@codecov
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

Attention: Patch coverage is 99.25373% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.76%. Comparing base (245eaf3) to head (8f7de67).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
packages/sdk-auth/src/auth.js 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1931      +/-   ##
==========================================
+ Coverage   94.65%   97.76%   +3.10%     
==========================================
  Files         148      147       -1     
  Lines        5105     4779     -326     
  Branches     1380     1277     -103     
==========================================
- Hits         4832     4672     -160     
+ Misses        270      104     -166     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tdeekens tdeekens requested a review from Copilot March 7, 2025 16:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR migrates the project from yarn to pnpm while also dropping lerna in favor of a new dependency management strategy. Key changes include updating changesets, CircleCI configurations, GitHub release workflows, and contributing documentation to reflect the migration.

Reviewed Changes

File Description
.changeset/silver-tips-serve.md Adds a changeset specifying major version bumps for several packages.
.circleci/config.yml Replaces yarn commands and cache logic with pnpm alternatives in CI pipelines.
.github/workflows/release.yml Updates the release workflow to use pnpm for dependency installation, building, and publishing.
CONTRIBUTING.md Revises installation and command instructions to use pnpm, though still retains a reference to lerna.
husky.config.js Removes the husky configuration, potentially impacting commit hooks management.

Copilot reviewed 97 out of 97 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

husky.config.js:1

  • The husky.config.js file has been removed; if commit hooks are still needed, please ensure they are configured elsewhere and update the documentation accordingly.
module.exports = {

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@islam3zzat islam3zzat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clearly involved a great deal of effort, thank you so much!

Comment on lines +82 to +85
command: pnpm test:ci
- run:
name: Running test (with coverage report)
command: yarn test:ci
command: pnpm test:ci
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we used to run the tests twice!

@tdeekens tdeekens merged commit ccb7812 into master Mar 17, 2025
9 checks passed
@tdeekens tdeekens deleted the yarn-to-pnpm branch March 17, 2025 12:56
@ct-changesets ct-changesets bot mentioned this pull request Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants