Skip to content

Commit 85893ea

Browse files
committed
chore: read from build/COMMIT_SHA fle as fallback for commit hash
1 parent 2cfb221 commit 85893ea

File tree

1 file changed

+21
-3
lines changed
  • packages/react-devtools-extensions

1 file changed

+21
-3
lines changed

packages/react-devtools-extensions/utils.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
const {execSync} = require('child_process');
9-
const {readFileSync} = require('fs');
9+
const {existsSync, readFileSync} = require('fs');
1010
const {resolve} = require('path');
1111

1212
const GITHUB_URL = 'https://github.com/facebook/react';
@@ -18,8 +18,26 @@ function getGitCommit() {
1818
.trim();
1919
} catch (error) {
2020
// 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+
}
2341
}
2442
}
2543

0 commit comments

Comments
 (0)