Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing the new "react-native upgrade"

Introducing the new "react-native upgrade"

Following React Native upgrades on an existing project has always been a pain. The process relies on a basic comparison between the existing files and the new ones. If the content differs, the developer has no other choice but to leave his file untouched or to override it...
What if we could use Git to handle changes from a React Native version to another ? Git comes with automatic-merge, 3-way merge and merge tools that could really boost the developer experience !

Nicolas Cuillery

January 18, 2017
Tweet

More Decks by Nicolas Cuillery

Other Decks in Programming

Transcript

  1. ME Nicolas Cuillery @ncuillery › JavaScript dev & trainer at

    Zenika. › Currently working on 6play apps.
  2. MyRNProject android ios ... ... ... “Host” apps Display a

    fullscreen React RootView. Contain the native part of RN & 3rd-parties.
  3. Why ? Unfriendly content Conflicts generally happen in native files,

    unfamiliar to the JS developer. Those file can even be not supposed to be touched by hand (project.pbxproj ) Fast pace RN is released on a monthly basis, making you repeating the process for each version. Necessary changes Chance of conflicts increases each time a native is touched: linking 3rd-parties, adding assets, configuring native stuff (device orientation, splashscreen, …)
  4. How to sort out the “conflicts” ? - Identify the

    undesirable conflicts - Knowing where do the changes come from (Developer or React Native)
  5. Working with a blank app By running the upgrade command

    on a blank app, the conflicts are only due to the React Native changes.
  6. rn-diff - Git is great to print differences in file

    contents. - Github is great to show them. https://github.com/ncuillery/rn-diff
  7. rn-diff - A branch for each version since 0.23.0. -

    Github compare view: https://github.com/ncuillery/rn-diff/compare /rn-0.33.0...rn-0.35.0
  8. A A React Native 0.X.0 React Native 0.Y.0 A B

    Developer’s changes If a conflicted file doesn’t appear in the rn-diff compare view, skip it with peace of mind
  9. Overwrite if the rn-diff shows the same (or almost the

    same) diff as Yeoman. And eventually report your changes by hand afterwards In other cases, rn-diff helps you take the good decision Do not overwrite If rn-diff shows a small amount of changes: skip the file and copy-paste the React Native changes manually
  10. Generate a Git patch › Simply append “.diff” to the

    compare view URL › Ready to “git apply --3way” ?
  11. Blob in the local repo index Add the rn-diff repo

    as remote and fetch it: git remote add rn-diff https://github.com/ncuillery/rn-diff.git git fetch rn-diff
  12. Project’s name in content We can’t modify the content of

    the patch, otherwise the blob would change and the apply operation would fail. Leave it like that and manually update after the apply operation.
  13. How to get rid of the drawbacks ? Git has

    to be the main tool… … but Yeoman is still in the game. Yeoman generates files that fit the user’s project perfectly
  14. Get the 3 files in Git index A C A

    Already in HEAD branch ! B Run the “upgrade” command on the current version and overwrite all files Install the new version, run the “upgrade” command and overwrite all files
  15. npm install -g react-native-git-upgrade › Separated package allowing upgrades from

    any version to any version › Will replace the upgrade command (ETA March 2017)
  16. Credits › Integration into RN: Christopher Chedeau (@vjeux), Konstantin Raev

    (@bestander_nz) and Martin Konicek (@martinkonicek) › Guidance about rn-diff: Ryan Kaskel (@ryankask) & Kenny Dits (@kenny_dee) › Allocated time for Open-Source development: Zenika › Presentation template: SlidesCarnival