@samitouri / QOS-React-2 / commits / 30b1a8009c

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.

Andrew Clark committed May 29, 2019 at 14:20 UTC 30b1a8009ce92d69b6debd1ff45dbb8a60f33b2f
5 files changed +57 -20
.circleci/config.yml
+15 -2
@@ -124,7 +124,7 @@ jobs:
124 - *run_yarn
125 - run: ./scripts/circleci/add_build_info_json.sh
126 - run: ./scripts/circleci/update_package_versions.sh
127 - - run: ./scripts/circleci/build.sh
127 + - run: yarn build
128 - run: cp ./scripts/rollup/results.json ./build/bundle-sizes.json
129 - run: ./scripts/circleci/upload_build.sh
130 - run: ./scripts/circleci/pack_and_store_artifact.sh
@@ -145,7 +145,6 @@ jobs:
145 - bundle-sizes.json
146
147 sizebot:
148 - build:
148 docker: *docker
149 environment: *environment
150 steps:
@@ -155,6 +154,17 @@ jobs:
154 - *run_yarn
155 - run: node ./scripts/tasks/danger
156
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 +
168 test_build:
169 docker: *docker
170 environment: *environment
@@ -222,6 +232,9 @@ workflows:
232 - sizebot:
233 requires:
234 - build
235 + - lint_build:
236 + requires:
237 + - build
238 - test_build:
239 requires:
240 - build
scripts/circleci/build.sh deleted
-12
@@ -1,12 +0,0 @@
1 -#!/bin/bash
2 -
3 -set -e
4 -
5 -yarn build --extract-errors
6 -# Note: since we run the full build including extracting error codes,
7 -# it is important that we *don't* reset the change to `scripts/error-codes/codes.json`.
8 -# When production bundle tests run later, it needs to be available.
9 -# See https://github.com/facebook/react/pull/11655.
10 -
11 -# Do a sanity check on bundles
12 -yarn lint-build
scripts/circleci/check_minified_errors.sh new
+14
@@ -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
+2 -2
@@ -4,7 +4,7 @@ exports[`error transform should correctly transform invariants that are not in t
4 "import _ReactError from 'shared/ReactError';
5
6 import invariant from 'shared/invariant';
7 -(function () {
7 +/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
8 if (!condition) {
9 throw _ReactError(\`This is not a real error message.\`);
10 }
@@ -15,7 +15,7 @@ exports[`error transform should handle escaped characters 1`] = `
15 "import _ReactError from 'shared/ReactError';
16
17 import invariant from 'shared/invariant';
18 -(function () {
18 +/*FIXME (minify-errors-in-prod): Unminified error message in production build!*/(function () {
19 if (!condition) {
20 throw _ReactError(\`What's up?\`);
21 }
scripts/error-codes/transform-error-messages.js
+26 -4
@@ -60,6 +60,22 @@ module.exports = function(babel) {
60 ])
61 );
62
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 +
79 // Avoid caching because we write it as we go.
80 const existingErrorMap = JSON.parse(
81 fs.readFileSync(__dirname + '/codes.json', 'utf-8')
@@ -67,12 +83,14 @@ module.exports = function(babel) {
83 const errorMap = invertObject(existingErrorMap);
84
85 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.
91 //
92 // Outputs:
93 + // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */
94 // if (!condition) {
95 // throw ReactError(`A ${adj} message that contains ${noun}`);
96 // }
@@ -82,6 +100,10 @@ module.exports = function(babel) {
100 t.blockStatement([devThrow])
101 )
102 );
103 + path.addComment(
104 + 'leading',
105 + 'FIXME (minify-errors-in-prod): Unminified error message in production build!'
106 + );
107 return;
108 }
109 prodErrorId = parseInt(prodErrorId, 10);