Commit Graph

12 Commits

Author SHA1 Message Date
Nicolas Cuillery 1116a59019 Allow binary files to be upgraded
Summary:
`react-native-git-upgrade` doesn't handle the binary files. An error is thrown if the user has changed the default Android icons. See #11402

With this PR, the upgrader would also be ready for the assets optimization: #10408 by GantMan

- Publish `react-native-git-upgrade` to sinopia
- `npm install -g react-native-git-upgrade`

- Init a new project with an old version: `react-native init MyApp --version=0.40.0`
- Replace an Android icon (i.e. `MyApp/android/app/src/main/res/mipmap-hdpi/ic_launcher.png`) by any other image file.
- Change the content of a text file.
- Run `react-native-git-upgrade`

👉 The project is upgraded successfully.
👉 The replaced image file is still here.
👉 The text change is still here.

- Replace an Android icon in the RN sources (i.e. https://github.com/facebook/react-native/blob/master/local-cli/templates/HelloWorld/android/app/src/mai
Closes https://github.com/facebook/react-native/pull/12201

Differential Revision: D4543190

Pulled By: mkonicek

fbshipit-source-id: f1df32ee064557220deed717a129c3e175a6e9e2
2017-02-10 07:30:44 -08:00
mikaello 0da9688f41 Forcing git diff to not use colorized output
Summary:
If a user sets `color.ui` or `color.diff` to `always` in their git configuration files, the output of `git diff` will contain some "color characters" as well as the diff. When you try to apply this diff with color characters with `git apply` you will get `fatal: unrecognized input`.

I think this is the cause of issue #11543

Reproduce in git with:
```
mkdir git-test
cd git-test/
git init
echo "foo" > bar.txt
git add bar.txt
git commit -m "First"
echo "foomobile" > bar.txt
git add bar.txt
git diff HEAD > new.patch --color=always
git reset --hard HEAD
git apply new.patch --check
```

Set `--color=never` or `--no-color` and the unrecognized input error should disappear and the patch be applied successfully.
Closes https://github.com/facebook/react-native/pull/12211

Differential Revision: D4514132

fbshipit-source-id: 3622df6ece92794c8a175f0599f5a276d92e82e8
2017-02-05 14:28:40 -08:00
Jirat K 1877e1b1d1 Fix react-native-git-upgrade by get package.json instead of selective field
Summary:
Explain the **motivation** for making this change. What existing problem does the pull request solve?

To fixes #11330 and fixes #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 https://github.com/facebook/react-native/pull/11348

Differential Revision: D4305894

Pulled By: mkonicek

fbshipit-source-id: 36ea7846926b424f4dd63c77b47db5cb69285027
2016-12-09 07:58:34 -08:00
Martin Konicek bf55df15db Git upgrade: Tweak wording
Reviewed By: mkonicek

Differential Revision:
D4276739
Ninja: OSS

fbshipit-source-id: 7480a3ee77ed8f6ab0d35f92b43a806bfe29a151
2016-12-05 06:28:34 -08:00
Martin Konicek f0490d67ff Git upgrade: Tweak README, bump version, fix a bug
Reviewed By: mkonicek

Differential Revision:
D4276644
Ninja: OSS only

fbshipit-source-id: 7bed331770d06addedf51e2ed09d0b9bde5b45ad
2016-12-05 05:58:29 -08:00
Martin Konicek 682f540b41 Git upgrade: add a README
Reviewed By: mkonicek

Differential Revision:
D4276245
Ninja: OSS docs only

fbshipit-source-id: b7a7561932e3209dc34322f12a512eb5724791c3
2016-12-05 03:13:31 -08:00
Nicolas Cuillery 53178b48d1 Fix the parse error when specifying an unknown version.
Summary:
**Motivation**

When running `react-native-git-upgrade` with an unknown version, the error message isn't very helpful

**Test Plan**

- Publish the `master` branch to Sinopia
- Run `react-native-git-upgrade 0.666.0` inside a RN project
- Error message is `SyntaxError: Unexpected end of JSON input`
- Publish this branch to Sinopia
- Run `react-native-git-upgrade 0.666.0` inside a RN project
- Error message should be `Error: The specified version of React Native 0.666.0 doesn't exist.
Re-run the react-native-git-upgrade command with an existing version,
for example: "react-native-git-upgrade 0.38.0",
or without arguments to upgrade to the latest: "react-native-git-upgrade".`
Closes https://github.com/facebook/react-native/pull/11264

Differential Revision: D4265553

Pulled By: mkonicek

fbshipit-source-id: 8597eb09cc3397bfa6d2205a9b3bb30acfad530f
2016-12-02 08:28:32 -08:00
Martin Konicek 6bee16a63d Use Yarn if available
Summary:
**Motivation**

If the project is using yarn to manage its dependencies, we should be running 'yarn add' to upgrade the React Native dependency, rather than 'npm install'.

**Test plan (required)**

Running in a project that's in a bad state:

    Error: react-native version in "package.json" (0.29.2) doesn't match the installed version in "node_modules" (0.38.0).
    Try running "yarn" to fix this.

Removed yarn.lock file, ran again:

    Error: react-native version in "package.json" (0.29.2) doesn't match the installed version in "node_modules" (0.38.0).
    Try running "npm install" to fix this.

Running inside a folder that doesn't contain a `package.json` file:

    Error: Unable to find "/Users/mkonicek/Zero29App/package.json" or "/Users/mkonicek/Zero29App/node_modules/react-native/package.json". Make sure you ran "yarn" and that you are inside a React Native project.

Removed yarn.lock file, ran again:

    Error: Unable to find "/Users/mkonicek/Zero29App/package.json" or "/Users/
Closes https://github.com/facebook/react-native/pull/11225

Differential Revision: D4261102

Pulled By: mkonicek

fbshipit-source-id: b44ae91fe46f2c81b14616ca2868cc171692c895
2016-12-02 00:13:32 -08:00
Nicolas Cuillery a0f3a93f0b Upgrade React and React Native at the same time
Summary:
**Motivation**
As NoelBroda pointed out in https://github.com/facebook/react-native/pull/11104 and https://github.com/facebook/react-native/pull/11123, NPM often produces an unmet peerDependency when upgrading React Native. It causes a failure when running "npm install" with NPM2.

During the git-upgrade, we have to take care of the `react` peerDep: this PR checks if the installed `react` package matches the `react` peerDep of the new `react-native` version. If so, R & RN are upgraded at the same time (in the same `npm install`).

**Test plan**
- Publish `react-native-git-upgrade` to Sinopia,
- Run `react-native-git-upgrade` inside a RN project with version < 0.37,
- Verify that no "unmet peer dependency" warning is displayed
- Open the `package.json` and verify that both R & RN have been updated
Closes https://github.com/facebook/react-native/pull/11226

Differential Revision: D4258007

Pulled By: mkonicek

fbshipit-source-id: cff466d4710807d97fc6161f47bb974097b75261
2016-12-01 03:43:28 -08:00
Martin Konicek be559d9760 Small wording and naming changes
Summary:
Just some small changes that made the core easier for me to understand as I went through it.

**Test plan (required)**

    $ cd react-native
    # "Install globally" without using Sinopia :)
    $ cp -r react-native-git-upgrade /usr/local/lib/node_modules/

    $ cd ~
    $ react-native init Zero29App --version=0.29.2
    $ cd Zero29App

Made a small change in `MainApplication.java` to introduce a conflict with the new template.

    $ git init && git add . && git commit -m "Initial commit"
    $ react-native-git-upgrade

Worked, printed the conflicting file. Output: http://pastie.org/10972793

    $ git reset --hard
    $ react-native-git-upgrade --verbose

Worked, printed the conflicting file. Output: http://pastie.org/10972796

In both cases (with and without --verbose) the output of `git st` was http://pastie.org/10972795
Closes https://github.com/facebook/react-native/pull/11197

Differential Revision: D4251008

Pulled By: mkonicek

fbshipit-source-id: c5bbbeaf996cb5cb46cccc12fd1da7634cc23520
2016-11-30 08:28:33 -08:00
Martin Konicek b20b20656a More accurate check for latest version
Summary:
When testing `react-native-git-upgrade` locally I noticed a warning:

    A more recent version of "react-native-git-upgrade" has been found:
    Current: 0.1.0
    Latest: 0.0.1

See https://www.npmjs.com/package/react-native-git-upgrade

This won't happen to a lot of people but better fix the warning. Also, if the check for updates fails, don't crash - the check for updates is not critical to the tool working.

Also, slightly updated one error message.

**Test plan (required)**

Installed `react-native-git-upgrade` locally, ran it inside an app folder (RN 0.29).

Didn't see the wrong "more recent version" warning anymore.

Tried making `checkForUpdates` fail by adding some dummy code: `semver.foo()`. Saw a warning but the process continued:

    git-upgrade WARN Check for latest version failed semver.foo is not a function

Saw a more descriptive error message:

    git-upgrade ERR! Error: react-native version in "package.json" (0.29.0) doesn't match the installed version in "node_mod
Closes https://github.com/facebook/react-native/pull/11188

Differential Revision: D4244002

Pulled By: bestander

fbshipit-source-id: 772044750a933663cb516201d09e2873462cca4a
2016-11-29 06:13:28 -08:00
Nicolas Cuillery 7d89b773a7 New upgrading process, relying on Git
Summary:
The upgrading process based on Yeoman is a pain. For each file, Yeoman (or the brand new copyAndReplace solution a477aec) compares the newly generated content with the existing one and prompts the user if it differs, with very basic options: overwrite or skip.

I have digged into this problem and came with [rn-diff](https://github.com/ncuillery/rn-diff) (you may have read [this article](https://medium.com/ncuillery/easier-react-native-upgrades-with-rn-diff-5020b5c3de2d#.llvy2dym5)). This repository helps people to upgrade RN on their projects. An alternative upgrading process using `git apply` instead of Yeoman is described [here](https://github.com/ncuillery/rn-diff/blob/master/USAGE.md).

This PR is the integration of this process into the core. I got rid of the drawbacks mentioned in the link below in order to make it a clean, elegant, one-step operation.

This process is based on some Shell operations that:
- Generate the blank sources of both old and new versions
Closes https://github.com/facebook/react-native/pull/11110

Differential Revision: D4237107

Pulled By: mkonicek

fbshipit-source-id: 15e82e030b762415c925ccb2a62ddb354a6e18b9
2016-11-28 08:28:35 -08:00