Skip to content

Commit 9a2ef23

Browse files
author
Sunil Pai
authored
adds back the explicit-require option (#232)
thanks to ismusidhu in #205
1 parent 6947283 commit 9a2ef23

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ through jscodeshift's `printOptions` command line argument
198198
npx react-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
199199
```
200200

201+
### `explicit-require=false`
202+
203+
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`.
204+
201205
### Support and Contributing
202206

203207
The scripts in this repository are provided in the hope that they are useful,

bin/__tests__/react-codemod-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('runTransform', () => {
9898
transformer: 'rename-unsafe-xyz'
9999
});
100100
expect(console.log).toBeCalledWith(
101+
// eslint-disable-next-line max-len
101102
`Executing command: jscodeshift --verbose=2 --ignore-pattern=**/node_modules/** --parser flow --transform ${path.join(
102103
transformerDirectory,
103104
'rename-unsafe-xyz.js'
@@ -115,6 +116,7 @@ describe('runTransform', () => {
115116
transformer: 'rename-unsafe-lifecycles'
116117
});
117118
expect(console.log).toBeCalledWith(
119+
// eslint-disable-next-line max-len
118120
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser flow --transform ${path.join(
119121
transformerDirectory,
120122
'rename-unsafe-lifecycles.js'
@@ -132,6 +134,7 @@ describe('runTransform', () => {
132134
transformer: 'rename-unsafe-lifecycles'
133135
});
134136
expect(console.log).toBeCalledWith(
137+
// eslint-disable-next-line max-len
135138
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser tsx --extensions=tsx,ts --transform ${path.join(
136139
transformerDirectory,
137140
'rename-unsafe-lifecycles.js'
@@ -152,6 +155,7 @@ describe('runTransform', () => {
152155
transformer: 'rename-unsafe-lifecycles'
153156
});
154157
expect(console.log).toBeCalledWith(
158+
// eslint-disable-next-line max-len
155159
`Executing command: jscodeshift --dry --verbose=2 --ignore-pattern=**/node_modules/** --parser babel --transform ${path.join(
156160
transformerDirectory,
157161
'rename-unsafe-lifecycles.js'

bin/cli.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function checkGitStatus(force) {
2727
if (force) {
2828
console.log(`WARNING: ${errorMessage}. Forcibly continuing.`);
2929
} else {
30-
console.log('Thank you for using jest-codemods!');
30+
console.log('Thank you for using react-codemods!');
3131
console.log(
3232
chalk.yellow(
3333
'\nBut before we continue, please stash or commit your git changes.'
@@ -46,7 +46,7 @@ function runTransform({ files, flags, parser, transformer, answers }) {
4646

4747
let args = [];
4848

49-
const { dry, print } = flags;
49+
const { dry, print, explicitRequire } = flags;
5050

5151
if (dry) {
5252
args.push('--dry');
@@ -55,6 +55,10 @@ function runTransform({ files, flags, parser, transformer, answers }) {
5555
args.push('--print');
5656
}
5757

58+
if (explicitRequire === 'false') {
59+
args.push('--explicit-require=false');
60+
}
61+
5862
args.push('--verbose=2');
5963

6064
args.push('--ignore-pattern=**/node_modules/**');
@@ -209,7 +213,7 @@ function run() {
209213
`
210214
},
211215
{
212-
boolean: ['force', 'dry', 'print', 'help'],
216+
boolean: ['force', 'dry', 'print', 'explicit-require', 'help'],
213217
string: ['_'],
214218
alias: {
215219
h: 'help'

0 commit comments

Comments
 (0)