From f2948fb2ad5760aa3e194e2bdefb43eda82e4e01 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 5 Jan 2026 04:05:34 -0800 Subject: [PATCH] Remove unused code from scm-utils (#55036) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55036 Changelog: [Internal] Reviewed By: cortinico Differential Revision: D90107033 fbshipit-source-id: 701b02801a59ee0c910de772dfa75d924e78860b --- .../utils/__tests__/scm-utils-test.js | 44 +----------- scripts/releases/utils/scm-utils.js | 70 ++----------------- scripts/shared/isGitRepo.js | 4 -- 3 files changed, 6 insertions(+), 112 deletions(-) diff --git a/scripts/releases/utils/__tests__/scm-utils-test.js b/scripts/releases/utils/__tests__/scm-utils-test.js index 64bbacf1597..62b12717f3c 100644 --- a/scripts/releases/utils/__tests__/scm-utils-test.js +++ b/scripts/releases/utils/__tests__/scm-utils-test.js @@ -8,11 +8,10 @@ * @format */ -const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils'); +const {isTaggedLatest} = require('../scm-utils'); let execResult = null; -const cpMock = jest.fn(); -const mkdirSyncMock = jest.fn(); + jest .mock('shelljs', () => ({ exec: () => { @@ -26,11 +25,9 @@ jest exit: exitCode => { process.exit(exitCode); }, - cp: cpMock, })) .mock('fs', () => ({ existsSync: jest.fn().mockImplementation(_ => true), - mkdirSync: mkdirSyncMock, })) .mock('path', () => ({ dirname: jest @@ -58,41 +55,4 @@ describe('scm-utils', () => { expect(isTaggedLatest('6c19dc3266b8')).toBe(false); }); }); - - describe('saveFiles', () => { - it('it should save files in the temp folder', () => { - const tmpFolder = '/tmp'; - saveFiles(['package.json', 'android/package.json'], tmpFolder); - expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, { - recursive: true, - }); - expect(cpMock).toHaveBeenNthCalledWith( - 1, - 'package.json', - '/tmp/package.json', - ); - expect(cpMock).toHaveBeenNthCalledWith( - 2, - 'android/package.json', - `${tmpFolder}/android/package.json`, - ); - }); - }); - - describe('revertFiles', () => { - it('it should revert files from the temp folder', () => { - const tmpFolder = '/tmp'; - revertFiles(['package.json', 'android/package.json'], tmpFolder); - expect(cpMock).toHaveBeenNthCalledWith( - 1, - `${tmpFolder}/package.json`, - 'package.json', - ); - expect(cpMock).toHaveBeenNthCalledWith( - 2, - `${tmpFolder}/android/package.json`, - 'android/package.json', - ); - }); - }); }); diff --git a/scripts/releases/utils/scm-utils.js b/scripts/releases/utils/scm-utils.js index 986ae22453f..0f1e59d196c 100644 --- a/scripts/releases/utils/scm-utils.js +++ b/scripts/releases/utils/scm-utils.js @@ -10,28 +10,8 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const {cp, echo, exec, exit} = require('shelljs'); - -/*:: -type Commit = string; -*/ - -function isGitRepo() /*: boolean */ { - try { - return ( - exec('git rev-parse --is-inside-work-tree', { - silent: true, - }).stdout.trim() === 'true' - ); - } catch (error) { - echo( - `It wasn't possible to check if we are in a git repository. Details: ${error}`, - ); - } - return false; -} +const isGitRepo = require('../../shared/isGitRepo'); +const {echo, exec, exit} = require('shelljs'); function exitIfNotOnGit /*::*/( command /*: () => T */, @@ -47,7 +27,7 @@ function exitIfNotOnGit /*::*/( } } -function isTaggedLatest(commitSha /*: Commit */) /*: boolean */ { +function isTaggedLatest(commitSha /*: string */) /*: boolean */ { return ( exec(`git rev-list -1 latest | grep ${commitSha}`, { silent: true, @@ -61,7 +41,7 @@ function getBranchName() /*: string */ { }).stdout.trim(); } -function getCurrentCommit() /*: Commit */ { +function getCurrentCommit() /*: string */ { return isGitRepo() ? exec('git rev-parse HEAD', { silent: true, @@ -69,51 +49,9 @@ function getCurrentCommit() /*: Commit */ { : 'TEMP'; } -function saveFiles(filePaths /*: Array */, tmpFolder /*: string */) { - for (const filePath of filePaths) { - const dirName = path.dirname(filePath); - if (dirName !== '.') { - const destFolder = `${tmpFolder}/${dirName}`; - fs.mkdirSync(destFolder, {recursive: true}); - } - cp(filePath, `${tmpFolder}/${filePath}`); - } -} - -function revertFiles(filePaths /*: Array */, tmpFolder /*: string */) { - for (const filePath of filePaths) { - const absoluteTmpPath = `${tmpFolder}/${filePath}`; - if (fs.existsSync(absoluteTmpPath)) { - cp(absoluteTmpPath, filePath); - } else { - echo( - `It was not possible to revert ${filePath} since ${absoluteTmpPath} does not exist.`, - ); - exit(1); - } - } -} - -// git restore for local path -function restore(repoPath /*: string */) { - const result = exec('git restore .', { - cwd: repoPath, - }); - - if (result.code !== 0) { - throw new Error(result.stderr); - } - - return; -} - module.exports = { exitIfNotOnGit, getCurrentCommit, getBranchName, - isGitRepo, isTaggedLatest, - revertFiles, - saveFiles, - restore, }; diff --git a/scripts/shared/isGitRepo.js b/scripts/shared/isGitRepo.js index 0e4f6d2ade1..654ee51d292 100644 --- a/scripts/shared/isGitRepo.js +++ b/scripts/shared/isGitRepo.js @@ -12,10 +12,6 @@ const childProcess = require('child_process'); -/*:: -type Commit = string; -*/ - function isGitRepo() /*: boolean */ { try { const result = childProcess.execSync(