Skip to content

Commit 743753f

Browse files
committed
Fix #11: Add ignore-pattern option, ignore node_modules by default
1 parent 7334d8e commit 743753f

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This is useful if you are sure that the code is already correct.
4848
| --- | --- | --- |
4949
| `-i` | `--incremental` | Run the migration tool in [incremental mode](#incremental-mode). |
5050
| `-e` | `--extensions` | Which file extensions to transform. Default: `.js` and `.ts`|
51+
| | `--ignore-pattern` | Ignore files that match the provided glob expression (default: `**/node_modules/**`).
5152
| `-l` | `--singleline` | Write log messages in a single line instead of printing the source location to a second line. |
5253
| `-v` | `--verbose` | Log verbose jscodeshift messages |
5354
| | `--force` | Overwrite files in the destination directory.

src/cli.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const argv = require('yargs')
4646
choices: ['js', 'ts'],
4747
default: ['js', 'ts']
4848
})
49+
.option('ignore-pattern', {
50+
group: optionalGroup,
51+
description: 'Ignore files that match the provided glob expression',
52+
type: 'string',
53+
default: '**/node_modules/**'
54+
})
4955
.option('singleline', {
5056
group: optionalGroup,
5157
alias: 'l',

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = async function migrate({
1616
extensions,
1717
incremental,
1818
force,
19-
verbose
19+
verbose,
20+
ignorePattern
2021
}) {
2122
const srcExists = fs.existsSync(src)
2223
const destExists = fs.existsSync(dest)
@@ -65,6 +66,8 @@ module.exports = async function migrate({
6566
'--parser=ts',
6667
'--transforms',
6768
transforms.join(','),
69+
'--ignore-pattern',
70+
ignorePattern,
6871
dest
6972
]
7073
if (singleline) {

test/test-runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = function prepareTests(dir, options = {}) {
3232
transforms: config.transforms,
3333
extensions: config.extensions,
3434
incremental: config.incremental,
35-
verbose: config.verbose
35+
verbose: config.verbose,
36+
ignorePattern: config.ignorePattern
3637
})
3738
}
3839

transforms/master-transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default function transformer(file, api, options: Options) {
105105
debug(`Skipping external transform '${name}' due to incremental mode`)
106106
continue
107107
}
108-
if (!stringSource) {
108+
if (typeof stringSource !== 'string') {
109109
stringSource = sources.toSource()
110110
sources = null
111111
}
@@ -138,7 +138,7 @@ export default function transformer(file, api, options: Options) {
138138
}
139139
}
140140

141-
if (!stringSource) {
141+
if (typeof stringSource !== 'string') {
142142
stringSource = sources.toSource()
143143
}
144144

0 commit comments

Comments
 (0)