2020-09-04 00:08:40 +08:00
|
|
|
/**
|
2022-10-18 11:19:24 -04:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2020-09-04 00:08:40 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-13 17:58:03 -07:00
|
|
|
const {execSync} = require('child_process');
|
2025-10-20 16:14:47 +01:00
|
|
|
const {existsSync, readFileSync} = require('fs');
|
2019-08-13 17:58:03 -07:00
|
|
|
const {resolve} = require('path');
|
2019-04-11 18:44:44 -07:00
|
|
|
|
2019-11-27 07:48:09 -08:00
|
|
|
const GITHUB_URL = 'https://github.com/facebook/react';
|
2019-04-11 19:06:07 -07:00
|
|
|
|
2019-11-27 07:48:09 -08:00
|
|
|
function getGitCommit() {
|
|
|
|
|
try {
|
2022-01-11 09:14:08 -08:00
|
|
|
return execSync('git show -s --no-show-signature --format=%h')
|
2019-11-27 07:48:09 -08:00
|
|
|
.toString()
|
|
|
|
|
.trim();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Mozilla runs this command from a git archive.
|
2025-10-20 16:14:47 +01:00
|
|
|
// In that context, there is no Git context.
|
|
|
|
|
// Using the commit hash specified to download-experimental-build.js script as a fallback.
|
|
|
|
|
|
|
|
|
|
// Try to read from build/COMMIT_SHA file
|
|
|
|
|
const commitShaPath = resolve(__dirname, '..', '..', 'build', 'COMMIT_SHA');
|
|
|
|
|
if (!existsSync(commitShaPath)) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Could not find build/COMMIT_SHA file. Did you run scripts/release/download-experimental-build.js script?',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const commitHash = readFileSync(commitShaPath, 'utf8').trim();
|
|
|
|
|
// Return short hash (first 7 characters) to match abbreviated commit hash format
|
|
|
|
|
return commitHash.slice(0, 7);
|
|
|
|
|
} catch (readError) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Failed to read build/COMMIT_SHA file: ${readError.message}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-05-23 11:55:32 -07:00
|
|
|
}
|
2019-04-11 18:44:44 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-27 17:18:48 -04:00
|
|
|
function getVersionString(packageVersion = null) {
|
|
|
|
|
if (packageVersion == null) {
|
|
|
|
|
packageVersion = JSON.parse(
|
|
|
|
|
readFileSync(
|
|
|
|
|
resolve(__dirname, '..', 'react-devtools-core', './package.json'),
|
|
|
|
|
),
|
|
|
|
|
).version;
|
|
|
|
|
}
|
2019-04-11 18:44:44 -07:00
|
|
|
|
2019-04-11 19:06:07 -07:00
|
|
|
const commit = getGitCommit();
|
2019-04-11 18:44:44 -07:00
|
|
|
|
|
|
|
|
return `${packageVersion}-${commit}`;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 07:48:09 -08:00
|
|
|
module.exports = {
|
|
|
|
|
GITHUB_URL,
|
|
|
|
|
getGitCommit,
|
|
|
|
|
getVersionString,
|
|
|
|
|
};
|