Name Date Size #Lines LOC

..26-Sep-2023-

__tests__/H26-Sep-2023-6755

bin/H26-Sep-2023-368296

common/H26-Sep-2023-5644

workspace-template/H26-Sep-2023-4237

.eslintignoreH A D26-Sep-202313 21

.eslintrc.jsH A D26-Sep-202364 54

CHANGELOG.mdH A D26-Sep-20233.8 KiB12061

README.mdH A D26-Sep-20234.4 KiB9158

index.jsH A D26-Sep-20232.6 KiB8150

package.jsonH A D26-Sep-2023739 3231

webpack.jsH A D26-Sep-20232.5 KiB7452

README.md

1# Expo Yarn Workspaces
2
3This is a package that provides support for Yarn workspaces within monorepos like the Expo repository. It finesses Yarn workspaces, Metro, and the Expo repository to work together.
4
5**Note:** This package runs only on macOS and Linux.
6
7## How apps work with workspaces
8
9Each Expo app in the repository that is intended to work with Yarn workspaces (as opposed to being tested in a non-workspace environment) does the steps described below. All of the steps are important and need to be followed carefully.
10
11### Add `expo-yarn-workspaces` as a devDependency of each app workspace
12
13**Run `yarn add --dev expo-yarn-workspaces` in each app.** This adds scripts provided by `expo-yarn-workspaces` to the project under its `node_modules/.bin` directory and also defines modules the app will use.
14
15### Add a `postinstall` script to each app's package.json
16
17**Add `"postinstall": "expo-yarn-workspaces postinstall"` under the `"scripts"` object in each app's package.json file.** The postinstall script does two things:
18
191. It creates symlinks for packages that some programs expect to exist under `node_modules`, namely `expo` and `react-native`. These symlinks point to the respective packages installed in the workspace root.
20
212. It generates an entry module for the app that assumes your app's root component is exported from `App.js` (`App.${platform}.js` also works). This is similar to conventional Expo apps, but we need to generate a different entry module because Metro does not use the logical path to the entry module within the symlinked `expo` package.
22
23### Define the entry module in the `"main"` field of each app's package.json
24
25The postinstall script determines the location of the generated entry module by looking at the `"main"` field in package.json. In a conventional Expo app, the value of the `"main"` field is `node_modules/expo/AppEntry.js`. In a workspace in the Expo repo, **specify `"__generated__/AppEntry.js"` as the value of the `"main"` field in package.json.** If using EAS Build, see the additional instructions below.
26
27You can specify other paths too. The `.expo` directory is convenient since it already contains auto-generated files and is .gitignore'd.
28
29### Create a file named `metro.config.js`
30
31**Create a file named `metro.config.js` in each app's base directory with these contents:**
32
33```js
34const { createMetroConfiguration } = require('expo-yarn-workspaces');
35
36module.exports = createMetroConfiguration(__dirname);
37```
38
39The `expo-yarn-workspaces` package defines a Metro configuration object that makes Metro work with Yarn workspaces in the Expo repo. It configures Metro to include packages from the workspace root, resolves symlinked packages, excludes modules from Haste's module system, and exclude modules in the native Android and Xcode projects. You can further customize this configuration object before exporting it, if needed.
40
41**Aside:** when starting the project, run `expo start --clear` so Metro uses the latest configuration instead of working with cached values.
42
43### Usage with Expo Web
44
45**Create a file named `webpack.config.js` in the app's base directory with these contents:**
46
47```js
48const { createWebpackConfigAsync } = require('expo-yarn-workspaces/webpack');
49
50module.exports = async function(env, argv) {
51  const config = await createWebpackConfigAsync(env, argv);
52  return config;
53};
54```
55
56This returns a webpack config object that can be customized further - for all available options see: https://github.com/expo/expo-cli/tree/main/packages/webpack-config
57
58### Configuration
59
60You can configure workspaces using the `expo-yarn-workspaces` field in each workspace package's `package.json` file.
61
62#### `symlinks`
63
64Sometimes an npm package must be located in the project's `node_modules` folder for things to work properly. Using the `expo-yarn-workspaces.symlinks` string array you can define a list of packages to symlink under the project's `node_modules` folder after installing the workspaces' dependencies.
65
66```json
67{
68  "expo-yarn-workspaces": {
69    "symlinks": ["react-native-unimodules"]
70  }
71}
72```
73
74## EAS Build integration
75
76You must configure EAS Build to use the generated entrypoint. Add the `ENTRY_FILE` environment variable to your `eas.json` like the following:
77
78```json
79{
80  "build": {
81    "development": {
82      "developmentClient": true,
83      "distribution": "internal",
84      "env": {
85        "ENTRY_FILE": "./__generated__/AppEntry.js"
86      }
87    },
88  }
89}
90```
91