From 82881b746338da22835c70bcd7c8d1f1f841e1e6 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 10 Mar 2020 09:16:23 -0700 Subject: [PATCH] Yarn start Failed with "Error: Unable to resolve module `react-redux`" (#883) Summary: Pull Request resolved: https://github.com/facebook/flipper/pull/883 https://github.com/facebook/flipper/issues/835 Reviewed By: passy Differential Revision: D20363818 fbshipit-source-id: 66b7cb7236c7b066db32473a9e993ba2ace529bc --- _watchmanconfig | 1 - package.json | 2 +- scripts/prepare-watchman-config.js | 30 ++++++++++++++++++++++++++++++ scripts/yarn-install.ts | 17 ----------------- static/_watchmanconfig | 1 - 5 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 scripts/prepare-watchman-config.js diff --git a/_watchmanconfig b/_watchmanconfig index c94bdec8a..2c63c0851 100644 --- a/_watchmanconfig +++ b/_watchmanconfig @@ -1,3 +1,2 @@ { - "ignore_dirs": ["node_modules", "build", "dist"] } diff --git a/package.json b/package.json index e9e03983d..efeea5def 100644 --- a/package.json +++ b/package.json @@ -232,7 +232,7 @@ ] }, "scripts": { - "preinstall": "yarn config set ignore-engines", + "preinstall": "node scripts/prepare-watchman-config.js && yarn config set ignore-engines", "postinstall": "cross-env TS_NODE_FILES=true node --require ts-node/register scripts/yarn-install.ts && patch-package", "rm-dist": "rimraf dist", "rm-modules": "rimraf node_modules static/node_modules", diff --git a/scripts/prepare-watchman-config.js b/scripts/prepare-watchman-config.js new file mode 100644 index 000000000..f302b758e --- /dev/null +++ b/scripts/prepare-watchman-config.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +const path = require('path'); +const util = require('util'); +const {exists: existsImport, copyFile} = require('fs'); +const exists = util.promisify(existsImport); + +const rootDir = path.resolve(__dirname, '..'); +const hasGit = exists(path.join(rootDir, '.git')); + +async function prepareWatchmanConfig(dir) { + const hasWatchmanConfig = exists(path.join(dir, '.watchmanconfig')); + if ((await hasGit) && !(await hasWatchmanConfig)) { + console.log(`Creating .watchmanconfig in ${dir}`); + await util.promisify(copyFile)( + path.join(dir, '_watchmanconfig'), + path.join(dir, '.watchmanconfig'), + ); + } +} + +prepareWatchmanConfig(rootDir); +prepareWatchmanConfig(path.join(rootDir, 'static')); diff --git a/scripts/yarn-install.ts b/scripts/yarn-install.ts index 24567b5c3..a5967c0d0 100644 --- a/scripts/yarn-install.ts +++ b/scripts/yarn-install.ts @@ -11,10 +11,8 @@ import path from 'path'; import util from 'util'; import globImport from 'glob'; import {exec as execImport} from 'child_process'; -import {exists as existsImport, copyFile} from 'fs'; const glob = util.promisify(globImport); const exec = util.promisify(execImport); -const exists = util.promisify(existsImport); const PACKAGES = [ 'headless-tests', 'static', @@ -28,9 +26,6 @@ const YARN_PATH = ? path.join(__dirname, process.argv[2]) : 'yarn' + (WINDOWS ? '.cmd' : ''); -prepareWatchmanConfig(path.join(__dirname, '..')); -prepareWatchmanConfig(path.join(__dirname, '..', 'static')); - Promise.all( PACKAGES.map(pattern => glob(path.join(__dirname, '..', pattern, 'package.json')), @@ -68,15 +63,3 @@ Promise.all( console.error(err); process.exit(1); }); - -async function prepareWatchmanConfig(dir: string) { - const hasGit = exists(path.join(__dirname, '..', '.git')); - const hasWatchmanConfig = exists(path.join(dir, '.watchmanconfig')); - if ((await hasGit) && !(await hasWatchmanConfig)) { - console.log(`Creating .watchmanconfig in ${dir}`); - await util.promisify(copyFile)( - path.join(dir, '_watchmanconfig'), - path.join(dir, '.watchmanconfig'), - ); - } -} diff --git a/static/_watchmanconfig b/static/_watchmanconfig index dc2ac4181..2c63c0851 100644 --- a/static/_watchmanconfig +++ b/static/_watchmanconfig @@ -1,3 +1,2 @@ { - "ignore_dirs": ["node_modules"] }