From f493de9b0b92e06612f9755ef8ce78f41adc7478 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Sat, 21 Nov 2026 10:46:04 +0000 Subject: [PATCH] Support pnpm via `pnpm import` from yarn.lock Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README. The workspace file also sets `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. pnpm 11+ also fails the install over a dependency's unapproved build script, and with #2270 none has one. Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes. Changelog: Internal Test plan: On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`. `flow check` passes under pnpm 12.15.0 and under Yarn. --- .gitignore | 3 +++ README.md | 11 +++++++++++ pnpm-workspace.yaml | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 pnpm-workspace.yaml diff --git a/.gitignore b/.gitignore index 59c88033c8..5519202f13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .eslintcache /node_modules /packages/*/node_modules/ +/private/*/node_modules/ +# yarn.lock is the source of truth, pnpm-lock.yaml is generated by `pnpm import` +pnpm-lock.yaml /coverage /reports npm-debug.log* diff --git a/README.md b/README.md index 4ecddd9069..827917e5ef 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,17 @@ Meta has adopted a Code of Conduct that we expect project participants to adhere Read our [contributing guide](https://github.com/react/metro/blob/main/CONTRIBUTING.md) to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes to Metro. +### Package managers + +Metro is developed with Yarn (v1), and `yarn.lock` is the source of truth for dependency versions - commit changes to `yarn.lock`, not `pnpm-lock.yaml`. + +pnpm is also supported, by generating a (git-ignored) `pnpm-lock.yaml` from `yarn.lock`: + +```sh +pnpm import +pnpm install --frozen-lockfile +``` + ### Discussions Larger discussions and proposals concerning React Native and Metro are discussed in [**@react-native-community/discussions-and-proposals**](https://github.com/react-native-community/discussions-and-proposals). diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000000..50fb6c40c4 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,7 @@ +packages: + - packages/* + - private/* + +# Metro's packages depend on each other by exact version - link them locally +# rather than fetching them from npm. +linkWorkspacePackages: true