forked from facebook/react
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
./scripts/fiber/find-errors to make future Umbrella task easier
In facebook#7925 there is a task to: > Ensure we replace errors with invariant calls and they have sensible > messages While it is likely a bit premature to begin that work, this script will make it easier to find and replace the exact call sites to manage. Usage: ``` sh $ ./scripts/fiber/find-errors ``` ``` sh $ ./scripts/fiber/find-errors --quiet ```
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const jscodeshift = require('jscodeshift'); | ||
const Runner = require('jscodeshift/dist/Runner'); | ||
const path = require('path'); | ||
console.log(jscodeshift.Runner); | ||
|
||
const options = { | ||
path: [path.join(process.cwd(), 'src')], | ||
dry: true, | ||
cpus: 1, | ||
transform: path.join(__dirname, 'jscodeshift-find-error.js'), | ||
}; | ||
|
||
process.env.JSCODESHIFT_PRINT_LEVEL = process.argv.some(arg => /quiet/.test(arg)) ? 'quiet' : ''; | ||
console.log('Detecting Errors to convert to invariant calls.'); | ||
Runner.run( | ||
options.transform, | ||
options.path, | ||
options | ||
).then((results) => { | ||
console.log( | ||
'%s throw statements to to convert to `invariant`', | ||
results.stats.error | ||
); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const printLevel = process.env.JSCODESHIFT_PRINT_LEVEL; | ||
|
||
module.exports = (fileInfo, api) => { | ||
const jscodeshift = api.jscodeshift; | ||
if ( | ||
/__tests__|vendor/.test(fileInfo.path) | ||
) { | ||
return; | ||
} | ||
// slice off process.cwd() and leading / | ||
const normalizedPath = fileInfo.path.replace(process.cwd(), '').slice(1); | ||
|
||
jscodeshift(fileInfo.source) | ||
.find(jscodeshift.ThrowStatement) | ||
.forEach(path => { | ||
api.stats('error'); | ||
console.log( | ||
'%s#%s:', | ||
normalizedPath, | ||
path.value.loc.start.line | ||
); | ||
if (printLevel !== 'quiet') { | ||
console.log( | ||
jscodeshift(path).toSource().split('\n').map(line => ' ' + line).join('\n') | ||
); | ||
console.log(); | ||
} | ||
}); | ||
}; | ||
|