Skip to content

Commit

Permalink
Fix react-native-git-upgrade by get package.json instead of selective…
Browse files Browse the repository at this point in the history
… field

Summary:
Explain the **motivation** for making this change. What existing problem does the pull request solve?

To fixes facebook#11330 and fixes facebook#11334

Regarding to this command (using in `react-native-git-upgrade` - [cliEntry.js#L261](https://github.com/facebook/react-native/blob/master/react-native-git-upgrade/cliEntry.js#L261))
```bash
npm view react-native@latest peerDependencies.react version --json
```
The result from this command are not consistent across a different npm versions.

We better get a whole `package.json` file by calling (remove field and subfield option)

```
npm view react-native@latest  --json
```

**Test plan (required)**

**Setup**
- Publish `react-native-git-upgrade` to `sinopia`
- `npm install -g react-native-git-upgrade`
- Test against multiple npm versions (`2.15.8` or `3.7.5` or `3.10.10` or ` 4.0.3`)
- `react-native init AwesomeApp  --version 0.38.0 && cd AwesomeApp`
- `react-native-git-upgrade` and `react-native-git-upgrade 0.39.0` should be working properly

 ---
Closes facebook#11348

Differential Revision: D4305894

Pulled By: mkonicek

fbshipit-source-id: 36ea7846926b424f4dd63c77b47db5cb69285027
  • Loading branch information
n3tr authored and Facebook Github Bot committed Dec 9, 2016
1 parent 3021375 commit 1877e1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions react-native-git-upgrade/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ function parseInformationJsonOutput(jsonOutput, requestedVersion) {
try {
const output = JSON.parse(jsonOutput);
const newVersion = output.version;
const newReactVersionRange = output['peerDependencies.react'];
const peerDependencies = output.peerDependencies;
const newReactVersionRange = peerDependencies.react;

assert(semver.valid(newVersion));

Expand Down Expand Up @@ -258,7 +259,7 @@ async function run(requestedVersion, cliArgs) {
checkGitAvailable();

log.info('Get information from NPM registry');
const viewCommand = 'npm view react-native@' + (requestedVersion || 'latest') + ' peerDependencies.react version --json';
const viewCommand = 'npm view react-native@' + (requestedVersion || 'latest') + ' --json';
const jsonOutput = await exec(viewCommand, verbose);
const {newVersion, newReactVersionRange} = parseInformationJsonOutput(jsonOutput, requestedVersion);
// Print which versions we're upgrading to
Expand Down
3 changes: 2 additions & 1 deletion react-native-git-upgrade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-git-upgrade",
"version": "0.2.3",
"version": "0.2.4",
"license": "BSD-3-Clause",
"description": "The React Native upgrade tool",
"main": "cli.js",
Expand All @@ -19,6 +19,7 @@
"babel-preset-es2015-node": "^6.1.1",
"babel-preset-stage-3": "^6.17.0",
"babel-register": "^6.18.0",
"minimist": "^1.2.0",
"npmlog": "^4.0.0",
"promise": "^7.1.1",
"rimraf": "^2.5.4",
Expand Down

0 comments on commit 1877e1b

Please sign in to comment.