mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Don't extract errors in CI (#15758)
Removes `--extract-errors` argument from CI build script command. Instead, the author is expected to run `yarn extract-errors` locally or manually edit the error code map. The lint rule should be sufficient to catch unminified errors, but as an extra precaution, I added a post-build step that greps the production bundles. The post-build step works even if someone disables the lint rule for a specific line or file.
This commit is contained in:
@@ -4,7 +4,7 @@ exports[`error transform should correctly transform invariants that are not in t
|
||||
"import _ReactError from 'shared/ReactError';
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
(function () {
|
||||
/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
|
||||
if (!condition) {
|
||||
throw _ReactError(\`This is not a real error message.\`);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ exports[`error transform should handle escaped characters 1`] = `
|
||||
"import _ReactError from 'shared/ReactError';
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
(function () {
|
||||
/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
|
||||
if (!condition) {
|
||||
throw _ReactError(\`What's up?\`);
|
||||
}
|
||||
|
||||
@@ -60,17 +60,8 @@ module.exports = function(babel) {
|
||||
])
|
||||
);
|
||||
|
||||
// Avoid caching because we write it as we go.
|
||||
const existingErrorMap = JSON.parse(
|
||||
fs.readFileSync(__dirname + '/codes.json', 'utf-8')
|
||||
);
|
||||
const errorMap = invertObject(existingErrorMap);
|
||||
|
||||
let prodErrorId = errorMap[errorMsgLiteral];
|
||||
if (prodErrorId === undefined || noMinify) {
|
||||
// There is no error code for this message. We use a lint rule to
|
||||
// enforce that messages can be minified, so assume this is
|
||||
// intentional and exit gracefully.
|
||||
if (noMinify) {
|
||||
// Error minification is disabled for this build.
|
||||
//
|
||||
// Outputs:
|
||||
// if (!condition) {
|
||||
@@ -84,6 +75,37 @@ module.exports = function(babel) {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Avoid caching because we write it as we go.
|
||||
const existingErrorMap = JSON.parse(
|
||||
fs.readFileSync(__dirname + '/codes.json', 'utf-8')
|
||||
);
|
||||
const errorMap = invertObject(existingErrorMap);
|
||||
|
||||
let prodErrorId = errorMap[errorMsgLiteral];
|
||||
|
||||
if (prodErrorId === undefined) {
|
||||
// There is no error code for this message. Add an inline comment
|
||||
// that flags this as an unminified error. This allows the build
|
||||
// to proceed, while also allowing a post-build linter to detect it.
|
||||
//
|
||||
// Outputs:
|
||||
// /* FIXME (minify-errors-in-prod): Unminified error message in production build! */
|
||||
// if (!condition) {
|
||||
// throw ReactError(`A ${adj} message that contains ${noun}`);
|
||||
// }
|
||||
path.replaceWith(
|
||||
t.ifStatement(
|
||||
t.unaryExpression('!', condition),
|
||||
t.blockStatement([devThrow])
|
||||
)
|
||||
);
|
||||
path.addComment(
|
||||
'leading',
|
||||
'FIXME (minify-errors-in-prod): Unminified error message in production build!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
prodErrorId = parseInt(prodErrorId, 10);
|
||||
|
||||
// Import ReactErrorProd
|
||||
|
||||
Reference in New Issue
Block a user