Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the RN bundling in CI servers by checking for CI servers and turn… (
#503) Summary: **Summary** *Issue : #355 *Follow up on my old PR : #497 The RN app build process is failing in CI servers due to the always-on file watch of metro. Mostly the CI servers will have a limit on no. of file watch at a time. This is a problem for RN apps with large no. of dependencies, and thus with a large no. of files in `node_modules`. Which cause the build to fail with `ENOSPC` error. This PR will detect the CI servers with [`ci-info`](https://github.com/watson/ci-info/) module and turn off the [file-watching of JestHasteMap in metro](https://github.com/facebook/metro/blob/f6314e43071ae498b41d9e5579ad4a13941a4baa/packages/metro/src/node-haste/DependencyGraph.js#L95). ~~Also in the [Metro documentation we have a `watch` field](https://facebook.github.io/metro/docs/en/configuration#watch), but it is not working since [this commit ](0d6c135#diff-75dc57ca2d6ab410090adb917784434f). So this PR will also make it working, so that people who wish to turn off the watch can do that with their metro config.~~ And this change is a no-op to current metro users, as it will maintain the default watch behavior. Also we can manually turn off the file watch by setting the `CI=true` environment variable. **Motivation** *Why this fix is required now ?* This file watching functionality will help in accelerating the local development, but that is not expected when we are building the project to release in our CI pipelines, where the build is happening in some docker containers or some ec2 servers, where sometimes we do not have access to set the `fs.inotify.max_user_watches`. So people try the workarounds like, npm script for deleting the folders in the node_modules which are not required in the bundling process. **Test plan** Completing the [metro pull request workflow](https://github.com/facebook/metro/blob/master/CONTRIBUTING.md#workflow-and-pull-requests). And I tested the functionality by creating a [sample RN app](https://github.com/alanjoxa/AwesomeProject) by applying this [patch](https://github.com/alanjoxa/AwesomeProject/tree/master/patches) to its metro dependencies in node-modules, as part of its [postinstall script](https://github.com/alanjoxa/AwesomeProject/blob/e52b92fd04d61e9ed8530d5fdf7f59657b1a8a2e/package.json#L11). It is working as expected. **Test simulation instructions** ``` git clone https://github.com/alanjoxa/AwesomeProject.git cd AwesomeProject npm install npm start ``` This will start a metro server and serve the bundles by watching all files in the project root. We can turn off the file watch by restarting it by `CI=true npm start`. A sample bundle can be triggered by making a GET request at `http://localhost:8081/index.bundle?platform=ios`. When in - `npm start` - Metro server will watch for all files in the project folder, including `node_modules` and apply any file changes to the bundle on the subsequent build request. - `CI=true npm start` - Will not watch for files, that means we need to restart the server for seeing the file changes. Pull Request resolved: #503 Differential Revision: D19286561 Pulled By: cpojer fbshipit-source-id: 68f99f746440ab2e199189bba92489a79e800f5d
- Loading branch information