Skip to content

Commit 30b1a80

Browse files
authored
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.
1 parent 112168f commit 30b1a80

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

.circleci/config.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
- *run_yarn
125125
- run: ./scripts/circleci/add_build_info_json.sh
126126
- run: ./scripts/circleci/update_package_versions.sh
127-
- run: ./scripts/circleci/build.sh
127+
- run: yarn build
128128
- run: cp ./scripts/rollup/results.json ./build/bundle-sizes.json
129129
- run: ./scripts/circleci/upload_build.sh
130130
- run: ./scripts/circleci/pack_and_store_artifact.sh
@@ -145,7 +145,6 @@ jobs:
145145
- bundle-sizes.json
146146

147147
sizebot:
148-
build:
149148
docker: *docker
150149
environment: *environment
151150
steps:
@@ -155,6 +154,17 @@ jobs:
155154
- *run_yarn
156155
- run: node ./scripts/tasks/danger
157156

157+
lint_build:
158+
docker: *docker
159+
environment: *environment
160+
steps:
161+
- checkout
162+
- attach_workspace: *attach_workspace
163+
- *restore_yarn_cache
164+
- *run_yarn
165+
- run: yarn lint-build
166+
- run: scripts/circleci/check_minified_errors.sh
167+
158168
test_build:
159169
docker: *docker
160170
environment: *environment
@@ -222,6 +232,9 @@ workflows:
222232
- sizebot:
223233
requires:
224234
- build
235+
- lint_build:
236+
requires:
237+
- build
225238
- test_build:
226239
requires:
227240
- build

scripts/circleci/build.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Ensure errors are minified in production
4+
5+
OUT=$(git --no-pager grep -n --untracked --no-exclude-standard 'FIXME (minify-errors-in-prod)' -- './build/*')
6+
7+
if [ "$OUT" != "" ]; then
8+
echo "$OUT";
9+
echo -e "\n";
10+
echo "Detected an unminified error message in the production build. User-facing errors message must have a corresponding error code in scripts/error-codes/codes.json."
11+
exit 1
12+
fi
13+
14+
exit 0

scripts/error-codes/__tests__/__snapshots__/transform-error-messages.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`error transform should correctly transform invariants that are not in t
44
"import _ReactError from 'shared/ReactError';
55
66
import invariant from 'shared/invariant';
7-
(function () {
7+
/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
88
if (!condition) {
99
throw _ReactError(\`This is not a real error message.\`);
1010
}
@@ -15,7 +15,7 @@ exports[`error transform should handle escaped characters 1`] = `
1515
"import _ReactError from 'shared/ReactError';
1616
1717
import invariant from 'shared/invariant';
18-
(function () {
18+
/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
1919
if (!condition) {
2020
throw _ReactError(\`What's up?\`);
2121
}

scripts/error-codes/transform-error-messages.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,37 @@ module.exports = function(babel) {
6060
])
6161
);
6262

63+
if (noMinify) {
64+
// Error minification is disabled for this build.
65+
//
66+
// Outputs:
67+
// if (!condition) {
68+
// throw ReactError(`A ${adj} message that contains ${noun}`);
69+
// }
70+
path.replaceWith(
71+
t.ifStatement(
72+
t.unaryExpression('!', condition),
73+
t.blockStatement([devThrow])
74+
)
75+
);
76+
return;
77+
}
78+
6379
// Avoid caching because we write it as we go.
6480
const existingErrorMap = JSON.parse(
6581
fs.readFileSync(__dirname + '/codes.json', 'utf-8')
6682
);
6783
const errorMap = invertObject(existingErrorMap);
6884

6985
let prodErrorId = errorMap[errorMsgLiteral];
70-
if (prodErrorId === undefined || noMinify) {
71-
// There is no error code for this message. We use a lint rule to
72-
// enforce that messages can be minified, so assume this is
73-
// intentional and exit gracefully.
86+
87+
if (prodErrorId === undefined) {
88+
// There is no error code for this message. Add an inline comment
89+
// that flags this as an unminified error. This allows the build
90+
// to proceed, while also allowing a post-build linter to detect it.
7491
//
7592
// Outputs:
93+
// /* FIXME (minify-errors-in-prod): Unminified error message in production build! */
7694
// if (!condition) {
7795
// throw ReactError(`A ${adj} message that contains ${noun}`);
7896
// }
@@ -82,6 +100,10 @@ module.exports = function(babel) {
82100
t.blockStatement([devThrow])
83101
)
84102
);
103+
path.addComment(
104+
'leading',
105+
'FIXME (minify-errors-in-prod): Unminified error message in production build!'
106+
);
85107
return;
86108
}
87109
prodErrorId = parseInt(prodErrorId, 10);

0 commit comments

Comments
 (0)