From 5dade01ca6389ea5745c696478943ece11be11dc Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Thu, 4 Jul 2019 09:18:56 -0700 Subject: [PATCH] Remove setupDevtools file Summary: There is a `setUpDeveloperTools.js` and a `setupDevtools.js` files. While they do set up different devtools it is very confusing to have these two files. This diff inlines one in the other which should bring more clarity. Reviewed By: gaearon Differential Revision: D16121236 fbshipit-source-id: 45641c7af9639ede6dc237ac53b763cd804a05c2 --- Libraries/Core/Devtools/setupDevtools.js | 46 ------------------------ Libraries/Core/setUpDeveloperTools.js | 26 +++++++++++++- jest/setup.js | 2 -- 3 files changed, 25 insertions(+), 49 deletions(-) delete mode 100644 Libraries/Core/Devtools/setupDevtools.js diff --git a/Libraries/Core/Devtools/setupDevtools.js b/Libraries/Core/Devtools/setupDevtools.js deleted file mode 100644 index 43ca374d50c..00000000000 --- a/Libraries/Core/Devtools/setupDevtools.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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 - * @flow - */ - -'use strict'; - -let register = function() { - // noop -}; - -if (__DEV__) { - const AppState = require('../../AppState/AppState'); - const reactDevTools = require('react-devtools-core'); - const getDevServer = require('./getDevServer'); - - // Don't steal the DevTools from currently active app. - // Note: if you add any AppState subscriptions to this file, - // you will also need to guard against `AppState.isAvailable`, - // or the code will throw for bundles that don't have it. - const isAppActive = () => AppState.currentState !== 'background'; - - // Get hostname from development server (packager) - const devServer = getDevServer(); - const host = devServer.bundleLoadedFromServer - ? devServer.url.replace(/https?:\/\//, '').split(':')[0] - : 'localhost'; - - reactDevTools.connectToDevTools({ - isAppActive, - host, - // Read the optional global variable for backward compatibility. - // It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0. - port: window.__REACT_DEVTOOLS_PORT__, - resolveRNStyle: require('../../StyleSheet/flattenStyle'), - }); -} - -module.exports = { - register, -}; diff --git a/Libraries/Core/setUpDeveloperTools.js b/Libraries/Core/setUpDeveloperTools.js index aefacad0a42..594427eec7a 100644 --- a/Libraries/Core/setUpDeveloperTools.js +++ b/Libraries/Core/setUpDeveloperTools.js @@ -22,7 +22,31 @@ if (__DEV__) { // not when debugging in chrome // TODO(t12832058) This check is broken if (!window.document) { - require('./Devtools/setupDevtools'); + const AppState = require('../AppState/AppState'); + // $FlowFixMe Module is untyped + const reactDevTools = require('react-devtools-core'); + const getDevServer = require('./Devtools/getDevServer'); + + // Don't steal the DevTools from currently active app. + // Note: if you add any AppState subscriptions to this file, + // you will also need to guard against `AppState.isAvailable`, + // or the code will throw for bundles that don't have it. + const isAppActive = () => AppState.currentState !== 'background'; + + // Get hostname from development server (packager) + const devServer = getDevServer(); + const host = devServer.bundleLoadedFromServer + ? devServer.url.replace(/https?:\/\//, '').split(':')[0] + : 'localhost'; + + reactDevTools.connectToDevTools({ + isAppActive, + host, + // Read the optional global variable for backward compatibility. + // It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0. + port: window.__REACT_DEVTOOLS_PORT__, + resolveRNStyle: require('../StyleSheet/flattenStyle'), + }); } // Set up inspector diff --git a/jest/setup.js b/jest/setup.js index 8c710256a64..a6faf2a996e 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -27,8 +27,6 @@ global.cancelAnimationFrame = function(id) { clearTimeout(id); }; -jest.mock('../Libraries/Core/Devtools/setupDevtools'); - // there's a __mock__ for it. jest.setMock( '../Libraries/vendor/core/ErrorUtils',