Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ through jscodeshift's `printOptions` command line argument
npx react-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
```

### `explicit-require=false`

If you're not explicitly importing React in your files (eg: if you're loading React with a script tag), you should add `--explicit-require=false`.

### Support and Contributing

The scripts in this repository are provided in the hope that they are useful,
Expand Down
4 changes: 4 additions & 0 deletions bin/__tests__/react-codemod-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('runTransform', () => {
transformer: 'rename-unsafe-xyz'
});
expect(console.log).toBeCalledWith(
// eslint-disable-next-line max-len
`Executing command: jscodeshift --verbose=2 --ignore-pattern=**/node_modules/** --parser flow --transform ${path.join(
transformerDirectory,
'rename-unsafe-xyz.js'
Expand All @@ -115,6 +116,7 @@ describe('runTransform', () => {
transformer: 'rename-unsafe-lifecycles'
});
expect(console.log).toBeCalledWith(
// eslint-disable-next-line max-len
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser flow --transform ${path.join(
transformerDirectory,
'rename-unsafe-lifecycles.js'
Expand All @@ -132,6 +134,7 @@ describe('runTransform', () => {
transformer: 'rename-unsafe-lifecycles'
});
expect(console.log).toBeCalledWith(
// eslint-disable-next-line max-len
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser tsx --extensions=tsx,ts --transform ${path.join(
transformerDirectory,
'rename-unsafe-lifecycles.js'
Expand All @@ -152,6 +155,7 @@ describe('runTransform', () => {
transformer: 'rename-unsafe-lifecycles'
});
expect(console.log).toBeCalledWith(
// eslint-disable-next-line max-len
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser babel --transform ${path.join(
transformerDirectory,
'rename-unsafe-lifecycles.js'
Expand Down
10 changes: 7 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function checkGitStatus(force) {
if (force) {
console.log(`WARNING: ${errorMessage}. Forcibly continuing.`);
} else {
console.log('Thank you for using jest-codemods!');
console.log('Thank you for using react-codemods!');
console.log(
chalk.yellow(
'\nBut before we continue, please stash or commit your git changes.'
Expand All @@ -46,7 +46,7 @@ function runTransform({ files, flags, parser, transformer, answers }) {

let args = [];

const { dry, print } = flags;
const { dry, print, explicitRequire } = flags;

if (dry) {
args.push('--dry');
Expand All @@ -55,6 +55,10 @@ function runTransform({ files, flags, parser, transformer, answers }) {
args.push('--print');
}

if (explicitRequire === 'false') {
args.push('--explicit-require=false');
}

args.push('--verbose=2');

args.push('--ignore-pattern=**/node_modules/**');
Expand Down Expand Up @@ -209,7 +213,7 @@ function run() {
`
},
{
boolean: ['force', 'dry', 'print', 'help'],
boolean: ['force', 'dry', 'print', 'explicit-require', 'help'],
string: ['_'],
alias: {
h: 'help'
Expand Down