Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sibs-projects/codemod-RN24-to-RN25

A simple codemod to handle the new import style on RN25
https://github.com/sibs-projects/codemod-RN24-to-RN25

codemod react react-native

Last synced: 17 days ago
JSON representation

A simple codemod to handle the new import style on RN25

Awesome Lists containing this project

README

        

# README

Why this transform is necessary?

Until React Native 24, you import React from 'react-native' package, but [this will change in RN 25][1], you will need to import React from 'react', and also all the other React exports like Component, PropTypes, Children and so on.
You probably have many files that does this, so I've created a codemod to save you a bunch of time

# How to use this

1. Install jscodeshift
1. Download this transform
1. Navigate to the directory
1. Run the transform

```bash
# 1
npm install -g jscodeshift

# 2, 3
git clone https://github.com/sibeliusseraphini/codemod-RN24-to-RN25.git && cd codemod-RN24-to-RN25

# 4.
jscodeshift PATH_TO_FILES
```

# Example
```js
import React, {
Component,
View,
Text,
StyleSheet,
TouchableHighlight,
TextInput,
PropTypes,
} from 'react-native';
import NavigationBar from 'react-native-navbar';

class LoginScreen extends Component {
render() {
return (



);
}
}
```

Will be transformed to:
```js
import React, {Component, PropTypes} from "react";
import {View, Text, StyleSheet, TouchableHighlight, TextInput} from "react-native";
import NavigationBar from 'react-native-navbar';

class LoginScreen extends Component {
render() {
return (



);
}
}
```

### Recast Options

Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
through the `printOptions` command line argument. See the full list of options [here](https://github.com/benjamn/recast/blob/master/lib/options.js).

```sh
jscodeshift PATH_TO_FILES --printOptions='{"quote":"double"}'
```

[1]: https://github.com/facebook/react-native/releases/tag/v0.25.1