From 2ce10e4a7117cd7297f7418a994a4564d5a9676f Mon Sep 17 00:00:00 2001 From: Rotem Mizrachi-Meidan Date: Wed, 7 Mar 2018 13:45:17 +0200 Subject: [PATCH] RN Update script updates react version implicitly (#610) * Travis Driven Development * Updated rn-cli.config to support old RN versions --- detox/test/package.json | 4 +- examples/demo-react-native-jest/package.json | 4 +- .../demo-react-native-jest/rn-cli.config.js | 7 ++- examples/demo-react-native/package.json | 4 +- examples/demo-react-native/rn-cli.config.js | 7 ++- scripts/change_react_native_version.js | 47 ++++++++++++++++--- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/detox/test/package.json b/detox/test/package.json index 6c9b0f73b3..6b7b8d4988 100644 --- a/detox/test/package.json +++ b/detox/test/package.json @@ -12,8 +12,8 @@ "build:android": "detox build --configuration android.emu.release" }, "dependencies": { - "react": "16.2.0", - "react-native": "0.53.3" + "react": "16.0.0-beta.5", + "react-native": "0.49.3" }, "devDependencies": { "detox": "^7.0.0", diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index dc7db5447f..69d1bfceb1 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -8,8 +8,8 @@ "test-android": "detox build --configuration android.emu.debug && detox test --configuration android.emu.debug -l verbose" }, "dependencies": { - "react": "16.2.0", - "react-native": "0.53.3" + "react": "16.0.0-beta.5", + "react-native": "0.49.3" }, "devDependencies": { "babel-jest": "21.2.0", diff --git a/examples/demo-react-native-jest/rn-cli.config.js b/examples/demo-react-native-jest/rn-cli.config.js index 1d494986a7..bc94d8d429 100644 --- a/examples/demo-react-native-jest/rn-cli.config.js +++ b/examples/demo-react-native-jest/rn-cli.config.js @@ -1,4 +1,9 @@ -const metroBundler = require('metro'); +let metroBundler; +try { + metroBundler = require('metro'); +} catch (ex) { + metroBundler = require('metro-bundler'); +} module.exports = { getBlacklistRE: function() { diff --git a/examples/demo-react-native/package.json b/examples/demo-react-native/package.json index 93d9a74087..7113984ef7 100644 --- a/examples/demo-react-native/package.json +++ b/examples/demo-react-native/package.json @@ -6,8 +6,8 @@ "start": "react-native start" }, "dependencies": { - "react": "^16.2.0", - "react-native": "^0.53.3" + "react": "16.0.0-beta.5", + "react-native": "0.49.3" }, "devDependencies": { "mocha": "^4.0.1", diff --git a/examples/demo-react-native/rn-cli.config.js b/examples/demo-react-native/rn-cli.config.js index 1d494986a7..bc94d8d429 100644 --- a/examples/demo-react-native/rn-cli.config.js +++ b/examples/demo-react-native/rn-cli.config.js @@ -1,4 +1,9 @@ -const metroBundler = require('metro'); +let metroBundler; +try { + metroBundler = require('metro'); +} catch (ex) { + metroBundler = require('metro-bundler'); +} module.exports = { getBlacklistRE: function() { diff --git a/scripts/change_react_native_version.js b/scripts/change_react_native_version.js index f42a74a452..1cb68c6056 100644 --- a/scripts/change_react_native_version.js +++ b/scripts/change_react_native_version.js @@ -1,13 +1,46 @@ let fs = require('fs'); let path = require('path'); +const https = require('https'); -const projectPath = process.argv[2]; -const reactNativeVersion = process.argv[3]; -const filePath = path.join(process.cwd(), projectPath, 'package.json'); -let packageJson = require(filePath); +async function run() { + const projectPath = process.argv[2]; + const reactNativeVersion = process.argv[3]; -console.log(`Changing react-native dependency in ${filePath} to ${reactNativeVersion}`); + const filePath = path.join(process.cwd(), projectPath, 'package.json'); + console.log(`Trying to change react-native dependency in ${filePath}`); -packageJson.dependencies['react-native'] = reactNativeVersion; -fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); \ No newline at end of file + let packageJson = require(filePath); + + const data = await fetch(`https://registry.npmjs.org/react-native/${reactNativeVersion}/`); + const reactVersion = data.peerDependencies.react; + + console.log(`Changed dependencies: + react-native: ${reactNativeVersion} + react: ${reactVersion}`); + + packageJson.dependencies['react-native'] = reactNativeVersion; + packageJson.dependencies['react'] = reactVersion; + fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); +} + +async function fetch(url) { + return new Promise((resolve, reject) => { + https.get(url, res => { + res.setEncoding('utf8'); + let body = ""; + res.on('data', data => { + body += data; + }); + res.on('end', () => { + body = JSON.parse(body); + resolve(body); + }); + res.on('error', (error) => { + reject(error); + }); + }); + }); +} + +run(); \ No newline at end of file