@jakubtkacz/expo-codemod
v0.1.1
Published
Codemods for migrating Expo apps between SDK versions
Maintainers
Readme
The @expo/codemod package is a CLI binary provided to help you upgrade between Expo SDK versions.
npx @expo/codemod <transform> <paths...>Usage
Run a transform against one or more paths or globs:
npx @expo/codemod <transform> <paths...>Options:
<transform> (required) name of transform to apply to files
(see a list of transforms available below)
<paths...> one or more paths or globs (e.g. src/**/*.tsx) of sources to transform
-h, --help print this help message
-v, --version print the CLI versionFor example, to run a transform over everything under src:
npx @expo/codemod sdk-56-expo-router-react-navigation-replace srcGlobs work too (wrap them in quotes so the shell doesn't expand them):
npx @expo/codemod sdk-56-expo-router-react-navigation-replace '**/*.{ts,tsx,js,jsx}'Transforms
sdk-56-expo-router-react-navigation-replace
Used to migrate a React Navigation app to Expo Router (SDK 56).
Replaces imports from @react-navigation/* with their expo-router equivalents.
| From | To |
| ----------------------------------- | -------------------------- |
| @react-navigation/native | expo-router |
| @react-navigation/stack | expo-router/js-stack |
| @react-navigation/bottom-tabs | expo-router/js-tabs |
| @react-navigation/material-top-tabs | expo-router/js-top-tabs |
Default and namespace imports (import X from ... / import * as X from ...) from the mapped packages are not supported.
Example
Input:
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { useRouter } from 'expo-router';Output:
import { NavigationContainer, useNavigation, useRouter } from "expo-router";Contributing
Adding a new transform
- Drop a new file under
src/transforms/namedsdk-<n>-<description>.tsexporting a default jscodeshiftTransformfunction. After the next build the runtime glob insrc/transforms/index.tspicks it up automatically — no other wiring needed. - Add a sibling test under
src/transforms/__tests__/<name>-test.tsusingapplyTransformfromjscodeshift/dist/testUtils. - Document the transform under
## Transformsabove with a from/to table and a short example.
