2016-11-28 16:17:51 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 20:32:37 +00:00
|
|
|
*
|
|
|
|
* @format
|
2016-11-28 16:17:51 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2016-11-28 16:17:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const {execSync} = require('child_process');
|
|
|
|
const semver = require('semver');
|
|
|
|
|
|
|
|
function checkDeclaredVersion(declaredVersion) {
|
|
|
|
if (!declaredVersion) {
|
|
|
|
throw new Error(
|
2018-05-11 20:32:37 +00:00
|
|
|
'Your "package.json" file doesn\'t seem to have "react-native" as a dependency.',
|
2016-11-28 16:17:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 08:04:37 +00:00
|
|
|
function checkMatchingVersions(currentVersion, declaredVersion, useYarn) {
|
2016-11-28 16:17:51 +00:00
|
|
|
if (!semver.satisfies(currentVersion, declaredVersion)) {
|
|
|
|
throw new Error(
|
2018-05-11 20:32:37 +00:00
|
|
|
'react-native version in "package.json" (' +
|
|
|
|
declaredVersion +
|
|
|
|
") doesn't match " +
|
|
|
|
'the installed version in "node_modules" (' +
|
|
|
|
currentVersion +
|
|
|
|
').\n' +
|
|
|
|
(useYarn
|
|
|
|
? 'Try running "yarn" to fix this.'
|
|
|
|
: 'Try running "npm install" to fix this.'),
|
2016-11-28 16:17:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkReactPeerDependency(currentVersion, declaredReactVersion) {
|
|
|
|
if (semver.lt(currentVersion, '0.21.0') && !declaredReactVersion) {
|
|
|
|
throw new Error(
|
|
|
|
'Your "package.json" file doesn\'t seem to have "react" as a dependency.\n' +
|
2018-05-11 20:32:37 +00:00
|
|
|
'"react" was changed from a dependency to a peer dependency in react-native v0.21.0.\n' +
|
|
|
|
'Therefore, it\'s necessary to include "react" in your project\'s dependencies.\n' +
|
|
|
|
'Please run "npm install --save react", then re-run ' +
|
|
|
|
'"react-native upgrade".',
|
2016-11-28 16:17:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkGitAvailable() {
|
|
|
|
try {
|
|
|
|
execSync('git --version');
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(
|
|
|
|
'"react-native-git-upgrade" requires "git" to be available in path. ' +
|
2018-05-11 20:32:37 +00:00
|
|
|
'Please install Git (https://git-scm.com)"',
|
2016-11-28 16:17:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
checkDeclaredVersion,
|
|
|
|
checkMatchingVersions,
|
|
|
|
checkReactPeerDependency,
|
|
|
|
checkGitAvailable,
|
|
|
|
};
|