To run this, you will first need to install the following npm packages:
npm i babylon babylon-walk glob
Then, with the script in the current directory in find-rn-imports.js
, you would want to run it, passing in
a glob pattern to hit all of the source code files in your repo. For instance I ran something like:
node ./find-rn-imports.js '!(node_modules|test)/**/*.js'
The output of that script will indicate which react native APIs you are importing and how many times in your
code base (though this assumes you are using import
and not require
).
For a recent RN project of ours:
name count
Alert 16
Platform 20
Text 47
View 65
StyleSheet 62
TextInput 7
Dimensions 31
TouchableOpacity 28
Image 30
Animated 14
TouchableHighlight 10
TouchableWithoutFeedback 9
StatusBar 5
Easing 9
ScrollView 6
ListView 7
UIManager 5
LayoutAnimation 5
PermissionsAndroid 1
Linking 8
NetInfo 1
AppState 3
NativeModules 4
InteractionManager 2
RefreshControl 2
ActionSheetIOS 1
Navigator 1
AsyncStorage 1