Détail du package

expo-yarn-workspaces

expo13.8kMIT2.3.2

A private package for working with Yarn workspaces within the Expo repository

readme

Expo Yarn Workspaces

⚠️ This package has been deprecated and replaced with proper monorepo support starting from Expo SDK 49. Learn more

This 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.

Note: This package runs only on macOS and Linux.

How apps work with workspaces

Each 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.

Add expo-yarn-workspaces as a devDependency of each app workspace

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.

Add a postinstall script to each app's package.json

Add "postinstall": "expo-yarn-workspaces postinstall" under the "scripts" object in each app's package.json file. The postinstall script does two things:

  1. 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.

  2. 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.

Define the entry module in the "main" field of each app's package.json

The 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.

You can specify other paths too. The .expo directory is convenient since it already contains auto-generated files and is .gitignore'd.

Create a file named metro.config.js

Create a file named metro.config.js in each app's base directory with these contents:

const { createMetroConfiguration } = require('expo-yarn-workspaces');

module.exports = createMetroConfiguration(__dirname);

The 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.

Aside: when starting the project, run expo start --clear so Metro uses the latest configuration instead of working with cached values.

Usage with Expo Web

Create a file named webpack.config.js in the app's base directory with these contents:

const { createWebpackConfigAsync } = require('expo-yarn-workspaces/webpack');

module.exports = async function(env, argv) {
  const config = await createWebpackConfigAsync(env, argv);
  return config;
};

This 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

Configuration

You can configure workspaces using the expo-yarn-workspaces field in each workspace package's package.json file.

symlinks

Sometimes 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.

{
  "expo-yarn-workspaces": {
    "symlinks": ["react-native-unimodules"]
  }
}

EAS Build integration

You must configure EAS Build to use the generated entrypoint. Add the ENTRY_FILE environment variable to your eas.json like the following:

{
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "env": {
        "ENTRY_FILE": "./__generated__/AppEntry.js"
      }
    },
  }
}

changelog

Changelog

Unpublished

🛠 Breaking changes

🎉 New features

🐛 Bug fixes

💡 Others

2.3.1 - 2023-12-19

This version does not introduce any user-facing changes.

2.3.0 — 2023-12-12

🎉 New features

  • Delete custom resolver.extraNodeModules in favor of the default symlinks support in Metro v0.79.0. (#25506 by @EvanBacon)

💡 Others

  • Remove deprecated Metro resolver.providesModuleNodeModules field. (#25506 by @EvanBacon)
  • Remove additional cjs in sourceExts in favor of upstream expo/metro-config version. (#25506 by @EvanBacon)
  • Remove watchFolders in favor of upstream expo/metro-config version. (#25506 by @EvanBacon)

2.2.4 — 2023-10-17

This version does not introduce any user-facing changes.

2.2.3 — 2023-09-18

This version does not introduce any user-facing changes.

2.2.2 — 2023-09-04

💡 Others

  • Reorder imports in the AppEntry template to match the latest eslint-config-universe settings (#23544 by @ide)

2.2.1 — 2023-06-21

This version does not introduce any user-facing changes.

2.2.0 — 2023-05-08

🎉 New features

  • Add support for passing options to expo/metro-config -- enables CSS support. (#22325 by @EvanBacon)

2.1.0 — 2023-02-03

💡 Others

2.0.4 — 2022-10-25

This version does not introduce any user-facing changes.

2.0.2 — 2022-07-25

This version does not introduce any user-facing changes.

2.0.1 — 2022-07-16

This version does not introduce any user-facing changes.

2.0.0 — 2022-04-18

🛠 Breaking changes

  • Remove deprecated metro config blacklistRE and drop react-native@<0.64.0 support. (#16479 by @kudo)

🎉 New features

  • Support looking up .cjs (still the bundler's job to be able to handle these files; EYW just allows them to be found) (#15836 by @ide)

💡 Others

1.7.0 — 2021-12-03

💡 Others

1.6.0 — 2021-09-28

🎉 New features

  • Support React Native 0.64 while also maintaining backwards compatibility with 0.63 and earlier. (#14136 by @brentvatne)

💡 Others

1.5.2 — 2021-06-16

This version does not introduce any user-facing changes.

1.5.1 — 2021-04-20

🐛 Bug fixes

1.5.0 — 2021-04-20

🎉 New features

1.4.1 — 2021-03-23

🎉 New features

  • Updated @expo/metro-config with deprecated .expo.* extension support and improved error stack traces. (#12252 by @EvanBacon)

1.4.0 — 2021-03-10

🎉 New features

🐛 Bug fixes

  • Use junction symlinks on Windows to avoid admin privileges (#11739 by @byCedric)

1.3.1 — 2021-01-08

🐛 Bug fixes

  • Do not attempt to symlink non-existent packages (#11567 by @SimenB)