Skip to content

Commit ff4e8a3

Browse files
chrisbobbegnprice
authored andcommitted
metro: Try not to minify classnames that end in Error
Thanks to Tyler Rockwood for the tip to use metro-minifier-terser: zulip#5177 (comment)
1 parent 5a64dc0 commit ff4e8a3

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

metro.config.js

+18
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,23 @@ module.exports = {
7373
inlineRequires: true,
7474
},
7575
}),
76+
77+
// Use 'metro-minify-terser' (the default minifier at Metro v0.73.0+,
78+
// but we're not there yet) to get the keep_classnames option in the
79+
// minifierConfig, below.
80+
// TODO(react-native-71): Remove "not there yet" comment, and maybe
81+
// leave this unspecified to accept the default.
82+
minifierPath: 'metro-minify-terser',
83+
84+
minifierConfig: {
85+
// Looking at the implementation, it seems that the "minifier config"
86+
// is passed straight to the `terser` minifier (thanks to
87+
// `minifierPath` being set to 'metro-minify-terser'), so we should
88+
// use `terser`'s doc:
89+
// https://github.com/terser/terser#minify-options
90+
91+
// Don't minify our custom Error class names (for logging's sake)
92+
keep_classnames: /Error$/,
93+
},
7694
},
7795
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"jest-extended": "^3.2.0",
120120
"jetifier": "^2.0.0",
121121
"metro-babel-register": "^0.67.0",
122+
"metro-minify-terser": "^0.67.0",
122123
"metro-react-native-babel-preset": "^0.67.0",
123124
"prettier": "^2.6.2",
124125
"prettier-eslint": "^15.0.0",

src/utils/logging.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ export type Extras = {| +[key: string]: JSONable |};
2828
*/
2929
// TODO: Add linting to make sure all our custom errors extend this
3030
export class ExtendableError extends Error {
31-
// Careful! Minification might make this differ from what we see in our
32-
// source code, which would be kind of sad. (I guess we'll find out?)
33-
// Don't use this for equality checks or user-facing text:
34-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#javascript_compressors_and_minifiers.
31+
// Gotcha: Minification has been making this differ from what we see in
32+
// our source code. Don't use in equality checks or user-facing text:
33+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#javascript_compressors_and_minifiers
34+
// However, we're trying Metro's `minifierConfig` to see if we can have it
35+
// not minify classnames that end in Error.
3536
//
3637
// This will work even down a chain of subclasses, i.e.,
3738
// MyVerySpecificError extends MySpecificError extends ExtendableError. If

yarn.lock

+32-7
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@
17931793
"@jridgewell/set-array" "^1.0.0"
17941794
"@jridgewell/sourcemap-codec" "^1.4.10"
17951795

1796-
"@jridgewell/gen-mapping@^0.3.2":
1796+
"@jridgewell/gen-mapping@^0.3.0", "@jridgewell/gen-mapping@^0.3.2":
17971797
version "0.3.2"
17981798
resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9"
17991799
integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==
@@ -1812,6 +1812,14 @@
18121812
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
18131813
integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==
18141814

1815+
"@jridgewell/source-map@^0.3.2":
1816+
version "0.3.2"
1817+
resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb"
1818+
integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==
1819+
dependencies:
1820+
"@jridgewell/gen-mapping" "^0.3.0"
1821+
"@jridgewell/trace-mapping" "^0.3.9"
1822+
18151823
"@jridgewell/[email protected]", "@jridgewell/sourcemap-codec@^1.4.10":
18161824
version "1.4.14"
18171825
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
@@ -2898,10 +2906,10 @@ acorn@^7.1.1:
28982906
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
28992907
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==
29002908

2901-
acorn@^8.2.4, acorn@^8.8.0:
2902-
version "8.8.1"
2903-
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
2904-
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==
2909+
acorn@^8.2.4, acorn@^8.5.0, acorn@^8.8.0:
2910+
version "8.8.2"
2911+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
2912+
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
29052913

29062914
agent-base@6, agent-base@^6.0.2:
29072915
version "6.0.2"
@@ -4162,7 +4170,7 @@ command-exists@^1.2.4, command-exists@^1.2.8:
41624170
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69"
41634171
integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==
41644172

4165-
commander@^2.19.0:
4173+
commander@^2.19.0, commander@^2.20.0:
41664174
version "2.20.3"
41674175
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
41684176
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@@ -8665,6 +8673,13 @@ [email protected]:
86658673
ws "^7.5.1"
86668674
yargs "^15.3.1"
86678675

8676+
metro-minify-terser@^0.67.0:
8677+
version "0.67.0"
8678+
resolved "https://registry.yarnpkg.com/metro-minify-terser/-/metro-minify-terser-0.67.0.tgz#b056883db20d5818b0bf44b67920730768850156"
8679+
integrity sha512-twt08q2hS15cG0eR1pu6iYL5ckEdKR9iVENz096G3yl+YfPgK0xZtTXYQYQNOidqcord2ca4I6m/NVRxKhrxag==
8680+
dependencies:
8681+
terser "^5.10.0"
8682+
86688683
86698684
version "0.67.0"
86708685
resolved "https://registry.yarnpkg.com/metro-minify-uglify/-/metro-minify-uglify-0.67.0.tgz#28a77dbd78d9e558dba8c2f31c2b9c6f939df966"
@@ -11186,7 +11201,7 @@ source-map-resolve@^0.5.0:
1118611201
source-map-url "^0.4.0"
1118711202
urix "^0.1.0"
1118811203

11189-
source-map-support@^0.5.16, source-map-support@^0.5.6:
11204+
source-map-support@^0.5.16, source-map-support@^0.5.6, source-map-support@~0.5.20:
1119011205
version "0.5.21"
1119111206
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
1119211207
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
@@ -11719,6 +11734,16 @@ terminal-table@^0.0.12:
1171911734
colors "^1.0.3"
1172011735
eastasianwidth "^0.1.0"
1172111736

11737+
terser@^5.10.0:
11738+
version "5.16.1"
11739+
resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.1.tgz#5af3bc3d0f24241c7fb2024199d5c461a1075880"
11740+
integrity sha512-xvQfyfA1ayT0qdK47zskQgRZeWLoOQ8JQ6mIgRGVNwZKdQMU+5FkCBjmv4QjcrTzyZquRw2FVtlJSRUmMKQslw==
11741+
dependencies:
11742+
"@jridgewell/source-map" "^0.3.2"
11743+
acorn "^8.5.0"
11744+
commander "^2.20.0"
11745+
source-map-support "~0.5.20"
11746+
1172211747
test-exclude@^6.0.0:
1172311748
version "6.0.0"
1172411749
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"

0 commit comments

Comments
 (0)