[DevTools] chore: read from build/COMMIT_SHA fle as fallback for commit hash (#34915)
This eliminates the gap in a reproducer for the React DevTools browser extension from the source code that we submit to Firefox extension stores. We use the commit hash as part of the Backend version, here: https://github.com/facebook/react/blob/2cfb221937eac48209d01d5dda5664de473b1953/packages/react-devtools-extensions/utils.js#L26-L38 The problem is that we archive the source code for Mozilla extension store reviews and there is no git. But since we still download the React sources from the CI, we could reuse the hash from `build/COMMIT_HASH` file.
Ruslan Lesiutin committed
Oct 20, 2025 at 16:14 UTC
aaad0ea055ce0c10b263db8505338cb1eedb86de
1 file changed
+21
-3
packages/react-devtools-extensions/utils.js
+21
-3
@@ -6,7 +6,7 @@
6
*/
7
8
const {execSync} = require('child_process');
9
-const {readFileSync} = require('fs');
9
+const {existsSync, readFileSync} = require('fs');
10
const {resolve} = require('path');
11
12
const GITHUB_URL = 'https://github.com/facebook/react';
@@ -18,8 +18,26 @@ function getGitCommit() {
18
.trim();
19
} catch (error) {
20
// Mozilla runs this command from a git archive.
21
- // In that context, there is no Git revision.
22
- return null;
21
+ // In that context, there is no Git context.
22
+ // Using the commit hash specified to download-experimental-build.js script as a fallback.
23
+
24
+ // Try to read from build/COMMIT_SHA file
25
+ const commitShaPath = resolve(__dirname, '..', '..', 'build', 'COMMIT_SHA');
26
+ if (!existsSync(commitShaPath)) {
27
+ throw new Error(
28
+ 'Could not find build/COMMIT_SHA file. Did you run scripts/release/download-experimental-build.js script?',
29
+ );
30
+ }
31
+
32
+ try {
33
+ const commitHash = readFileSync(commitShaPath, 'utf8').trim();
34
+ // Return short hash (first 7 characters) to match abbreviated commit hash format
35
+ return commitHash.slice(0, 7);
36
+ } catch (readError) {
37
+ throw new Error(
38
+ `Failed to read build/COMMIT_SHA file: ${readError.message}`,
39
+ );
40
+ }
41
}
42
}
43