Skip to content

Commit 260bcf7

Browse files
tido64facebook-github-bot
authored andcommitted
fix: limit diagnostics width output by hermesc (facebook#37531)
Summary: Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning. See issues filed: - microsoft/rnx-kit#2416 - microsoft/rnx-kit#2419 - microsoft/rnx-kit#2424 ## Changelog: [GENERAL] [FIXED] - Limit diagnostics width output by `hermesc` Pull Request resolved: facebook#37531 Test Plan: See listed issues for repros. Reviewed By: cipolleschi Differential Revision: D46102686 Pulled By: cortinico fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
1 parent e8b4bb0 commit 260bcf7

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ abstract class BundleHermesCTask : DefaultTask() {
174174
return windowsAwareCommandLine(
175175
hermesCommand,
176176
"-emit-binary",
177+
"-max-diagnostic-width=80",
177178
"-out",
178179
bytecodeFile.cliPath(rootFile),
179180
bundleFile.cliPath(rootFile),

packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,12 @@ class BundleHermesCTaskTest {
341341

342342
assertEquals(customHermesc, hermesCommand[0])
343343
assertEquals("-emit-binary", hermesCommand[1])
344-
assertEquals("-out", hermesCommand[2])
345-
assertEquals(bytecodeFile.absolutePath, hermesCommand[3])
346-
assertEquals(bundleFile.absolutePath, hermesCommand[4])
347-
assertEquals("my-custom-hermes-flag", hermesCommand[5])
348-
assertEquals(6, hermesCommand.size)
344+
assertEquals("-max-diagnostic-width=80", hermesCommand[2])
345+
assertEquals("-out", hermesCommand[3])
346+
assertEquals(bytecodeFile.absolutePath, hermesCommand[4])
347+
assertEquals(bundleFile.absolutePath, hermesCommand[5])
348+
assertEquals("my-custom-hermes-flag", hermesCommand[6])
349+
assertEquals(7, hermesCommand.size)
349350
}
350351

351352
@Test
@@ -366,11 +367,12 @@ class BundleHermesCTaskTest {
366367
assertEquals("/c", hermesCommand[1])
367368
assertEquals(customHermesc, hermesCommand[2])
368369
assertEquals("-emit-binary", hermesCommand[3])
369-
assertEquals("-out", hermesCommand[4])
370-
assertEquals(bytecodeFile.relativeTo(tempFolder.root).path, hermesCommand[5])
371-
assertEquals(bundleFile.relativeTo(tempFolder.root).path, hermesCommand[6])
372-
assertEquals("my-custom-hermes-flag", hermesCommand[7])
373-
assertEquals(8, hermesCommand.size)
370+
assertEquals("-max-diagnostic-width=80", hermesCommand[4])
371+
assertEquals("-out", hermesCommand[5])
372+
assertEquals(bytecodeFile.relativeTo(tempFolder.root).path, hermesCommand[6])
373+
assertEquals(bundleFile.relativeTo(tempFolder.root).path, hermesCommand[7])
374+
assertEquals("my-custom-hermes-flag", hermesCommand[8])
375+
assertEquals(9, hermesCommand.size)
374376
}
375377

376378
@Test

packages/react-native/scripts/react-native-xcode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ else
176176
if [[ $EMIT_SOURCEMAP == true ]]; then
177177
EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map"
178178
fi
179-
"$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
179+
"$HERMES_CLI_PATH" -emit-binary -max-diagnostic-width=80 "$EXTRA_COMPILER_ARGS" -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
180180
if [[ $EMIT_SOURCEMAP == true ]]; then
181181
HBC_SOURCEMAP_FILE="$DEST/main.jsbundle.map"
182182
"$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"

0 commit comments

Comments
 (0)