-
Notifications
You must be signed in to change notification settings - Fork 58
chore: migrate from Yarn to PNPM #1458
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
base: main
Are you sure you want to change the base?
Conversation
Migrate CI workflows, scripts, and workspaces to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the repository from Yarn v1 to PNPM to take advantage of performance and security improvements. The migration involves updating package manager references, workspace configurations, CI/CD workflows, and dependency declarations across the monorepo.
Key Changes:
- Migration from Yarn to PNPM as the package manager with workspace protocol for internal dependencies
- Updated all GitHub Actions workflows to use PNPM with proper caching setup
- Converted documentation and scripts to reference PNPM instead of Yarn
Reviewed changes
Copilot reviewed 75 out of 79 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | New PNPM workspace configuration with security settings |
| package.json | Updated packageManager field, scripts, and publish commands for PNPM |
| lerna.json | Changed npmClient from yarn to pnpm |
| packages/*/package.json | Converted dependencies to workspace:* protocol and updated scripts to use pnpm |
| .github/workflows/*.yml | Updated CI/CD workflows to use PNPM with setup-node v4 and caching |
| .husky/* | Updated git hooks to use pnpm commands |
| README.md, CONTRIBUTING.md, AGENTS.md | Updated documentation references from yarn to pnpm |
| test-server/README.md | Updated test server instructions to use pnpm |
| tsconfig.json | Removed 'idb' from types array |
| packages/*/test/tsconfig.json | Added test-specific TypeScript configs |
| packages/*/jest.config.js | Added transformIgnorePatterns for PNPM compatibility |
| packages/analytics-core/src/types/proxy.ts | New file exporting InstanceProxy type |
| packages/session-replay-browser/src/targeting/targeting-manager.ts | Bug fix for parsing string sessionId to number |
| packages/session-replay-browser/src/helpers.ts | Added explicit return type annotation |
| packages/plugin-experiment-browser/package.json | Fixed missing && operator in version script |
| Various test files | Updated imports and mocking strategies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c867195 to
5158268
Compare
a027f2a to
a22af1e
Compare
a22af1e to
7b1baaa
Compare
Mercy811
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'prerelease' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:publish -- from-git -y --ignore-scripts --pre-dist-tag ${{ env.PREID }} | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:publish -y --ignore-scripts --tag ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing -- prevents arguments from reaching pnpm scripts
The prerelease workflow passes arguments directly to pnpm scripts without --, so flags like -y, --ignore-scripts, --tag, --conventional-prerelease, and --preid won't be forwarded to the underlying lerna version or pnpm publish commands. The release version step at line 97 correctly uses pnpm deploy:version -- -y ... with --, but these three lines omit it. This will cause prerelease and dry-run workflows to fail or behave incorrectly because the lerna/pnpm commands won't receive the necessary configuration flags.
Additional Locations (2)
- @amplitude/analytics-browser@2.33.2-pnpm-migration.0 - @amplitude/analytics-client-common@2.4.20-pnpm-migration.0 - @amplitude/analytics-core@2.35.1-pnpm-migration.0 - @amplitude/analytics-node@1.5.30-pnpm-migration.0 - @amplitude/analytics-react-native@1.5.33-pnpm-migration.0 - @amplitude/analytics-types@2.11.1-pnpm-migration.0 - @amplitude/gtm-snippet@2.33.2-pnpm-migration.0 - @amplitude/plugin-autocapture-browser@1.18.4-pnpm-migration.0 - @amplitude/plugin-global-user-properties@1.2.111-pnpm-migration.0 - @amplitude/plugin-network-capture-browser@1.7.4-pnpm-migration.0 - @amplitude/plugin-page-url-enrichment-browser@0.5.10-pnpm-migration.0 - @amplitude/plugin-page-view-tracking-browser@2.6.7-pnpm-migration.0 - @amplitude/plugin-session-replay-browser@1.25.6-pnpm-migration.0 - @amplitude/plugin-session-replay-react-native@0.4.6-pnpm-migration.0 - @amplitude/plugin-web-attribution-browser@2.1.104-pnpm-migration.0 - @amplitude/plugin-web-vitals-browser@1.1.5-pnpm-migration.0 - @amplitude/segment-session-replay-plugin@0.0.0-pnpm-migration.0 - @amplitude/session-replay-browser@1.30.5-pnpm-migration.0 - @amplitude/unified@1.0.0-pnpm-migration.0
This reverts commit b6afc2a.
.github/workflows/publish-v2.yml
Outdated
| - name: Publish Release to NPM | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:publish -- ${{ env.PUBLISH_FROM }} -y --pre-dist-tag beta --loglevel silly | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:publish --ignore-scripts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publish workflow may fail for unchanged packages
The deploy:publish script changed from lerna publish to pnpm -r --filter "./packages/**" publish. The old lerna publish from-git command intelligently published only packages that received new git tags from lerna version. The new pnpm approach attempts to publish ALL public packages recursively. For packages that weren't changed (and thus not version-bumped by lerna version), npm will reject the publish with "cannot publish over existing version", causing the entire workflow to fail. This affects both the release and prerelease jobs.
Additional Locations (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. It won't publish the package if it already exists in the NPM registry. It will just skip over it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the output when it tries publishing packages that are already published:
➜ Amplitude-TypeScript git:(pnpm-migration) pnpm deploy:publish:dry-run
> @ deploy:publish:dry-run /Users/danielgraham/code/Amplitude-TypeScript
> DRY_RUN=true pnpm -r --filter "./packages/**" publish --dry-run --no-git-checks
There are no new packages that should be published
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'dry-run' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:version -- -y --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.determine-branch.outputs.branch }} --no-changelog --no-push --no-git-tag-version | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run--preid ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space causes workflow script to not be found
The command pnpm deploy:version:dry-run--preid ${{ env.PREID }} is missing a space between dry-run and --preid. This causes pnpm to look for a script named deploy:version:dry-run--preid which doesn't exist in package.json. The actual script is named deploy:version:dry-run. This will cause the dry-run workflow to fail with a "script not found" error whenever someone runs the publish workflow with releaseType: dry-run.
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'dry-run' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.determine-branch.outputs.branch }} --no-changelog --no-push --no-git-tag-version | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run--preid ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space creates invalid script name in workflow
The command pnpm deploy:version:dry-run--preid is missing a space between deploy:version:dry-run and --preid. The script deploy:version:dry-run--preid does not exist in package.json — only deploy:version:dry-run exists. This will cause the "Dry run pre-release version" workflow step to fail when releaseType is dry-run, breaking the publish dry-run functionality.
859dcdf to
003570e
Compare
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'dry-run' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.determine-branch.outputs.branch }} --no-changelog --no-push --no-git-tag-version | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run--preid ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space breaks dry-run workflow command
The command pnpm deploy:version:dry-run--preid is missing a space between dry-run and --preid. This causes pnpm to look for a non-existent script called deploy:version:dry-run--preid instead of running deploy:version:dry-run with the --preid argument. The dry-run pre-release workflow will fail when triggered.
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'dry-run' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.determine-branch.outputs.branch }} --no-changelog --no-push --no-git-tag-version | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run--preid ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space causes workflow command to fail
The command pnpm deploy:version:dry-run--preid is missing a space before --preid. This causes pnpm to try to run a non-existent script called deploy:version:dry-run--preid instead of the intended script deploy:version:dry-run with --preid as an argument. The dry-run pre-release version workflow step will fail whenever triggered.
This reverts commit db34376.
.github/workflows/publish-v2.yml
Outdated
| if: ${{ github.event.inputs.releaseType == 'dry-run' }} | ||
| run: | | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.determine-branch.outputs.branch }} --no-changelog --no-push --no-git-tag-version | ||
| GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} pnpm deploy:version:dry-run--preid ${{ env.PREID }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space causes invalid pnpm script name
The command pnpm deploy:version:dry-run--preid is missing a space between deploy:version:dry-run and --preid. This creates an invalid script name that doesn't exist in package.json, causing the dry-run pre-release workflow step to fail. The command should be pnpm deploy:version:dry-run --preid ${{ env.PREID }}.
- @amplitude/analytics-browser@2.33.2-pnpm-migration.0 - @amplitude/analytics-client-common@2.4.20-pnpm-migration.0 - @amplitude/analytics-core@2.35.1-pnpm-migration.0 - @amplitude/analytics-node@1.5.30-pnpm-migration.0 - @amplitude/analytics-react-native@1.5.33-pnpm-migration.0 - @amplitude/analytics-types@2.11.1-pnpm-migration.0 - @amplitude/gtm-snippet@2.33.2-pnpm-migration.0 - @amplitude/plugin-autocapture-browser@1.18.4-pnpm-migration.0 - @amplitude/plugin-global-user-properties@1.2.111-pnpm-migration.0 - @amplitude/plugin-network-capture-browser@1.7.4-pnpm-migration.0 - @amplitude/plugin-page-url-enrichment-browser@0.5.10-pnpm-migration.0 - @amplitude/plugin-page-view-tracking-browser@2.6.7-pnpm-migration.0 - @amplitude/plugin-session-replay-browser@1.25.6-pnpm-migration.0 - @amplitude/plugin-session-replay-react-native@0.4.6-pnpm-migration.0 - @amplitude/plugin-web-attribution-browser@2.1.104-pnpm-migration.0 - @amplitude/plugin-web-vitals-browser@1.1.5-pnpm-migration.0 - @amplitude/segment-session-replay-plugin@0.0.0-pnpm-migration.0 - @amplitude/session-replay-browser@1.30.5-pnpm-migration.0 - @amplitude/unified@1.0.0-pnpm-migration.0
| "deploy:version": "lerna version", | ||
| "deploy:publish": "lerna publish", | ||
| "deploy:version:dry-run": "DRY_RUN=true lerna version --no-push --no-git-tag-version --allow-branch \"$(git rev-parse --abbrev-ref HEAD)\" --conventional-prerelease --no-changelog --no-push --no-git-tag-version", | ||
| "deploy:publish": "pnpm -r --filter \"./packages/**\" publish", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Release workflow may fail publishing unchanged packages
The deploy:publish script changed from lerna publish to pnpm -r --filter "./packages/**" publish. The old lerna publish command supported from-git mode (used in the v1 workflow to publish only packages with new git tags after lerna version). The new pnpm command publishes ALL packages unconditionally. When lerna version bumps only changed packages, then pnpm publish runs on all packages, unchanged packages will fail because their versions already exist on npm. The workflow comment at line 184 of publish-v2.yml still references "Use 'from git' option" but this behavior is no longer implemented.
5380682 to
cc96e65
Compare
cc96e65 to
66ffd36
Compare
| "test:mobile": "jest --setupFiles './test/mock/setup-mobile.ts'", | ||
| "typecheck": "tsc -p ./tsconfig.json", | ||
| "version": "yarn version-file && yarn build", | ||
| "version": "pnpm version-file && pnpm build", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete migration leaves yarn commands in scripts
The Yarn to PNPM migration is incomplete. The example scripts in three React Native packages still use yarn commands (yarn --cwd example and yarn workspace ...) while other scripts in the same files were updated to use pnpm. After migration, if Yarn is not installed or Corepack enforces the pnpm packageManager, running pnpm example in these packages will fail because the underlying command still invokes yarn.
Additional Locations (2)
| "deploy:version": "lerna version", | ||
| "deploy:publish": "lerna publish", | ||
| "deploy:version:dry-run": "DRY_RUN=true lerna version --no-push --no-git-tag-version --allow-branch \"$(git rev-parse --abbrev-ref HEAD)\" --conventional-prerelease --no-changelog --no-push --no-git-tag-version", | ||
| "deploy:publish": "pnpm -r --filter \"./packages/**\" publish", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prerelease publish command uses incompatible lerna arguments
The deploy:publish script was changed from lerna publish to pnpm -r --filter \"./packages/**\" publish. However, the prerelease publish step in publish-v2.yml (line 188) still calls npm run deploy:publish -- from-git -y --ignore-scripts --pre-dist-tag ${{ env.PREID }}. These are lerna-specific arguments (from-git, --ignore-scripts, --pre-dist-tag) that pnpm's recursive publish command doesn't understand. This will cause the prerelease workflow to fail when triggered.
Summary
We're migrating from Yarn to PNPM to take advantage of performance and security enhancements that PNPM provides. And because Yarn v1 has been in maintenance mode for ~6 years
Made a test pre-release called



@amplitude/analytics-browser@2.33.2-pnpm-migration.0and tested it locallyChecklist
Note
Monorepo migration to pnpm
pnpmacross scripts, Husky hooks, docs, andlerna.json(npmClient: pnpm); addpnpmsetup/caching in all GitHub Actions (CI, docs, e2e, publish)pnpm(versioning, publish, dry-run) and adjust caching topnpm-lock.yamlPackage and dependency alignment
workspace:*; replace imports fromanalytics-types/analytics-client-commonwithanalytics-corein packages/teststransformIgnorePatternsfor pnpm, test tsconfig files, and minor build script tweaksCore and session replay tweaks
InstanceProxyfromanalytics-core; add proxy typessessionIdparsed to number in targeting; add test; tighten types ingetDebugConfigMisc
Written by Cursor Bugbot for commit d8c094d. This will update automatically on new commits. Configure here.