import-codemod
Flexible codemod for moving around imports.
It's super useful for migrating giant codebases to react-primitives
. It might be useful for some other things.
Usage
Create a config file (or use the included src/configs/config.primitives.js
)
yarn global add jscodeshiftyarn add import-codemod jscodeshift <path> -t ./node_modules/import-codemod/lib/index.js --config path-to-config.js
Things it can do
Move select named imports from one module to another
;// ->;
config.js
moduleexports = mappings: module: from: 'react-native' to: 'react-primitives' specifiers: 'Text' 'View' }
Move all named imports from one module to another
;// ->;
config.js
moduleexports = mappings: module: from: 'react-native' to: 'react-primitives' specifiers: '*'
Move and rename named imports from one module to another
;// ->;
config.js
moduleexports = mappings: module: from: 'react-native' to: 'react-primitives' specifiers: 'Text': 'Words' 'View': 'Box'
Move default imports from one module to another
;// ->;
config.js
moduleexports = mappings: module: from: 'react-native' to: 'react-primitives' specifiers: 'default'
Move default imports from one module to named imports of another
;// ->;
config.js
moduleexports = mappings: module: from: 'react-native' to: 'react-primitives' specifiers: 'default': 'Foo'
Exclude files from being transformed
// @ignoreMe…
config.js
moduleexports = ignoreMark: '@ignoreMe' mappings: