Skip to content

Commit ea64219

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 two things. `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.87.1"` from npm, which fails after a version bump that isn't published yet. `allowBuilds` declines `core-js-pure`'s postinstall (a funding banner) - otherwise pnpm 11+ fails the install with `ERR_PNPM_IGNORED_BUILDS`. Not covered yet: Flow never finishes crawling pnpm's `node_modules` (`flow ls` was still going after 5 minutes, vs ~23k files with Yarn's layout). Ignoring the cross-linked workspace packages didn't help, so I've noted it in the README for now. Changelog: Internal Test plan: On a fresh export of this stack, with each of pnpm 11.28.8 and 12.15.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 (155 suites, 2856 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`. Without `allowBuilds`, `pnpm install` exits 1 on both versions.
1 parent 9dba9af commit ea64219

3 files changed

Lines changed: 26 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ 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+
50+
Flow (`typecheck`) doesn't yet work with pnpm's `node_modules` layout, so use Yarn for that.
51+
3952
### Discussions
4053

4154
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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
8+
9+
allowBuilds:
10+
core-js-pure: false

0 commit comments

Comments
 (0)