• Stars
    star
    115
  • Rank 296,311 (Top 6 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tools and utils to support a React Native monorepo built with Yarn Workspaces

React Native Monorepo Tools

A set of tools to help you build your React Native project in a Yarn Workspaces monorepo.

Check out the "Running React Native everywhere" tutorial and the react-native-universal-monorepo to see them in action.

Usage

Install the package using npm or Yarn.

# Using npm
npm install -D react-native-monorepo-tools

# Using yarn
yarn add -D react-native-monorepo-tools

Tools for making React Native codebases compatible with Yarn Workspaces

getMetroTools(params: Object): Object

Return Metro tools to make it compatible with Yarn workspaces.

Usage:

const { getMetroTools } = require("react-native-monorepo-tools");

const metroTools = getMetroTools();

console.log(metroTools.watchFolders);
// ↪ [
//    "/Users/me/my-monorepo/node_modules/"
//    "/Users/me/my-monorepo/packages/workspace-a/",
//    "/Users/me/my-monorepo/packages/workspace-b",
//   ]

console.log(metroTools.blockList);
// ↪ [
//     /^((?!workspace-a).)*\/node_modules\/react\/.*$/,
//     /^((?!workspace-a).)*\/node_modules\/react-native\/.*$/,
//   ]

console.log(metroTools.extraNodeModules);
// ↪ {
//     "react": "/Users/me/my-monorepo/packages/workspace-a/node_modules/react",
//     "react-native": "/Users/me/my-monorepo/packages/workspace-a/node_modules/react-native"
//   }

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().
  • reactNativeAlias: Optional. Alias for the react-native lib (e.g., react-native-macos).
  • libNamesOnly: Optional. Return the nothoist list as library names instead of paths? Defaults to false.

Output:

  • watchFolders: Directories watched by metro.
  • blockList: List of regexes resolving to paths ignored by metro.
  • extraNodeModules: List of required modules outside of the workspace directory.

getWebpackTools(params: Object): Object

Return Webpack tools to make it compatible with Yarn workspaces.

Usage:

const { getWebpackTools } = require("react-native-monorepo-tools");
const webpackConfig = require('./webpack.config.js')

const webpackTools = getWebpackTools();

console.log(webpackTools.addNohoistAliases(webpackConfig));
// ↪ alias: {
//     "react": "/Users/me/my-monorepo/packages/workspace-a/node_modules/react"
//     "react-native": "/Users/me/my-monorepo/packages/workspace-a/node_modules/react-native-web"
//   }

console.log(webpackTools.enableWorkspacesResolution(webpackConfig));
// ↪ adds to babel-loader each workspace

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().

Output:

  • enableWorkspacesResolution(webpackConfig): Updates a webpack config to allow importing from external workspaces.
  • addNohoistAliases(webpackConfig): Updates a webpack config to ensure nohoisted libraries are resolved from this workspace.

getMetroAndroidAssetsResolutionFix(params: Object): Object

Return the Metro Android assets resolution fix.

Metro's bundler has an issue with assets resolution on Android when importing assets from paths outside of the project's root directory.
To fix it, we can patch metro's publicPath and enhanceMiddleware to allow reading from n depths below the project directory. For more info, see this metro comment: facebook/metro#290 (comment)

Usage:

const {
  getMetroAndroidAssetsResolutionFix,
} = require("react-native-monorepo-tools");

const metroAndroidAssetsResolutionFix = getMetroAndroidAssetsResolutionFix();

console.log(metroAndroidAssetsResolutionFix.publicPath);
// ↪ "/assets/dir/dir/dir/dir"

console.log(metroAndroidAssetsResolutionFix.applyMiddleware);
// ↪ Function that applies the patch middleware to metro.

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().

Output:

  • publicPath: Metro's publicPath.
  • applyMiddleware: Function that applies the patch middleware to metro.

Additional minor utils

getMonorepoRoot(params: Object): string

Return the root path of this monorepo.

Usage:

const { getMonorepoRoot } = require("react-native-monorepo-tools");

const monorepoRoot = getMonorepoRoot();
console.log(monorepoRoot);
// ↪ /Users/me/my-monorepo',

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().

getWorkspaces(params: Object): string[]

Return the workspaces of this monorepo (as paths).

Usage:

const { getWorkspaces } = require("react-native-monorepo-tools");

const workspaces = getWorkspaces();
console.log(workspaces);
// ↪ [
//     "/Users/me/my-monorepo/packages/workspace-a",
//     "/Users/me/my-monorepo/packages/workspace-b",
//   ]

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().

getCurrentWorkspace(params: Object): string

Return the current workspace path.

Usage:

const { getCurrentWorkspace } = require("react-native-monorepo-tools");

const currentWorkspace = getCurrentWorkspace();
console.log(currentWorkspace);
// ↪ "/Users/me/my-monorepo/packages/workspace-a"

getNohoist(params: Object): string[]

Return the nothoist libraries of this monorepo (as paths or names).

Usage:

const { getNohoist } = require("react-native-monorepo-tools");

const nohoist = getNohoist();
console.log(nohoist);
// ↪ [
//     "/Users/me/my-monorepo/packages/workspace-a/react",
//     "/Users/me/my-monorepo/packages/workspace-a/react-native",
//     "/Users/me/my-monorepo/packages/workspace-b/react",
//     "/Users/me/my-monorepo/packages/workspace-b/react-native",
//   ]

Available params:

  • cwd: Optional. Current working directory. Defaults to process.cwd().
  • currentWorkspaceOnly: Optional. Return the nothoist list for the current workspace only? Defaults to false.
  • libNamesOnly: Optional. Return the nothoist list as library names instead of paths? Defaults to false.

Contributing

Each contribution is welcome!
Please, check the contributing guidelines.

License

React Native Monorepo Tools is released under AGPL-3.0 - GNU Affero General Public License v3.0.

Briefly:

  • Modification and redistribution allowed for both private and commercial use.
  • You must grant patent rigth to the owner and to all the contributors.
  • You must keep it open source and distribute under the same license.
  • Changes must be documented.
  • Include a limitation of liability and it does not provide any warranty.

Warranty

THIS TOOL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. For the full warranty check the LICENSE.

More Repositories

1

react-native-modal-datetime-picker

A React-Native datetime-picker for Android and iOS
JavaScript
2,809
star
2

react-native-universal-monorepo

React Native boilerplate supporting multiple platforms: Android, iOS, macOS, Windows, web, browser extensions, Electron.
JavaScript
1,619
star
3

react-native-dialog

Pure JavaScript React-Native dialog
TypeScript
634
star
4

breathly-app

A tiny breath training app built with React-Native
TypeScript
477
star
5

ordinary-puzzles-app

Mobile and web puzzle game built with React-Native
TypeScript
469
star
6

react-native-login-animation-example

A React-Native login animation example
JavaScript
350
star
7

tangerine-monorepo

A "fast" TypeScript-based Node.js monorepo setup powered by esbuild & turborepo
TypeScript
265
star
8

tap-the-number

A simple React-Native game for iOS
JavaScript
157
star
9

top-github

Android app for browsing GitHub top repositories
Java
95
star
10

firebase-recyclerview

Generic Firebase recyclerview list for Android
Java
91
star
11

react-native-beacons-android

A React-Native library for detecting beacons on Android
Java
73
star
12

the-starter-app

An in-depth tutorial about building mobile apps using React-Native
TypeScript
67
star
13

eslint-plugin-react-app

ESLint configuration used by Create React App
JavaScript
51
star
14

react-native-radio-button

Just a simple radio button
JavaScript
48
star
15

just-tap

A first test drive of hooks, redux and redux-saga in React-Native!
TypeScript
39
star
16

easy-bookmarks

Bookmarks saving and sharing app for Android (with Firebase)
Java
38
star
17

create-react-app-electron-boilerplate

JavaScript
34
star
18

alfred-jira-search

An Alfred workflow to search for Jira tickets
Shell
26
star
19

jira-express

Browser extension to quickly access your Jira tickets.
TypeScript
21
star
20

react-native-starter

React-Native/Redux/Parse
JavaScript
20
star
21

url-metadata-scraper

Tiny Vercel serverless function to scrape metadata from a URL
JavaScript
15
star
22

serverino

Tiny CLI-based static server
JavaScript
13
star
23

trees-and-tents-sample

React-Native implementation of the Trees and Tents puzzle game
JavaScript
13
star
24

build-it-bigger

Udacity Android Nanodegree: Project 4
Java
12
star
25

pinboard-api-proxy

Tiny proxy server to allow all origins to fetch the Pinboard API
JavaScript
11
star
26

reason-react-material-ui-demo

A simple form built with Reason React and Material UI
Reason
8
star
27

react-native-trello-login

Use Trello's API token-based authentication in React-Native
JavaScript
8
star
28

img-resizable

Resizable polymer <img>
HTML
6
star
29

which-one

A small React + Typescript + MobX game
TypeScript
6
star
30

some-react-native-components

components components components components components components components
4
star
31

visual-ui-testing-example

Using Playwright and GitHub action to automate visual UI testing
TypeScript
4
star
32

bookmarkpack-server

NodeJS/Express/Mongoose REST API server
JavaScript
3
star
33

multi-pacman

A multiplayer pacman for Android (Libgdx + Google Play Games Services)
Java
3
star
34

bookmarkpack-client-angular

JavaScript
2
star
35

touch-delay

Fixing the small (~100ms) touch delay on mobile
JavaScript
2
star
36

breathly-website

Breathly app landing page
HTML
2
star
37

polymer-scroll-threshold

aka core-scroll-threshold for polymer 1.0
HTML
2
star
38

miniexec

Minimalist approach to running shell commands in Deno
TypeScript
1
star
39

spotify-streamer-stage-2

Udacity Android Nanodegree: Project 2
Java
1
star
40

dotfiles

Simple dotfiles
Shell
1
star
41

react-toolbox-postcss-boilerplate

A minimal boilerplate for react-toolbox + postcss
JavaScript
1
star
42

quick-reminders-cli

Tiny Deno CLI to create new reminders in the Apple's Reminders app using a natural language parser
TypeScript
1
star