Skip to content

Commit a0a3d2f

Browse files
committed
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.
1 parent 3861b47 commit a0a3d2f

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.eslintcache
22
/node_modules
33
/packages/*/node_modules/
4+
/private/*/node_modules/
5+
# yarn.lock is the source of truth, pnpm-lock.yaml is generated by `pnpm import`
6+
pnpm-lock.yaml
47
/coverage
58
/reports
69
npm-debug.log*

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ Meta has adopted a Code of Conduct that we expect project participants to adhere
3636

3737
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.
3838

39+
### Package managers
40+
41+
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`.
42+
43+
pnpm is also supported, by generating a (git-ignored) `pnpm-lock.yaml` from `yarn.lock`:
44+
45+
```sh
46+
pnpm import
47+
pnpm install --frozen-lockfile
48+
```
49+
3950
### Discussions
4051

4152
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).

‎pnpm-workspace.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
packages:
2+
- packages/*
3+
- private/*
4+
5+
# Metro's packages depend on each other by exact version - link them locally
6+
# rather than fetching them from npm.
7+
linkWorkspacePackages: true

0 commit comments

Comments
 (0)