Skip to content

Commit f90ce89

Browse files
authored
feat: upgrade template and repo to Yarn 3 (#421)
### Summary This migrates the repo and the templates to Yarn 3 from Yarn 1. - Yarn 1 is no longer receiving any updates or bug fixes, so it's better to move to an actively maintained version. - Previously the generated app was a fake monorepo that worked by overriding the `yarn` binary. Now it works like a regular monorepo without any hacks. ### Test plan - Generate a native module project and make sure it builds and runs on iOS & Android - Make an Expo project and make sure it runs on iOS, Android & Web
1 parent 2a92f26 commit f90ce89

File tree

25 files changed

+12891
-6806
lines changed

25 files changed

+12891
-6806
lines changed

.github/actions/setup/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ runs:
1515
with:
1616
path: |
1717
**/node_modules
18+
.yarn/install-state.gz
1819
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
1920
restore-keys: |
2021
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
2122
${{ runner.os }}-yarn-
2223
2324
- name: Install dependencies
2425
if: steps.yarn-cache.outputs.cache-hit != 'true'
25-
run: yarn install --frozen-lockfile
26+
run: yarn install --immutable
2627
shell: bash

.github/workflows/build-templates.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
--author-url https://test.test \
113113
--repo-url https://test.test \
114114
--type ${{ matrix.type }} \
115-
--languages ${{ matrix.language }} \
115+
--languages ${{ matrix.language }}
116116
117117
- name: Cache dependencies of library
118118
id: library-yarn-cache
@@ -129,8 +129,11 @@ jobs:
129129
if: steps.library-yarn-cache.outputs.cache-hit != 'true'
130130
working-directory: ${{ env.work_dir }}
131131
run: |
132-
yarn install --cwd example
133-
yarn install
132+
touch yarn.lock # Without this Yarn will fail due to the parent directory being a Yarn workspace
133+
rm -f example/yarn.lock # Workaround for cached yarn.lock from older version
134+
yarn install --no-immutable
135+
env:
136+
POD_INSTALL: 0
134137

135138
- name: Get build target
136139
working-directory: ${{ env.work_dir }}
@@ -163,8 +166,8 @@ jobs:
163166
if: env.android_build == 1 || env.ios_build == 1
164167
working-directory: ${{ env.work_dir }}
165168
run: |
166-
TURBO_CACHE_STATUS_ANDROID=$(node -p "($(yarn --silent turbo run build:android --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
167-
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
169+
TURBO_CACHE_STATUS_ANDROID=$(node -p "($(yarn turbo run build:android --cache-dir=".turbo" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
170+
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn turbo run build:ios --cache-dir=".turbo" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
168171
169172
if [[ $TURBO_CACHE_STATUS_ANDROID == "HIT" ]]; then
170173
echo "turbo_cache_hit_android=1" >> $GITHUB_ENV
@@ -227,7 +230,7 @@ jobs:
227230
if: env.android_build == 1
228231
working-directory: ${{ env.work_dir }}
229232
run: |
230-
yarn turbo run build:android --cache-dir=".turbo/cache"
233+
yarn turbo run build:android --cache-dir=".turbo"
231234
232235
- name: Cache cocoapods
233236
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1
@@ -246,12 +249,12 @@ jobs:
246249
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 && steps.library-cocoapods-cache.outputs.cache-hit != 'true'
247250
working-directory: ${{ env.work_dir }}
248251
run: |
249-
yarn example pods
252+
yarn pod-install example/ios
250253
env:
251254
NO_FLIPPER: 1
252255

253256
- name: Build example (iOS)
254257
if: env.ios_build == 1
255258
working-directory: ${{ env.work_dir }}
256259
run: |
257-
yarn turbo run build:ios --cache-dir=".turbo/cache"
260+
yarn turbo run build:ios --cache-dir=".turbo"

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ build/Release
4141
node_modules/
4242
jspm_packages/
4343

44+
# Yarn
45+
.yarn/*
46+
!.yarn/patches
47+
!.yarn/plugins
48+
!.yarn/releases
49+
!.yarn/sdks
50+
!.yarn/versions
51+
4452
# Typescript v1 declaration files
4553
typings/
4654

.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Lines changed: 28 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-3.6.1.cjs

Lines changed: 874 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
nodeLinker: node-modules
2+
3+
plugins:
4+
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
5+
spec: "@yarnpkg/plugin-workspace-tools"
6+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
7+
spec: "@yarnpkg/plugin-interactive-tools"
8+
9+
yarnPath: .yarn/releases/yarn-3.6.1.cjs

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,12 @@ If your library depends on another react-native library containing native code,
250250

251251
- **Add the native library to `peerDependencies`**
252252

253-
This means that the user will need to install the native library and add it to their `package.json`. It makes sure that:
253+
This means that the consumer of the library will need to install the native library and add it to the `dependencies` section of their `package.json`. It makes sure that:
254254

255255
- There are no version conflicts if another package also happens to use the same library, or if the user wants to use the library in their app. While there can be multiple versions of a JavaScript-only library, there can only be one version of a native library - so avoiding version conflicts is important.
256256
- The package manager installs it in correct location so that autolinking can work properly.
257257

258-
Don't add the native library to `dependencies`, otherwise it may cause issues for the user even if it seems to work.
258+
Don't add the native library to `dependencies` of your library, otherwise it may cause issues for the user even if it seems to work.
259259

260260
- **Add the native library to `devDependencies`**
261261

@@ -339,6 +339,34 @@ For more accurate testing, we recommend following approaches:
339339

340340
You can find installation and usage instructions in the [Verdaccio documentation](https://verdaccio.org/docs/en/installation).
341341

342+
### Users get a warning when they install my library
343+
344+
If users are using Yarn 1, they may get a warning when installing your library:
345+
346+
```sh
347+
warning Workspaces can only be enabled in private projects.
348+
```
349+
350+
This is because the example app is configured as a Yarn workspace, and there is a [bug in Yarn 1](https://github.com/yarnpkg/yarn/issues/8580) which causes this warning to be shown for third-party packages. It has no impact for the consumers of the library and the warning can be ignored. If consumers would like to get rid of the warning, there are 2 options:
351+
352+
1. **Disable workspaces**
353+
354+
If the consumer doesn't use Yarn workspaces, they can disable it by adding the following to the `.yarnrc` file in the root of their project:
355+
356+
```rc
357+
workspaces-experimental false
358+
```
359+
360+
2. **Upgrade to Yarn 3**
361+
362+
Yarn 1 is no longer maintained, so it's recommended to upgrade to Yarn 3. Yarn 3 works with React Native projects with the `node-modules` linker. To upgrade, consumers can follow the [official upgrade guide](https://yarnpkg.com/migration/guide).
363+
364+
It's also necessary to use `node-modules` linker. To use it, consumers can add the following to the `.yarnrc.yml` file in the root of their project:
365+
366+
```yml
367+
nodeLinker: node-modules
368+
```
369+
342370
## Development workflow
343371
344372
This project uses a monorepo using `yarn`. To setup the project, run `yarn` in the root directory to install the required dependencies.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"type": "git",
1010
"url": "git+https://github.com/react-navigation/react-navigation.git"
1111
},
12+
"packageManager": "[email protected]",
1213
"engines": {
1314
"node": ">= 18.0.0"
1415
},
15-
"packageManager": "^[email protected]",
1616
"scripts": {
1717
"lint": "eslint \"**/*.{js,ts,tsx}\"",
1818
"typecheck": "tsc --noEmit",

packages/create-react-native-library/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
},
2525
"homepage": "https://github.com/callstack/react-native-builder-bob/blob/main/README.md",
2626
"main": "lib/index.js",
27-
"bin": {
28-
"create-react-native-library": "bin/create-react-native-library"
29-
},
27+
"bin": "bin/create-react-native-library",
3028
"files": [
3129
"lib",
3230
"templates"

0 commit comments

Comments
 (0)