utils.js — react Source File
Architecture documentation for utils.js, a javascript file in the react codebase.
Entity Profile
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const {execSync} = require('child_process');
const {existsSync, readFileSync} = require('fs');
const {resolve} = require('path');
const GITHUB_URL = 'https://github.com/facebook/react';
function getGitCommit() {
try {
return execSync('git show -s --no-show-signature --format=%h')
.toString()
.trim();
} catch (error) {
// Mozilla runs this command from a git archive.
// 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}`,
);
}
}
}
function getVersionString(packageVersion = null) {
if (packageVersion == null) {
packageVersion = JSON.parse(
readFileSync(
resolve(__dirname, '..', 'react-devtools-core', './package.json'),
),
).version;
}
const commit = getGitCommit();
return `${packageVersion}-${commit}`;
}
module.exports = {
GITHUB_URL,
getGitCommit,
getVersionString,
};
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does utils.js do?
utils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in utils.js?
utils.js defines 2 function(s): getGitCommit, getVersionString.
Where is utils.js in the architecture?
utils.js is located at packages/react-devtools-extensions/utils.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-extensions).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free