forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support
parser
option for codemods, and enable ts parsing by d…
…efault (vuejs#4883) fixes vuejs#4861
- Loading branch information
1 parent
ef2cbae
commit b7f83b4
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
const jscodeshift = require('jscodeshift') | ||
const adapt = require('vue-jscodeshift-adapter') | ||
let jscodeshift = require('jscodeshift') | ||
|
||
module.exports = function runCodemod (transform, fileInfo, options) { | ||
return adapt(transform)(fileInfo, { jscodeshift }, options || {}) | ||
module.exports = function runCodemod (transformModule, fileInfo, options = {}) { | ||
const transform = typeof transformModule.default === 'function' | ||
? transformModule.default | ||
: transformModule | ||
|
||
let parser = transformModule.parser || options.parser | ||
if (!parser) { | ||
if (fileInfo.path.endsWith(('.ts'))) { | ||
parser = 'ts' | ||
} else if (fileInfo.path.endsWith('.tsx')) { | ||
parser = 'tsx' | ||
} | ||
} | ||
|
||
if (parser) { | ||
jscodeshift = jscodeshift.withParser(parser) | ||
} | ||
|
||
const api = { | ||
jscodeshift, | ||
j: jscodeshift, | ||
stats: () => {}, | ||
report: () => {} | ||
} | ||
|
||
return adapt(transform)(fileInfo, api, options) | ||
} |