diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 214f324839ed..411cc83e799c 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -15540,10 +15540,12 @@ exports["default"] = newComponentCategory; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -16127,7 +16129,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/awaitStagingDeploys/index.js b/.github/actions/javascript/awaitStagingDeploys/index.js index 7ae106487882..8ffaac81af7a 100644 --- a/.github/actions/javascript/awaitStagingDeploys/index.js +++ b/.github/actions/javascript/awaitStagingDeploys/index.js @@ -12344,10 +12344,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12931,7 +12933,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/checkAndroidStatus/index.js b/.github/actions/javascript/checkAndroidStatus/index.js index fbfb62f9636f..bcb2fb90dfdf 100644 --- a/.github/actions/javascript/checkAndroidStatus/index.js +++ b/.github/actions/javascript/checkAndroidStatus/index.js @@ -737087,10 +737087,12 @@ checkAndroidStatus() Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -737674,7 +737676,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/checkDeployBlockers/index.js b/.github/actions/javascript/checkDeployBlockers/index.js index 36e405f2315a..e3762414978d 100644 --- a/.github/actions/javascript/checkDeployBlockers/index.js +++ b/.github/actions/javascript/checkDeployBlockers/index.js @@ -11611,10 +11611,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12198,7 +12200,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/checkSVGCompression/index.js b/.github/actions/javascript/checkSVGCompression/index.js index a0aec4f728a5..73d3aa1f1a63 100644 --- a/.github/actions/javascript/checkSVGCompression/index.js +++ b/.github/actions/javascript/checkSVGCompression/index.js @@ -20136,10 +20136,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -20723,7 +20725,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js index fa3e042e4885..7c46ed86022b 100644 --- a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js @@ -11739,10 +11739,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12485,7 +12487,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/getArtifactInfo/index.js b/.github/actions/javascript/getArtifactInfo/index.js index dad4ab512a3a..c239d1756e0a 100644 --- a/.github/actions/javascript/getArtifactInfo/index.js +++ b/.github/actions/javascript/getArtifactInfo/index.js @@ -11572,10 +11572,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12159,7 +12161,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/getDeployPullRequestList/index.js b/.github/actions/javascript/getDeployPullRequestList/index.js index 4990c6d5a805..86807369ae9d 100644 --- a/.github/actions/javascript/getDeployPullRequestList/index.js +++ b/.github/actions/javascript/getDeployPullRequestList/index.js @@ -11758,10 +11758,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12504,7 +12506,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/getPreviousVersion/index.js b/.github/actions/javascript/getPreviousVersion/index.js index c4a2a47fb5ec..950e9c7b157f 100644 --- a/.github/actions/javascript/getPreviousVersion/index.js +++ b/.github/actions/javascript/getPreviousVersion/index.js @@ -11569,10 +11569,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12315,7 +12317,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/getPullRequestDetails/index.js b/.github/actions/javascript/getPullRequestDetails/index.js index 028bf6dd3c4c..b731a960a7ef 100644 --- a/.github/actions/javascript/getPullRequestDetails/index.js +++ b/.github/actions/javascript/getPullRequestDetails/index.js @@ -11701,10 +11701,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12288,7 +12290,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/getPullRequestIncrementalChanges/index.js b/.github/actions/javascript/getPullRequestIncrementalChanges/index.js index 48bdf304a75c..56301e47dd84 100644 --- a/.github/actions/javascript/getPullRequestIncrementalChanges/index.js +++ b/.github/actions/javascript/getPullRequestIncrementalChanges/index.js @@ -11803,10 +11803,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12390,7 +12392,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, @@ -12536,18 +12538,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.GIT_ERRORS = void 0; const github_1 = __nccwpck_require__(5438); const child_process_1 = __nccwpck_require__(2081); const util_1 = __nccwpck_require__(3837); +const CONST_1 = __importDefault(__nccwpck_require__(9873)); const GithubUtils_1 = __importDefault(__nccwpck_require__(9296)); const Logger_1 = __nccwpck_require__(8891); -const exec = (0, util_1.promisify)(child_process_1.exec); +function exec(command, options) { + const optionsWithEncoding = { + encoding: 'utf8', + cwd: process.cwd(), + ...options, + }; + return (0, util_1.promisify)(child_process_1.exec)(command, optionsWithEncoding); +} +function execSync(command, options) { + const optionsWithEncoding = { + ...options, + encoding: 'utf8', + cwd: process.cwd(), + }; + return (0, child_process_1.execSync)(command, optionsWithEncoding); +} const IS_CI = process.env.CI === 'true'; -const GIT_ERRORS = { - FAILED_TO_FETCH_FROM_REMOTE: 'Failed to fetch from remote', -}; -exports.GIT_ERRORS = GIT_ERRORS; +const GITHUB_BASE_REF = process.env.GITHUB_BASE_REF; /** * Utility class for git operations. */ @@ -12560,9 +12574,7 @@ class Git { */ static isValidRef(ref) { try { - (0, child_process_1.execSync)(`git rev-parse --verify "${ref}^{object}"`, { - encoding: 'utf8', - cwd: process.cwd(), + execSync(`git rev-parse --verify "${ref}^{object}"`, { stdio: 'pipe', // Suppress output }); return true; @@ -12592,10 +12604,7 @@ class Git { command += ` -- ${quotedPaths}`; } // Execute git diff with unified format - let errors bubble up - const diffOutput = (0, child_process_1.execSync)(command, { - encoding: 'utf8', - cwd: process.cwd(), - }); + const diffOutput = execSync(command); return Git.parseDiff(diffOutput); } /** @@ -12758,7 +12767,7 @@ class Git { */ static show(ref, filePath) { try { - return (0, child_process_1.execSync)(`git show ${ref}:${filePath}`, { encoding: 'utf8' }); + return execSync(`git show ${ref}:${filePath}`); } catch (error) { throw new Error(`Failed to get file content from git: ${error instanceof Error ? error.message : String(error)}`); @@ -12776,33 +12785,30 @@ class Git { return; // Reference is already available locally } try { - console.log(`🔄 Fetching missing ref: ${ref}`); - await exec(`git fetch --no-tags --depth=1 ${remote} ${ref}`, { - encoding: 'utf8', - cwd: process.cwd(), - }); + (0, Logger_1.log)(`🔄 Fetching missing ref: ${ref}`); + await exec(`git fetch ${remote} ${ref} --no-tags --depth=1 --quiet`); // Verify the ref is now available if (!this.isValidRef(ref)) { - throw new Error(`Reference ${ref} is still not valid after fetching`); + throw new Error(`Reference ${ref} is still not valid after fetching from remote ${remote}`); } } catch (error) { throw new Error(`Failed to fetch git reference ${ref}: ${error instanceof Error ? error.message : String(error)}`); } } - static getMainBaseCommitHash(remote) { - // Fetch the main branch from the specified remote to ensure it's available - try { - (0, child_process_1.execSync)(`git fetch ${remote} main --no-tags --depth=1 -q`, { encoding: 'utf8' }); - } - catch (error) { - throw new Error(GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE); + static async getMainBranchCommitHash(remote) { + const baseRefName = GITHUB_BASE_REF ?? CONST_1.default.DEFAULT_BASE_REF; + // Fetch the main branch from the specified remote (or locally) to ensure it's available + if (IS_CI || remote) { + await exec(`git fetch ${remote ?? 'origin'} ${baseRefName} --no-tags --depth=1`); } // In CI, use a simpler approach - just use the remote main branch directly // This avoids issues with shallow clones and merge-base calculations if (IS_CI) { + const mainBaseRef = remote ? `${remote}/${baseRefName}` : `origin/${baseRefName}`; try { - const mergeBaseHash = (0, child_process_1.execSync)(`git rev-parse ${remote}/main`, { encoding: 'utf8' }).trim(); + const { stdout: revParseOutput } = await exec(`git rev-parse ${mainBaseRef}`); + const mergeBaseHash = revParseOutput.trim(); // Validate the output is a proper SHA hash if (!mergeBaseHash || !/^[a-fA-F0-9]{40}$/.test(mergeBaseHash)) { throw new Error(`git rev-parse returned unexpected output: ${mergeBaseHash}`); @@ -12810,25 +12816,27 @@ class Git { return mergeBaseHash; } catch (error) { - (0, Logger_1.error)(`Failed to get commit hash for ${remote}/main:`, error); - throw new Error(`Could not get commit hash for ${remote}/main`); + (0, Logger_1.error)(`Failed to get commit hash for ${mainBaseRef}:`, error); + throw new Error(`Could not get commit hash for ${mainBaseRef}`); } } + const mainBaseRef = remote ? `${remote}/${baseRefName}` : baseRefName; // For local development, try to find the actual merge base let mergeBaseHash; try { - mergeBaseHash = (0, child_process_1.execSync)(`git merge-base ${remote}/main HEAD`, { encoding: 'utf8' }).trim(); + const { stdout: mergeBaseOutput } = await exec(`git merge-base ${mainBaseRef} HEAD`); + mergeBaseHash = mergeBaseOutput.trim(); } - catch (error) { + catch { + (0, Logger_1.warn)(`Warning: Could not find merge base between ${mainBaseRef} and HEAD.`); // If merge-base fails locally, fall back to using the remote main branch try { - mergeBaseHash = (0, child_process_1.execSync)(`git rev-parse ${remote}/main`, { encoding: 'utf8' }).trim(); - (0, Logger_1.error)(`Warning: Could not find merge base between ${remote}/main and HEAD. Using ${remote}/main as base.`); + const { stdout: revParseOutput } = await exec(`git rev-parse ${mainBaseRef}`); + mergeBaseHash = revParseOutput.trim(); } catch (fallbackError) { - (0, Logger_1.error)(`Failed to find merge base with ${remote}/main:`, error); - (0, Logger_1.error)(`Fallback also failed:`, fallbackError); - throw new Error(`Could not determine merge base with ${remote}/main`); + (0, Logger_1.error)(`Failed to find merge base with ${mainBaseRef}:`, fallbackError); + throw new Error(`Could not determine merge base with ${mainBaseRef}`); } } // Validate the output is a proper SHA hash @@ -12837,33 +12845,35 @@ class Git { } return mergeBaseHash; } - static async getChangedFiles(remote) { + /** + * Check if there are any uncommitted changes (both staged and unstaged). + * + * @returns true if there are uncommitted changes, false otherwise + */ + static async hasUncommittedChanges() { + try { + const { stdout } = await exec('git status --porcelain'); + const status = stdout.trim(); + return status.length > 0; + } + catch (error) { + return false; + } + } + static async getChangedFileNames(fromRef, toRef = 'HEAD') { if (IS_CI) { const { data: changedFiles } = await GithubUtils_1.default.octokit.pulls.listFiles({ - owner: 'Expensify', - repo: 'App', + owner: CONST_1.default.GITHUB_OWNER, + repo: CONST_1.default.APP_REPO, // eslint-disable-next-line @typescript-eslint/naming-convention pull_number: github_1.context.payload.pull_request?.number ?? 0, }); return changedFiles.map((file) => file.filename); } - try { - // Get files changed in the current branch/commit - const mainBaseCommitHash = this.getMainBaseCommitHash(remote); - // Get the diff output and check status - const gitDiffOutput = (0, child_process_1.execSync)(`git diff --diff-filter=AMR --name-only ${mainBaseCommitHash} HEAD`, { - encoding: 'utf8', - }); - const files = gitDiffOutput.trim().split('\n'); - return files; - } - catch (error) { - if (error instanceof Error && error.message === GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE) { - throw error; - } - (0, Logger_1.error)('Could not determine changed files:', error); - throw error; - } + // Get the diff output and check status + const diffResult = this.diff(fromRef, toRef); + const files = diffResult.files.map((file) => file.filePath); + return files; } } exports["default"] = Git; @@ -12887,9 +12897,9 @@ const COLOR_BOLD = '\x1b[1m'; const EMOJIS = { // One column emojis need to be rendered with an extra space after to align with two column emojis INFO: '▶️ ', + WARN: '⚠️ ', // Two column emojis can be rendered as-is SUCCESS: '✅', - WARN: '⚠️', ERROR: '🔴', }; const log = (...args) => { diff --git a/.github/actions/javascript/isStagingDeployLocked/index.js b/.github/actions/javascript/isStagingDeployLocked/index.js index 17426f649697..f11329ae4f3a 100644 --- a/.github/actions/javascript/isStagingDeployLocked/index.js +++ b/.github/actions/javascript/isStagingDeployLocked/index.js @@ -11572,10 +11572,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12159,7 +12161,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/index.js b/.github/actions/javascript/markPullRequestsAsDeployed/index.js index 4fde88d74dfe..0a44de160bda 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/index.js +++ b/.github/actions/javascript/markPullRequestsAsDeployed/index.js @@ -13025,10 +13025,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -13612,7 +13614,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/postTestBuildComment/index.js b/.github/actions/javascript/postTestBuildComment/index.js index 22d189a62061..e2bb6cd44d57 100644 --- a/.github/actions/javascript/postTestBuildComment/index.js +++ b/.github/actions/javascript/postTestBuildComment/index.js @@ -11702,10 +11702,12 @@ exports["default"] = run; Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12289,7 +12291,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/proposalPoliceComment/index.js b/.github/actions/javascript/proposalPoliceComment/index.js index 911a29aa867a..26fffecafca1 100644 --- a/.github/actions/javascript/proposalPoliceComment/index.js +++ b/.github/actions/javascript/proposalPoliceComment/index.js @@ -11841,10 +11841,12 @@ function convertToNumber(value) { Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12428,7 +12430,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/reopenIssueWithComment/index.js b/.github/actions/javascript/reopenIssueWithComment/index.js index 4ba4badaa52e..25f1900a0c6e 100644 --- a/.github/actions/javascript/reopenIssueWithComment/index.js +++ b/.github/actions/javascript/reopenIssueWithComment/index.js @@ -11582,10 +11582,12 @@ reopenIssueWithComment() Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12169,7 +12171,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/reviewerChecklist/index.js b/.github/actions/javascript/reviewerChecklist/index.js index cb29c2546ce9..d32742027f2a 100644 --- a/.github/actions/javascript/reviewerChecklist/index.js +++ b/.github/actions/javascript/reviewerChecklist/index.js @@ -11674,10 +11674,12 @@ getNumberOfItemsFromReviewerChecklist() Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12261,7 +12263,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/actions/javascript/verifySignedCommits/index.js b/.github/actions/javascript/verifySignedCommits/index.js index 5ea3b9bdd64a..62087cfde03a 100644 --- a/.github/actions/javascript/verifySignedCommits/index.js +++ b/.github/actions/javascript/verifySignedCommits/index.js @@ -11614,10 +11614,12 @@ GithubUtils_1.default.octokit.pulls Object.defineProperty(exports, "__esModule", ({ value: true })); const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', }; const CONST = { ...GIT_CONST, @@ -12201,7 +12203,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path, ref = 'main') { + static async getFileContents(path, ref = CONST_1.default.DEFAULT_BASE_REF) { const { data } = await this.octokit.repos.getContent({ owner: CONST_1.default.GITHUB_OWNER, repo: CONST_1.default.APP_REPO, diff --git a/.github/libs/CONST.ts b/.github/libs/CONST.ts index ad7711426ca3..3a2b61c79801 100644 --- a/.github/libs/CONST.ts +++ b/.github/libs/CONST.ts @@ -1,9 +1,12 @@ const GITHUB_BASE_URL_REGEX = new RegExp('https?://(?:github\\.com|api\\.github\\.com)'); +const DEFAULT_REPO_IDENTIFIER = 'Expensify/App'; + const GIT_CONST = { GITHUB_OWNER: process.env.GITHUB_REPOSITORY_OWNER ?? 'Expensify', - APP_REPO: (process.env.GITHUB_REPOSITORY ?? 'Expensify/App').split('/').at(1) ?? '', + APP_REPO: (process.env.GITHUB_REPOSITORY ?? DEFAULT_REPO_IDENTIFIER).split('/').at(1) ?? '', MOBILE_EXPENSIFY_REPO: 'Mobile-Expensify', + DEFAULT_BASE_REF: 'main', } as const; const CONST = { diff --git a/.github/libs/GithubUtils.ts b/.github/libs/GithubUtils.ts index 281f1027d04c..a9983db69dc7 100644 --- a/.github/libs/GithubUtils.ts +++ b/.github/libs/GithubUtils.ts @@ -658,7 +658,7 @@ class GithubUtils { /** * Get the contents of a file from the API at a given ref as a string. */ - static async getFileContents(path: string, ref = 'main'): Promise { + static async getFileContents(path: string, ref = CONST.DEFAULT_BASE_REF): Promise { const {data} = await this.octokit.repos.getContent({ owner: CONST.GITHUB_OWNER, repo: CONST.APP_REPO, diff --git a/.github/workflows/react-compiler-compliance.yml b/.github/workflows/react-compiler-compliance.yml index 3afcdf1bbc1e..1a7f42ff01ac 100644 --- a/.github/workflows/react-compiler-compliance.yml +++ b/.github/workflows/react-compiler-compliance.yml @@ -5,17 +5,16 @@ on: pull_request: types: [opened, synchronize] branches-ignore: [staging, production] - paths: ['**.tsx'] + paths: ["**.tsx"] concurrency: - group: ${{ github.ref == 'refs/heads/main' && format('{0}-{1}', github.ref, github.sha) || github.ref }}-react-compiler-compliance + group: react-compiler-compliance-${{ github.ref == 'refs/heads/main' && format('{0}-{1}', github.ref, github.sha) || github.ref }} cancel-in-progress: true jobs: react-compiler-compliance: name: React Compiler Compliance if: ${{ github.actor != 'OSBotify' }} runs-on: ubuntu-latest - steps: # v4 - name: Checkout @@ -25,7 +24,7 @@ jobs: uses: ./.github/actions/composite/setupNode - name: Run React Compiler Compliance Check - run: npm run react-compiler-compliance-check check-changed + run: npm run react-compiler-compliance-check check-changed --filterByDiff --printSuppressedErrors env: CI: true GITHUB_TOKEN: ${{ github.token }} diff --git a/contributingGuides/REACT_COMPILER.md b/contributingGuides/REACT_COMPILER.md index 5901a35ff7be..997b07d04dae 100644 --- a/contributingGuides/REACT_COMPILER.md +++ b/contributingGuides/REACT_COMPILER.md @@ -32,7 +32,7 @@ npm run react-compiler-compliance-check check src/path/Component.tsx # Check spe npm run react-compiler-compliance-check check "src/**/*.tsx" # Check glob pattern ``` -#### Check only changed files against a remote main (default remote is `origin`) +#### Check only changed files (against main) ```bash npm run react-compiler-compliance-check check-changed @@ -47,12 +47,42 @@ npm run react-compiler-compliance-check check --report npm run react-compiler-compliance-check check-changed --report ``` -## How can I check what exactly prevents file from successful optimization or whether my fix for passing `react-compiler` actually works? +#### Additional flags -You can run a dedicated script: `react-compiler-healthcheck-test` and examine the output. This command will list the files that failed to compile with details on what caused the failures. It will then save this output to `./react-compiler-output.txt` file. Read and examine the output to find what specific error the react-compiler throws. +**Filter by diff changes (`--filterByDiff`)** + +Only check files that have been modified in the current diff. This is useful when you want to focus on files that have actual changes: + +```bash +npm run react-compiler-compliance-check check --filterByDiff +npm run react-compiler-compliance-check check-changed --filterByDiff +``` + +**Print successful compilations (`--printSuccesses`)** + +By default, the script only shows compilation failures. Use this flag to also display files that compiled successfully: + +```bash +npm run react-compiler-compliance-check check --printSuccesses +npm run react-compiler-compliance-check check-changed --printSuccesses +``` + +**Custom report filename (`--reportFileName`)** + +Specify a custom filename for the generated report instead of the default `react-compiler-report.json`: + +```bash +npm run react-compiler-compliance-check check --report --reportFileName my-custom-report.json +npm run react-compiler-compliance-check check-changed --report --reportFileName my-custom-report.json +``` + +**Custom remote name (`--remote`)** + +By default, the script uses `origin` as the base remote. If your GitHub remote is named differently, specify it with this flag: ```bash -npm run react-compiler-healthcheck-test +npm run react-compiler-compliance-check check-changed --remote upstream +npm run react-compiler-compliance-check check --filterByDiff --remote my-remote ``` ## How to fix a particular problem? diff --git a/package-lock.json b/package-lock.json index 65fd53ceefc8..7b9bb61fa251 100644 --- a/package-lock.json +++ b/package-lock.json @@ -227,7 +227,7 @@ "babel-jest": "29.7.0", "babel-loader": "^9.1.3", "babel-plugin-module-resolver": "^5.0.0", - "babel-plugin-react-compiler": "^19.0.0-beta-ebf51a3-20250411", + "babel-plugin-react-compiler": "1.0.0", "babel-plugin-react-native-web": "^0.18.7", "babel-plugin-transform-remove-console": "^6.9.4", "clean-webpack-plugin": "^4.0.0", @@ -247,7 +247,7 @@ "eslint-plugin-jest": "^29.0.1", "eslint-plugin-jsdoc": "^60.7.0", "eslint-plugin-lodash": "^7.4.0", - "eslint-plugin-react-compiler": "^19.0.0-beta-8a03594-20241020", + "eslint-plugin-react-compiler": "^19.1.0-rc.2", "eslint-plugin-react-native-a11y": "^3.3.0", "eslint-plugin-storybook": "^0.12.0", "eslint-plugin-testing-library": "^7.11.0", @@ -274,7 +274,6 @@ "portfinder": "^1.0.28", "prettier": "3.5.3", "react-compiler-healthcheck": "^19.0.0-beta-8a03594-20241020", - "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020", "react-native-clean-project": "^4.0.0-alpha4.0", "react-refresh": "^0.14.2", "react-test-renderer": "19.0.0", @@ -16498,8 +16497,10 @@ } }, "node_modules/babel-plugin-react-compiler": { - "version": "19.0.0-beta-ebf51a3-20250411", - "devOptional": true, + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-plugin-react-compiler/-/babel-plugin-react-compiler-1.0.0.tgz", + "integrity": "sha512-Ixm8tFfoKKIPYdCCKYTsqv+Fd4IJ0DQqMyEimo+pxUOMUR9cVPlwTrFt9Avu+3cb6Zp3mAzl+t1MrG2fxxKsxw==", + "dev": true, "license": "MIT", "dependencies": { "@babel/types": "^7.26.0" @@ -16573,181 +16574,6 @@ "@babel/core": "^7.0.0 || ^8.0.0-0" } }, - "node_modules/babel-preset-expo": { - "version": "13.2.4", - "resolved": "https://registry.npmjs.org/babel-preset-expo/-/babel-preset-expo-13.2.4.tgz", - "integrity": "sha512-3IKORo3KR+4qtLdCkZNDj8KeA43oBn7RRQejFGWfiZgu/NeaRUSri8YwYjZqybm7hn3nmMv9OLahlvXBX23o5Q==", - "license": "MIT", - "dependencies": { - "@babel/helper-module-imports": "^7.25.9", - "@babel/plugin-proposal-decorators": "^7.12.9", - "@babel/plugin-proposal-export-default-from": "^7.24.7", - "@babel/plugin-syntax-export-default-from": "^7.24.7", - "@babel/plugin-transform-export-namespace-from": "^7.25.9", - "@babel/plugin-transform-flow-strip-types": "^7.25.2", - "@babel/plugin-transform-modules-commonjs": "^7.24.8", - "@babel/plugin-transform-object-rest-spread": "^7.24.7", - "@babel/plugin-transform-parameters": "^7.24.7", - "@babel/plugin-transform-private-methods": "^7.24.7", - "@babel/plugin-transform-private-property-in-object": "^7.24.7", - "@babel/plugin-transform-runtime": "^7.24.7", - "@babel/preset-react": "^7.22.15", - "@babel/preset-typescript": "^7.23.0", - "@react-native/babel-preset": "0.79.6", - "babel-plugin-react-native-web": "~0.19.13", - "babel-plugin-syntax-hermes-parser": "^0.25.1", - "babel-plugin-transform-flow-enums": "^0.0.2", - "debug": "^4.3.4", - "react-refresh": "^0.14.2", - "resolve-from": "^5.0.0" - }, - "peerDependencies": { - "babel-plugin-react-compiler": "^19.0.0-beta-e993439-20250405" - }, - "peerDependenciesMeta": { - "babel-plugin-react-compiler": { - "optional": true - } - } - }, - "node_modules/babel-preset-expo/node_modules/@babel/traverse": { - "version": "7.28.4", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.4.tgz", - "integrity": "sha512-YEzuboP2qvQavAcjgQNVgsvHIDv6ZpwXvcvjmyySP2DIMuByS/6ioU5G9pYrWHM6T2YDfc7xga9iNzYOs12CFQ==", - "license": "MIT", - "dependencies": { - "@babel/code-frame": "^7.27.1", - "@babel/generator": "^7.28.3", - "@babel/helper-globals": "^7.28.0", - "@babel/parser": "^7.28.4", - "@babel/template": "^7.27.2", - "@babel/types": "^7.28.4", - "debug": "^4.3.1" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/babel-preset-expo/node_modules/@react-native/babel-plugin-codegen": { - "version": "0.79.6", - "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.79.6.tgz", - "integrity": "sha512-CS5OrgcMPixOyUJ/Sk/HSsKsKgyKT5P7y3CojimOQzWqRZBmoQfxdST4ugj7n1H+ebM2IKqbgovApFbqXsoX0g==", - "license": "MIT", - "dependencies": { - "@babel/traverse": "^7.25.3", - "@react-native/codegen": "0.79.6" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/babel-preset-expo/node_modules/@react-native/babel-preset": { - "version": "0.79.6", - "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.79.6.tgz", - "integrity": "sha512-H+FRO+r2Ql6b5IwfE0E7D52JhkxjeGSBSUpCXAI5zQ60zSBJ54Hwh2bBJOohXWl4J+C7gKYSAd2JHMUETu+c/A==", - "license": "MIT", - "dependencies": { - "@babel/core": "^7.25.2", - "@babel/plugin-proposal-export-default-from": "^7.24.7", - "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@babel/plugin-syntax-export-default-from": "^7.24.7", - "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", - "@babel/plugin-syntax-optional-chaining": "^7.8.3", - "@babel/plugin-transform-arrow-functions": "^7.24.7", - "@babel/plugin-transform-async-generator-functions": "^7.25.4", - "@babel/plugin-transform-async-to-generator": "^7.24.7", - "@babel/plugin-transform-block-scoping": "^7.25.0", - "@babel/plugin-transform-class-properties": "^7.25.4", - "@babel/plugin-transform-classes": "^7.25.4", - "@babel/plugin-transform-computed-properties": "^7.24.7", - "@babel/plugin-transform-destructuring": "^7.24.8", - "@babel/plugin-transform-flow-strip-types": "^7.25.2", - "@babel/plugin-transform-for-of": "^7.24.7", - "@babel/plugin-transform-function-name": "^7.25.1", - "@babel/plugin-transform-literals": "^7.25.2", - "@babel/plugin-transform-logical-assignment-operators": "^7.24.7", - "@babel/plugin-transform-modules-commonjs": "^7.24.8", - "@babel/plugin-transform-named-capturing-groups-regex": "^7.24.7", - "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7", - "@babel/plugin-transform-numeric-separator": "^7.24.7", - "@babel/plugin-transform-object-rest-spread": "^7.24.7", - "@babel/plugin-transform-optional-catch-binding": "^7.24.7", - "@babel/plugin-transform-optional-chaining": "^7.24.8", - "@babel/plugin-transform-parameters": "^7.24.7", - "@babel/plugin-transform-private-methods": "^7.24.7", - "@babel/plugin-transform-private-property-in-object": "^7.24.7", - "@babel/plugin-transform-react-display-name": "^7.24.7", - "@babel/plugin-transform-react-jsx": "^7.25.2", - "@babel/plugin-transform-react-jsx-self": "^7.24.7", - "@babel/plugin-transform-react-jsx-source": "^7.24.7", - "@babel/plugin-transform-regenerator": "^7.24.7", - "@babel/plugin-transform-runtime": "^7.24.7", - "@babel/plugin-transform-shorthand-properties": "^7.24.7", - "@babel/plugin-transform-spread": "^7.24.7", - "@babel/plugin-transform-sticky-regex": "^7.24.7", - "@babel/plugin-transform-typescript": "^7.25.2", - "@babel/plugin-transform-unicode-regex": "^7.24.7", - "@babel/template": "^7.25.0", - "@react-native/babel-plugin-codegen": "0.79.6", - "babel-plugin-syntax-hermes-parser": "0.25.1", - "babel-plugin-transform-flow-enums": "^0.0.2", - "react-refresh": "^0.14.0" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@babel/core": "*" - } - }, - "node_modules/babel-preset-expo/node_modules/@react-native/codegen": { - "version": "0.79.6", - "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.79.6.tgz", - "integrity": "sha512-iRBX8Lgbqypwnfba7s6opeUwVyaR23mowh9ILw7EcT2oLz3RqMmjJdrbVpWhGSMGq2qkPfqAH7bhO8C7O+xfjQ==", - "license": "MIT", - "dependencies": { - "@babel/core": "^7.25.2", - "@babel/parser": "^7.25.3", - "glob": "^7.1.1", - "hermes-parser": "0.25.1", - "invariant": "^2.2.4", - "nullthrows": "^1.1.1", - "yargs": "^17.6.2" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@babel/core": "*" - } - }, - "node_modules/babel-preset-expo/node_modules/babel-plugin-react-native-web": { - "version": "0.19.13", - "resolved": "https://registry.npmjs.org/babel-plugin-react-native-web/-/babel-plugin-react-native-web-0.19.13.tgz", - "integrity": "sha512-4hHoto6xaN23LCyZgL9LJZc3olmAxd7b6jDzlZnKXAh4rRAbZRKNBJoOOdp46OBqgy+K0t0guTj5/mhA8inymQ==", - "license": "MIT" - }, - "node_modules/babel-preset-expo/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/babel-preset-jest": { "version": "29.6.3", "license": "MIT", @@ -21280,14 +21106,16 @@ } }, "node_modules/eslint-plugin-react-compiler": { - "version": "19.0.0-beta-8a03594-20241020", + "version": "19.1.0-rc.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-compiler/-/eslint-plugin-react-compiler-19.1.0-rc.2.tgz", + "integrity": "sha512-oKalwDGcD+RX9mf3NEO4zOoUMeLvjSvcbbEOpquzmzqEEM2MQdp7/FY/Hx9NzmUwFzH1W9SKTz5fihfMldpEYw==", "dev": true, "license": "MIT", "dependencies": { "@babel/core": "^7.24.4", "@babel/parser": "^7.24.4", "@babel/plugin-proposal-private-methods": "^7.18.6", - "hermes-parser": "^0.20.1", + "hermes-parser": "^0.25.1", "zod": "^3.22.4", "zod-validation-error": "^3.0.3" }, @@ -21298,19 +21126,6 @@ "eslint": ">=7" } }, - "node_modules/eslint-plugin-react-compiler/node_modules/hermes-estree": { - "version": "0.20.1", - "dev": true, - "license": "MIT" - }, - "node_modules/eslint-plugin-react-compiler/node_modules/hermes-parser": { - "version": "0.20.1", - "dev": true, - "license": "MIT", - "dependencies": { - "hermes-estree": "0.20.1" - } - }, "node_modules/eslint-plugin-react-compiler/node_modules/zod": { "version": "3.25.76", "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", @@ -22089,6 +21904,24 @@ "expo": "*" } }, + "node_modules/expo/node_modules/@babel/traverse": { + "version": "7.28.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.4.tgz", + "integrity": "sha512-YEzuboP2qvQavAcjgQNVgsvHIDv6ZpwXvcvjmyySP2DIMuByS/6ioU5G9pYrWHM6T2YDfc7xga9iNzYOs12CFQ==", + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.27.1", + "@babel/generator": "^7.28.3", + "@babel/helper-globals": "^7.28.0", + "@babel/parser": "^7.28.4", + "@babel/template": "^7.27.2", + "@babel/types": "^7.28.4", + "debug": "^4.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/expo/node_modules/@expo/fingerprint": { "version": "0.13.0", "resolved": "https://registry.npmjs.org/@expo/fingerprint/-/fingerprint-0.13.0.tgz", @@ -22111,6 +21944,99 @@ "fingerprint": "bin/cli.js" } }, + "node_modules/expo/node_modules/@react-native/babel-plugin-codegen": { + "version": "0.79.6", + "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.79.6.tgz", + "integrity": "sha512-CS5OrgcMPixOyUJ/Sk/HSsKsKgyKT5P7y3CojimOQzWqRZBmoQfxdST4ugj7n1H+ebM2IKqbgovApFbqXsoX0g==", + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.25.3", + "@react-native/codegen": "0.79.6" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/expo/node_modules/@react-native/babel-preset": { + "version": "0.79.6", + "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.79.6.tgz", + "integrity": "sha512-H+FRO+r2Ql6b5IwfE0E7D52JhkxjeGSBSUpCXAI5zQ60zSBJ54Hwh2bBJOohXWl4J+C7gKYSAd2JHMUETu+c/A==", + "license": "MIT", + "dependencies": { + "@babel/core": "^7.25.2", + "@babel/plugin-proposal-export-default-from": "^7.24.7", + "@babel/plugin-syntax-dynamic-import": "^7.8.3", + "@babel/plugin-syntax-export-default-from": "^7.24.7", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", + "@babel/plugin-syntax-optional-chaining": "^7.8.3", + "@babel/plugin-transform-arrow-functions": "^7.24.7", + "@babel/plugin-transform-async-generator-functions": "^7.25.4", + "@babel/plugin-transform-async-to-generator": "^7.24.7", + "@babel/plugin-transform-block-scoping": "^7.25.0", + "@babel/plugin-transform-class-properties": "^7.25.4", + "@babel/plugin-transform-classes": "^7.25.4", + "@babel/plugin-transform-computed-properties": "^7.24.7", + "@babel/plugin-transform-destructuring": "^7.24.8", + "@babel/plugin-transform-flow-strip-types": "^7.25.2", + "@babel/plugin-transform-for-of": "^7.24.7", + "@babel/plugin-transform-function-name": "^7.25.1", + "@babel/plugin-transform-literals": "^7.25.2", + "@babel/plugin-transform-logical-assignment-operators": "^7.24.7", + "@babel/plugin-transform-modules-commonjs": "^7.24.8", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.24.7", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7", + "@babel/plugin-transform-numeric-separator": "^7.24.7", + "@babel/plugin-transform-object-rest-spread": "^7.24.7", + "@babel/plugin-transform-optional-catch-binding": "^7.24.7", + "@babel/plugin-transform-optional-chaining": "^7.24.8", + "@babel/plugin-transform-parameters": "^7.24.7", + "@babel/plugin-transform-private-methods": "^7.24.7", + "@babel/plugin-transform-private-property-in-object": "^7.24.7", + "@babel/plugin-transform-react-display-name": "^7.24.7", + "@babel/plugin-transform-react-jsx": "^7.25.2", + "@babel/plugin-transform-react-jsx-self": "^7.24.7", + "@babel/plugin-transform-react-jsx-source": "^7.24.7", + "@babel/plugin-transform-regenerator": "^7.24.7", + "@babel/plugin-transform-runtime": "^7.24.7", + "@babel/plugin-transform-shorthand-properties": "^7.24.7", + "@babel/plugin-transform-spread": "^7.24.7", + "@babel/plugin-transform-sticky-regex": "^7.24.7", + "@babel/plugin-transform-typescript": "^7.25.2", + "@babel/plugin-transform-unicode-regex": "^7.24.7", + "@babel/template": "^7.25.0", + "@react-native/babel-plugin-codegen": "0.79.6", + "babel-plugin-syntax-hermes-parser": "0.25.1", + "babel-plugin-transform-flow-enums": "^0.0.2", + "react-refresh": "^0.14.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/core": "*" + } + }, + "node_modules/expo/node_modules/@react-native/codegen": { + "version": "0.79.6", + "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.79.6.tgz", + "integrity": "sha512-iRBX8Lgbqypwnfba7s6opeUwVyaR23mowh9ILw7EcT2oLz3RqMmjJdrbVpWhGSMGq2qkPfqAH7bhO8C7O+xfjQ==", + "license": "MIT", + "dependencies": { + "@babel/core": "^7.25.2", + "@babel/parser": "^7.25.3", + "glob": "^7.1.1", + "hermes-parser": "0.25.1", + "invariant": "^2.2.4", + "nullthrows": "^1.1.1", + "yargs": "^17.6.2" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/core": "*" + } + }, "node_modules/expo/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -22132,6 +22058,60 @@ "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", "license": "MIT" }, + "node_modules/expo/node_modules/babel-plugin-react-compiler": { + "version": "19.0.0-beta-ebf51a3-20250411", + "resolved": "https://registry.npmjs.org/babel-plugin-react-compiler/-/babel-plugin-react-compiler-19.0.0-beta-ebf51a3-20250411.tgz", + "integrity": "sha512-q84bNR9JG1crykAlJUt5Ud0/5BUyMFuQww/mrwIQDFBaxsikqBDj3f/FNDsVd2iR26A1HvXKWPEIfgJDv8/V2g==", + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@babel/types": "^7.26.0" + } + }, + "node_modules/expo/node_modules/babel-plugin-react-native-web": { + "version": "0.19.13", + "resolved": "https://registry.npmjs.org/babel-plugin-react-native-web/-/babel-plugin-react-native-web-0.19.13.tgz", + "integrity": "sha512-4hHoto6xaN23LCyZgL9LJZc3olmAxd7b6jDzlZnKXAh4rRAbZRKNBJoOOdp46OBqgy+K0t0guTj5/mhA8inymQ==", + "license": "MIT" + }, + "node_modules/expo/node_modules/babel-preset-expo": { + "version": "13.2.4", + "resolved": "https://registry.npmjs.org/babel-preset-expo/-/babel-preset-expo-13.2.4.tgz", + "integrity": "sha512-3IKORo3KR+4qtLdCkZNDj8KeA43oBn7RRQejFGWfiZgu/NeaRUSri8YwYjZqybm7hn3nmMv9OLahlvXBX23o5Q==", + "license": "MIT", + "dependencies": { + "@babel/helper-module-imports": "^7.25.9", + "@babel/plugin-proposal-decorators": "^7.12.9", + "@babel/plugin-proposal-export-default-from": "^7.24.7", + "@babel/plugin-syntax-export-default-from": "^7.24.7", + "@babel/plugin-transform-export-namespace-from": "^7.25.9", + "@babel/plugin-transform-flow-strip-types": "^7.25.2", + "@babel/plugin-transform-modules-commonjs": "^7.24.8", + "@babel/plugin-transform-object-rest-spread": "^7.24.7", + "@babel/plugin-transform-parameters": "^7.24.7", + "@babel/plugin-transform-private-methods": "^7.24.7", + "@babel/plugin-transform-private-property-in-object": "^7.24.7", + "@babel/plugin-transform-runtime": "^7.24.7", + "@babel/preset-react": "^7.22.15", + "@babel/preset-typescript": "^7.23.0", + "@react-native/babel-preset": "0.79.6", + "babel-plugin-react-native-web": "~0.19.13", + "babel-plugin-syntax-hermes-parser": "^0.25.1", + "babel-plugin-transform-flow-enums": "^0.0.2", + "debug": "^4.3.4", + "react-refresh": "^0.14.2", + "resolve-from": "^5.0.0" + }, + "peerDependencies": { + "babel-plugin-react-compiler": "^19.0.0-beta-e993439-20250405" + }, + "peerDependenciesMeta": { + "babel-plugin-react-compiler": { + "optional": true + } + } + }, "node_modules/expo/node_modules/brace-expansion": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", @@ -22184,6 +22164,49 @@ "node": ">=6" } }, + "node_modules/expo/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/expo/node_modules/glob/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/expo/node_modules/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/expo/node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -31670,14 +31693,6 @@ "url": "https://github.com/sponsors/colinhacks" } }, - "node_modules/react-compiler-runtime": { - "version": "19.0.0-beta-8a03594-20241020", - "dev": true, - "license": "MIT", - "peerDependencies": { - "react": "^18.2.0 || ^19.0.0" - } - }, "node_modules/react-content-loader": { "version": "7.0.0", "license": "MIT", diff --git a/package.json b/package.json index 058b3568dacc..a199b409ad8b 100644 --- a/package.json +++ b/package.json @@ -298,7 +298,7 @@ "babel-jest": "29.7.0", "babel-loader": "^9.1.3", "babel-plugin-module-resolver": "^5.0.0", - "babel-plugin-react-compiler": "^19.0.0-beta-ebf51a3-20250411", + "babel-plugin-react-compiler": "1.0.0", "babel-plugin-react-native-web": "^0.18.7", "babel-plugin-transform-remove-console": "^6.9.4", "clean-webpack-plugin": "^4.0.0", @@ -318,7 +318,7 @@ "eslint-plugin-jest": "^29.0.1", "eslint-plugin-jsdoc": "^60.7.0", "eslint-plugin-lodash": "^7.4.0", - "eslint-plugin-react-compiler": "^19.0.0-beta-8a03594-20241020", + "eslint-plugin-react-compiler": "^19.1.0-rc.2", "eslint-plugin-react-native-a11y": "^3.3.0", "eslint-plugin-storybook": "^0.12.0", "eslint-plugin-testing-library": "^7.11.0", @@ -345,7 +345,6 @@ "portfinder": "^1.0.28", "prettier": "3.5.3", "react-compiler-healthcheck": "^19.0.0-beta-8a03594-20241020", - "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020", "react-native-clean-project": "^4.0.0-alpha4.0", "react-refresh": "^0.14.2", "react-test-renderer": "19.0.0", diff --git a/scripts/aggregateGitHubDataFromUpwork.ts b/scripts/aggregateGitHubDataFromUpwork.ts index f47b2b43e5cc..aab8fcc613e8 100644 --- a/scripts/aggregateGitHubDataFromUpwork.ts +++ b/scripts/aggregateGitHubDataFromUpwork.ts @@ -12,6 +12,7 @@ import {paginateRest} from '@octokit/plugin-paginate-rest'; import {throttling} from '@octokit/plugin-throttling'; import {createObjectCsvWriter} from 'csv-writer'; import fs from 'fs'; +import CONST from '@github/libs/CONST'; type OctokitOptions = {method: string; url: string; request: {retryCount: number}}; type IssueType = 'bug' | 'feature' | 'other'; @@ -112,7 +113,7 @@ async function getProjectsForIssue(issueNumber: number): Promise { const response = await octokit.graphql( ` { - repository(owner: "Expensify", name: "App") { + repository(owner: "${CONST.GITHUB_OWNER}", name: "${CONST.APP_REPO}") { issue(number: ${issueNumber}) { projectsV2(last: 30) { nodes { @@ -134,8 +135,8 @@ async function getGitHubData() { console.info(`Fetching ${issueNumber}`); const result = await octokit.rest.issues .get({ - owner: 'Expensify', - repo: 'App', + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, // eslint-disable-next-line @typescript-eslint/naming-convention issue_number: issueNumber, }) diff --git a/scripts/react-compiler-compliance-check.ts b/scripts/react-compiler-compliance-check.ts index 775c68958360..b7f150914eb3 100644 --- a/scripts/react-compiler-compliance-check.ts +++ b/scripts/react-compiler-compliance-check.ts @@ -11,74 +11,109 @@ import {writeFileSync} from 'fs'; import {join} from 'path'; import type {TupleToUnion} from 'type-fest'; import CLI from './utils/CLI'; -import Git, {GIT_ERRORS} from './utils/Git'; -import {bold, info, log, error as logError, success as logSuccess, note, warn} from './utils/Logger'; +import Git from './utils/Git'; +import {log, bold as logBold, error as logError, info as logInfo, note as logNote, success as logSuccess, warn as logWarn} from './utils/Logger'; + +const TAB = ' '; const DEFAULT_REPORT_FILENAME = 'react-compiler-report.json'; -type HealthcheckJsonResults = { - success: string[]; - failures: CompilerFailure; -}; +const SUPPRESSED_COMPILER_ERRORS = [ + // This error is caused by an internal limitation of React Compiler + // https://github.com/facebook/react/issues/29583 + '(BuildHIR::lowerExpression) Expected Identifier, got MemberExpression key in ObjectExpression', +] as const satisfies string[]; + +const VERBOSE_OUTPUT_LINE_REGEXES = { + SUCCESS: /Successfully compiled (?:hook|component) \[([^\]]+)\]\(([^)]+)\)/, + FAILURE_WITH_REASON: /Failed to compile ([^:]+):(\d+):(\d+)\. Reason: (.+)/, + FAILURE_WITHOUT_REASON: /Failed to compile ([^:]+):(\d+):(\d+)\./, + REASON: /Reason: (.+)/, +} as const satisfies Record; + +type FailureMap = Map; type CompilerResults = { success: Set; - failures: Map; + failures: FailureMap; + suppressedFailures: FailureMap; }; type CompilerFailure = { file: string; line?: number; column?: number; - reason: string; + reason?: string; +}; + +type DiffFilteringCommits = { + from: string; + to: string; +}; + +type PrintResultsOptions = { + shouldPrintSuccesses: boolean; + shouldPrintSuppressedErrors: boolean; +}; + +type BaseCheckOptions = PrintResultsOptions & { + remote?: string; + reportFileName?: string; + shouldGenerateReport?: boolean; + shouldFilterByDiff?: boolean; +}; + +type CheckOptions = BaseCheckOptions & { + files?: string[]; }; -function check(filesToCheck?: string[], shouldGenerateReport = false) { - if (filesToCheck) { - info(`Running React Compiler check for ${filesToCheck.length} files or glob patterns...`); +async function check({ + files, + shouldGenerateReport = false, + reportFileName = DEFAULT_REPORT_FILENAME, + shouldFilterByDiff = false, + remote, + shouldPrintSuccesses = false, + shouldPrintSuppressedErrors = false, +}: CheckOptions): Promise { + if (files) { + logInfo(`Running React Compiler check for ${files.length} files or glob patterns...`); } else { - info('Running React Compiler check for all files...'); + logInfo('Running React Compiler check for all files...'); } - const src = createFilesGlob(filesToCheck); - const results = runCompilerHealthcheck(src); + const src = createFilesGlob(files); + let results = runCompilerHealthcheck(src); - const isPassed = results.failures.size === 0; - if (isPassed) { - logSuccess('All changed files pass React Compiler compliance check!'); - return true; + if (shouldFilterByDiff) { + const mainBaseCommitHash = await Git.getMainBranchCommitHash(remote); + const diffFilteringCommits: DiffFilteringCommits = {from: mainBaseCommitHash, to: 'HEAD'}; + + results = await filterResultsByDiff(results, diffFilteringCommits, {shouldPrintSuccesses, shouldPrintSuppressedErrors}); } - printFailureSummary(results); + printResults(results, {shouldPrintSuccesses, shouldPrintSuppressedErrors}); if (shouldGenerateReport) { - generateReport(results, DEFAULT_REPORT_FILENAME); + generateReport(results, reportFileName); } - return false; + const isPassed = results.failures.size === 0; + return isPassed; } -async function checkChangedFiles(remote: string): Promise { - info('Checking changed files for React Compiler compliance...'); +async function checkChangedFiles({remote, ...restOptions}: BaseCheckOptions): Promise { + logInfo('Checking changed files for React Compiler compliance...'); - try { - const changedFiles = await Git.getChangedFiles(remote); - const filesToCheck = [...new Set(changedFiles)]; + const mainBaseCommitHash = await Git.getMainBranchCommitHash(remote); + const changedFiles = await Git.getChangedFileNames(mainBaseCommitHash); - if (filesToCheck.length === 0) { - logSuccess('No React files changed, skipping check.'); - return true; - } - - return check(filesToCheck); - } catch (error) { - if (error instanceof Error && error.message === GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE) { - logError(`Could not fetch from remote ${remote}. If your base remote is not ${remote}, please specify another remote with the --remote flag.`); - } - - logError('Could not determine changed files:', error); - return false; + if (changedFiles.length === 0) { + logSuccess('No React files changed, skipping check.'); + return true; } + + return check({files: changedFiles, ...restOptions}); } function runCompilerHealthcheck(src?: string): CompilerResults { @@ -88,188 +123,304 @@ function runCompilerHealthcheck(src?: string): CompilerResults { srcString = srcString?.endsWith('"') ? srcString : `${srcString}"`; } - const command = `npx react-compiler-healthcheck ${src ? `--src ${srcString}` : ''} --json --verbose `; + const command = `npx react-compiler-healthcheck ${src ? `--src ${srcString}` : ''} --verbose`; const output = execSync(command, { encoding: 'utf8', cwd: process.cwd(), }); - // Parse and then normalize via Set/Map to ensure true uniqueness - const parsed = parseCombinedOutput(output); + return parseHealthcheckOutput(output); +} - // Use Set to deduplicate success entries - const successSet = new Set(parsed.success); +// eslint-disable-next-line rulesdir/no-negated-variables +function addFailureIfDoesNotExist(failureMap: FailureMap, newFailure: CompilerFailure): boolean { + const key = getUniqueFileKey(newFailure); + const existingFailure = failureMap.get(key); - // Use Map keyed by unique file key to deduplicate failures - const failureMap = new Map(); - parsed.failures.forEach((failure) => { - const key = getUniqueFileKey(failure); - // Prefer the first occurrence that has a reason - const existing = failureMap.get(key); - if (!existing) { - failureMap.set(key, failure); - return; - } - if (!existing.reason && failure.reason) { - failureMap.set(key, failure); + if (existingFailure) { + const isReasonSet = !!existingFailure.reason; + const isNewReasonSet = !!newFailure.reason; + if (!isReasonSet && isNewReasonSet) { + failureMap.set(key, newFailure); + return true; } - }); - return {success: successSet, failures: failureMap}; + return false; + } + + failureMap.set(key, newFailure); + return true; } -function parseCombinedOutput(output: string): CompilerResults { +function parseHealthcheckOutput(output: string): CompilerResults { const lines = output.split('\n'); - const successSet = new Set(); - const failure = new Map(); - - // First, try to extract JSON from the output - let jsonStart = -1; - let jsonEnd = -1; - for (let i = 0; i < lines.length; i++) { - if (lines.at(i)?.trim().startsWith('{')) { - jsonStart = i; - } - if (jsonStart !== -1 && lines.at(i)?.trim().endsWith('}')) { - jsonEnd = i; - break; - } - } - // Parse JSON if found - if (jsonStart !== -1 && jsonEnd !== -1) { - try { - const jsonLines = lines.slice(jsonStart, jsonEnd + 1); - const jsonStr = jsonLines.join('\n'); - const jsonResult = JSON.parse(jsonStr) as HealthcheckJsonResults; - jsonResult.success.forEach((success) => successSet.add(success)); - } catch (error) { - warn('Failed to parse JSON from combined output:', error); - } - } else { - warn('No JSON found in combined output, parsing verbose text only'); - } + const results: CompilerResults = { + success: new Set(), + failures: new Map(), + suppressedFailures: new Map(), + }; - // Parse verbose output for detailed failure information - let currentFailure: CompilerFailure | null = null; + let currentFailureWithoutReason: CompilerFailure | null = null; + // Parse verbose output for (const line of lines) { - // Parse successful compilation from verbose output - const successMatch = line.match(/Successfully compiled (?:hook|component) \[([^\]]+)\]\(([^)]+)\)/); + // Parse successful file paths + const successMatch = line.match(VERBOSE_OUTPUT_LINE_REGEXES.SUCCESS); if (successMatch) { const filePath = successMatch[2]; - successSet.add(filePath); + results.success.add(filePath); continue; } - // Parse failed compilation with file, location, and reason all on one line - const failureWithReasonMatch = line.match(/Failed to compile ([^:]+):(\d+):(\d+)\. Reason: (.+)/); + // Parse failed file paths with file, location, and reason all on one line + const failureWithReasonMatch = line.match(VERBOSE_OUTPUT_LINE_REGEXES.FAILURE_WITH_REASON); if (failureWithReasonMatch) { - const newFailure = { + const newFailure: CompilerFailure = { file: failureWithReasonMatch[1], line: parseInt(failureWithReasonMatch[2], 10), column: parseInt(failureWithReasonMatch[3], 10), reason: failureWithReasonMatch[4], }; - const key = getUniqueFileKey(newFailure); - // Only add if not already exists, or if existing one has no reason - const existing = failure.get(key); - if (!existing?.reason) { - failure.set(key, newFailure); + // If we already have a reason, we don't want to set the reason again + currentFailureWithoutReason = null; + + if (shouldSuppressCompilerError(newFailure.reason)) { + addFailureIfDoesNotExist(results.suppressedFailures, newFailure); + continue; } - currentFailure = null; - continue; + + // Only add if failure does not exist already, or if existing one has no reason + addFailureIfDoesNotExist(results.failures, newFailure); } // Parse failed compilation with file and location only (fallback) - const failureMatch = line.match(/Failed to compile ([^:]+):(\d+):(\d+)\./); - if (failureMatch) { - // Save previous failure if exists - if (currentFailure) { - const key = getUniqueFileKey(currentFailure); - const existing = failure.get(key); - if (!existing?.reason) { - failure.set(key, currentFailure); - } - } + const failureWithoutReasonMatch = line.match(VERBOSE_OUTPUT_LINE_REGEXES.FAILURE_WITHOUT_REASON); + if (failureWithoutReasonMatch) { + const newFailure: CompilerFailure = { + file: failureWithoutReasonMatch[1], + line: parseInt(failureWithoutReasonMatch[2], 10), + column: parseInt(failureWithoutReasonMatch[3], 10), + }; - const key = getUniqueFileKey({ - file: failureMatch[1], - line: parseInt(failureMatch[2], 10), - column: parseInt(failureMatch[3], 10), - reason: '', - }); + currentFailureWithoutReason = newFailure; // Only create new failure if it doesn't exist - if (failure.has(key)) { - // Use existing failure if it exists - const existingFailure = failure.get(key); - if (existingFailure) { - currentFailure = existingFailure; - } - continue; - } + addFailureIfDoesNotExist(results.failures, newFailure); - currentFailure = { - file: failureMatch[1], - line: parseInt(failureMatch[2], 10), - column: parseInt(failureMatch[3], 10), - reason: '', - }; continue; } // Parse reason line (fallback for multi-line reasons) - const reasonMatch = line.match(/Reason: (.+)/); - if (reasonMatch && currentFailure) { - // Only update reason if it's not already set - if (!currentFailure.reason) { - currentFailure.reason = reasonMatch[1]; - failure.set(getUniqueFileKey(currentFailure), currentFailure); + const reasonMatch = line.match(VERBOSE_OUTPUT_LINE_REGEXES.REASON); + if (reasonMatch && currentFailureWithoutReason) { + const reason = reasonMatch[1]; + + const currentFailure: CompilerFailure = { + file: currentFailureWithoutReason.file, + line: currentFailureWithoutReason.line, + column: currentFailureWithoutReason.column, + reason, + }; + + currentFailureWithoutReason = null; + + if (shouldSuppressCompilerError(reason)) { + addFailureIfDoesNotExist(results.suppressedFailures, currentFailure); + continue; } - currentFailure = null; - continue; + + addFailureIfDoesNotExist(results.failures, currentFailure); } } - // Add any remaining failure - if (currentFailure) { - const key = getUniqueFileKey(currentFailure); - const existing = failure.get(key); - if (!existing?.reason) { - failure.set(key, currentFailure); - } + return results; +} + +function shouldSuppressCompilerError(reason: string | undefined): boolean { + if (!reason) { + return false; } - return {success: successSet, failures: failure}; + // Check if the error reason matches any of the suppressed error patterns + return SUPPRESSED_COMPILER_ERRORS.some((suppressedError) => reason.includes(suppressedError)); } -function getUniqueFileKey(failure: CompilerFailure): string { - return `${failure.file}:${failure.line}:${failure.column}`; +function getUniqueFileKey({file, line, column}: CompilerFailure): string { + const isLineSet = line !== undefined; + const isLineAndColumnSet = isLineSet && column !== undefined; + + return file + (isLineSet ? `:${line}` : '') + (isLineAndColumnSet ? `:${column}` : ''); } -function createFilesGlob(filesToCheck?: string[]): string | undefined { - if (!filesToCheck || filesToCheck.length === 0) { +function createFilesGlob(files?: string[]): string | undefined { + if (!files || files.length === 0) { return undefined; } - if (filesToCheck.length === 1) { - return filesToCheck.at(0); + if (files.length === 1) { + return files.at(0); } - return `**/+(${filesToCheck.join('|')})`; + return `**/+(${files.join('|')})`; } -function printFailureSummary({success, failures}: CompilerResults): void { - // const failedFileNames = getDistinctFileNames(Array.from(failures.values()), (f) => f.file, fileToCheck); +/** + * Filters compiler results to only include failures for lines that were changed in the git diff. + * This helps focus on new issues introduced by the current changes rather than pre-existing issues. + * + * @param results - The compiler results to filter + * @param diffFilteringCommits - The commit range to diff (from and to) + * @returns Filtered compiler results containing only failures in changed lines + */ +async function filterResultsByDiff( + results: CompilerResults, + diffFilteringCommits: DiffFilteringCommits, + {shouldPrintSuccesses, shouldPrintSuppressedErrors}: PrintResultsOptions, +): Promise { + // Check for uncommitted changes and warn if any exist + if (await Git.hasUncommittedChanges()) { + logWarn('Warning: You have uncommitted changes. The diff results may not accurately reflect your current working directory.'); + } + + logInfo(`Filtering results by diff between ${diffFilteringCommits.from} and ${diffFilteringCommits.to}...`); + + // Get the diff between the two commits + const diffResult = Git.diff(diffFilteringCommits.from, diffFilteringCommits.to); + + // If there are no changes, return empty results + if (!diffResult.hasChanges) { + return { + success: new Set(), + failures: new Map(), + suppressedFailures: new Map(), + }; + } + + // Create a map of file paths to changed line numbers for quick lookup + const changedLinesMap = new Map>(); + for (const file of diffResult.files) { + const changedLines = new Set([...file.addedLines, ...file.modifiedLines]); + changedLinesMap.set(file.filePath, changedLines); + } + + // Filter failures to only include those on changed lines + const filteredFailures = new Map(); + results.failures.forEach((failure, key) => { + const changedLines = changedLinesMap.get(failure.file); + + // If the file is not in the diff, skip this failure + if (!changedLines) { + return; + } + + // If the failure has a line number, check if it's in the changed lines + if (failure.line !== undefined) { + const isLineChanged = changedLines.has(failure.line); + if (isLineChanged) { + filteredFailures.set(key, failure); + } + return; + } + + // If there's no line number, include the failure if the file has changes + filteredFailures.set(key, failure); + }); - if (success.size > 0) { + const filteredSuppressedFailures = new Map(); + results.suppressedFailures.forEach((failure, key) => { + if (filteredFailures.has(key)) { + return; + } + filteredSuppressedFailures.set(key, failure); + }); + + // Filter success set to only include files that are in the diff + const changedFiles = new Set(diffResult.files.map((file) => file.filePath)); + const filteredSuccesses = new Set(); + results.success.forEach((file) => { + if (!changedFiles.has(file)) { + return; + } + filteredSuccesses.add(file); + }); + + if (shouldPrintSuccesses) { + if (filteredSuccesses.size === 0) { + logInfo('No successes remain after filtering by diff.'); + } else { + logInfo(`${filteredSuccesses.size} out of ${results.success.size} successes remain after filtering by diff.`); + } + } + + if (shouldPrintSuppressedErrors) { + if (filteredSuppressedFailures.size === 0) { + logInfo('No suppressed errors remain after filtering by diff.'); + } else { + logInfo(`${filteredSuppressedFailures.size} out of ${results.suppressedFailures.size} successes remain after filtering by diff.`); + } + } + + if (filteredFailures.size === 0) { + logInfo('No failures remain after filtering by diff.'); + } else { + logInfo(`${filteredFailures.size} out of ${results.failures.size} failures remain after filtering by diff.`); + } + + return { + success: filteredSuccesses, + failures: filteredFailures, + suppressedFailures: filteredSuppressedFailures, + }; +} + +function printResults({success, failures, suppressedFailures}: CompilerResults, {shouldPrintSuccesses, shouldPrintSuppressedErrors}: PrintResultsOptions): void { + if (shouldPrintSuccesses && success.size > 0) { log(); logSuccess(`Successfully compiled ${success.size} files with React Compiler:`); + log(); + + success.forEach((successFile) => { + logSuccess(`${successFile}`); + }); + + log(); } - const tab = ' '; + if (shouldPrintSuppressedErrors && suppressedFailures.size > 0) { + // Create a Map of suppressed error type -> Failure[] with distinct errors and a list of failures with that error + const suppressedErrorMap = new Map(); + suppressedFailures.forEach((failure) => { + if (!failure.reason) { + return; + } + + if (!suppressedErrorMap.has(failure.reason)) { + suppressedErrorMap.set(failure.reason, []); + } + + suppressedErrorMap.get(failure.reason)?.push(failure); + }); + + log(); + logWarn(`Suppressed the following errors in these files:`); + log(); + + for (const [error, suppressedErrorFiles] of suppressedErrorMap.entries()) { + logBold(error); + const filesLine = suppressedErrorFiles.map((failure) => getUniqueFileKey(failure)).join(', '); + logNote(`${TAB} - ${filesLine}`); + } + + log(); + } + + const isPassed = failures.size === 0; + if (isPassed) { + logSuccess('All files pass React Compiler compliance check!'); + return; + } const distinctFileNames = new Set(); failures.forEach((failure) => { @@ -280,13 +431,10 @@ function printFailureSummary({success, failures}: CompilerResults): void { logError(`Failed to compile ${distinctFileNames.size} files with React Compiler:`); log(); - // Print unique failures for the files that were checked failures.forEach((failure) => { const location = failure.line && failure.column ? `:${failure.line}:${failure.column}` : ''; - bold(`${failure.file}${location}`); - if (failure.reason) { - note(`${tab}${failure.reason}`); - } + logBold(`${failure.file}${location}`); + logNote(`${TAB}${failure.reason ?? 'No reason provided'}`); }); log(); @@ -295,7 +443,7 @@ function printFailureSummary({success, failures}: CompilerResults): void { function generateReport(results: CompilerResults, outputFileName = DEFAULT_REPORT_FILENAME): void { log('\n'); - info('Creating React Compiler Compliance Check report:'); + logInfo('Creating React Compiler Compliance Check report:'); // Save detailed report const reportFile = join(process.cwd(), outputFileName); @@ -353,42 +501,64 @@ async function main() { ], namedArgs: { remote: { - description: 'Git remote name to use for main branch (default: origin)', + description: 'Git remote name to use for main branch (default: no remote locally and origin in CI)', required: false, supersedes: ['check-changed'], - default: 'origin', + }, + reportFileName: { + description: 'File name to save the report to', + required: false, + default: DEFAULT_REPORT_FILENAME, }, }, flags: { + filterByDiff: { + description: 'Filter the files to check by the diff between the current commit/PR and the main branch', + required: false, + default: false, + }, report: { description: 'Generate a report of the results', required: false, default: false, }, + printSuccesses: { + description: 'Print the successes', + required: false, + default: false, + }, + printSuppressedErrors: { + description: 'Print suppressed errors', + required: false, + default: false, + }, }, }); const {command, file} = cli.positionalArgs; - const {remote} = cli.namedArgs; - const {report: shouldGenerateReport} = cli.flags; + const {remote, reportFileName} = cli.namedArgs; + const {report: shouldGenerateReport, filterByDiff: shouldFilterByDiff, printSuccesses: shouldPrintSuccesses, printSuppressedErrors: shouldPrintSuppressedErrors} = cli.flags; - let isPassed = false; - try { + const commonOptions: BaseCheckOptions = {shouldGenerateReport, reportFileName, shouldFilterByDiff, shouldPrintSuccesses, shouldPrintSuppressedErrors}; + + async function runCommand() { switch (command) { case 'check': - isPassed = Checker.check(file !== '' ? [file] : undefined, shouldGenerateReport); - break; + return Checker.check({files: file ? [file] : undefined, ...commonOptions}); case 'check-changed': - isPassed = await Checker.checkChangedFiles(remote); - break; + return Checker.checkChangedFiles({remote, ...commonOptions}); default: logError(`Unknown command: ${String(command)}`); - isPassed = false; + return Promise.resolve(false); } - } catch (error) { - isPassed = false; - } finally { + } + + try { + const isPassed = await runCommand(); process.exit(isPassed ? 0 : 1); + } catch (error) { + logError('Error running react-compiler-compliance-check:', error); + process.exit(1); } } diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 5d4834efdc04..994ae5aaf9b6 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -4,6 +4,7 @@ "moduleResolution": "node", "target": "ES2023", "types": ["node"], + "strict": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "downlevelIteration": true, diff --git a/scripts/utils/Git.ts b/scripts/utils/Git.ts index 15100b948d2d..67812b206387 100644 --- a/scripts/utils/Git.ts +++ b/scripts/utils/Git.ts @@ -1,16 +1,39 @@ import {context} from '@actions/github'; -import {execSync, exec as execWithCallback} from 'child_process'; +import {exec as execWithCallback, execSync as originalExecSync} from 'child_process'; +import type {ExecSyncOptionsWithStringEncoding, ExecOptions as ExecWithCallbackOptions} from 'child_process'; import {promisify} from 'util'; +import CONST from '@github/libs/CONST'; import GitHubUtils from '@github/libs/GithubUtils'; -import {error as logError} from './Logger'; +import {log, error as logError, warn as logWarn} from './Logger'; -const exec = promisify(execWithCallback); +type ExecOptions = Omit & {cwd?: ExecWithCallbackOptions['cwd']}; +function exec(command: string, options?: ExecOptions) { + const optionsWithEncoding = { + encoding: 'utf8', + cwd: process.cwd(), + ...options, + }; -const IS_CI = process.env.CI === 'true'; + return promisify(execWithCallback)(command, optionsWithEncoding); +} -const GIT_ERRORS = { - FAILED_TO_FETCH_FROM_REMOTE: 'Failed to fetch from remote', -} as const; +type ExecSyncOptions = Omit & { + encoding?: ExecSyncOptionsWithStringEncoding['encoding']; + cwd?: ExecSyncOptionsWithStringEncoding['cwd']; +}; + +function execSync(command: string, options?: ExecSyncOptions) { + const optionsWithEncoding: ExecSyncOptionsWithStringEncoding = { + ...options, + encoding: 'utf8', + cwd: process.cwd(), + }; + + return originalExecSync(command, optionsWithEncoding); +} + +const IS_CI = process.env.CI === 'true'; +const GITHUB_BASE_REF = process.env.GITHUB_BASE_REF as string | undefined; /** * Represents a single changed line in a git diff. @@ -65,8 +88,6 @@ class Git { static isValidRef(ref: string): boolean { try { execSync(`git rev-parse --verify "${ref}^{object}"`, { - encoding: 'utf8', - cwd: process.cwd(), stdio: 'pipe', // Suppress output }); return true; @@ -97,10 +118,7 @@ class Git { } // Execute git diff with unified format - let errors bubble up - const diffOutput = execSync(command, { - encoding: 'utf8', - cwd: process.cwd(), - }); + const diffOutput = execSync(command); return Git.parseDiff(diffOutput); } @@ -282,7 +300,7 @@ class Git { */ static show(ref: string, filePath: string): string { try { - return execSync(`git show ${ref}:${filePath}`, {encoding: 'utf8'}); + return execSync(`git show ${ref}:${filePath}`); } catch (error) { throw new Error(`Failed to get file content from git: ${error instanceof Error ? error.message : String(error)}`); } @@ -301,34 +319,34 @@ class Git { } try { - console.log(`🔄 Fetching missing ref: ${ref}`); - await exec(`git fetch --no-tags --depth=1 ${remote} ${ref}`, { - encoding: 'utf8', - cwd: process.cwd(), - }); + log(`🔄 Fetching missing ref: ${ref}`); + await exec(`git fetch ${remote} ${ref} --no-tags --depth=1 --quiet`); // Verify the ref is now available if (!this.isValidRef(ref)) { - throw new Error(`Reference ${ref} is still not valid after fetching`); + throw new Error(`Reference ${ref} is still not valid after fetching from remote ${remote}`); } } catch (error) { throw new Error(`Failed to fetch git reference ${ref}: ${error instanceof Error ? error.message : String(error)}`); } } - static getMainBaseCommitHash(remote: string): string { - // Fetch the main branch from the specified remote to ensure it's available - try { - execSync(`git fetch ${remote} main --no-tags --depth=1 -q`, {encoding: 'utf8'}); - } catch (error) { - throw new Error(GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE); + static async getMainBranchCommitHash(remote?: string): Promise { + const baseRefName = GITHUB_BASE_REF ?? CONST.DEFAULT_BASE_REF; + + // Fetch the main branch from the specified remote (or locally) to ensure it's available + if (IS_CI || remote) { + await exec(`git fetch ${remote ?? 'origin'} ${baseRefName} --no-tags --depth=1`); } // In CI, use a simpler approach - just use the remote main branch directly // This avoids issues with shallow clones and merge-base calculations if (IS_CI) { + const mainBaseRef = remote ? `${remote}/${baseRefName}` : `origin/${baseRefName}`; + try { - const mergeBaseHash = execSync(`git rev-parse ${remote}/main`, {encoding: 'utf8'}).trim(); + const {stdout: revParseOutput} = await exec(`git rev-parse ${mainBaseRef}`); + const mergeBaseHash = revParseOutput.trim(); // Validate the output is a proper SHA hash if (!mergeBaseHash || !/^[a-fA-F0-9]{40}$/.test(mergeBaseHash)) { @@ -337,24 +355,28 @@ class Git { return mergeBaseHash; } catch (error) { - logError(`Failed to get commit hash for ${remote}/main:`, error); - throw new Error(`Could not get commit hash for ${remote}/main`); + logError(`Failed to get commit hash for ${mainBaseRef}:`, error); + throw new Error(`Could not get commit hash for ${mainBaseRef}`); } } + const mainBaseRef = remote ? `${remote}/${baseRefName}` : baseRefName; + // For local development, try to find the actual merge base let mergeBaseHash: string; try { - mergeBaseHash = execSync(`git merge-base ${remote}/main HEAD`, {encoding: 'utf8'}).trim(); - } catch (error) { + const {stdout: mergeBaseOutput} = await exec(`git merge-base ${mainBaseRef} HEAD`); + mergeBaseHash = mergeBaseOutput.trim(); + } catch { + logWarn(`Warning: Could not find merge base between ${mainBaseRef} and HEAD.`); + // If merge-base fails locally, fall back to using the remote main branch try { - mergeBaseHash = execSync(`git rev-parse ${remote}/main`, {encoding: 'utf8'}).trim(); - logError(`Warning: Could not find merge base between ${remote}/main and HEAD. Using ${remote}/main as base.`); + const {stdout: revParseOutput} = await exec(`git rev-parse ${mainBaseRef}`); + mergeBaseHash = revParseOutput.trim(); } catch (fallbackError) { - logError(`Failed to find merge base with ${remote}/main:`, error); - logError(`Fallback also failed:`, fallbackError); - throw new Error(`Could not determine merge base with ${remote}/main`); + logError(`Failed to find merge base with ${mainBaseRef}:`, fallbackError); + throw new Error(`Could not determine merge base with ${mainBaseRef}`); } } @@ -366,11 +388,26 @@ class Git { return mergeBaseHash; } - static async getChangedFiles(remote: string): Promise { + /** + * Check if there are any uncommitted changes (both staged and unstaged). + * + * @returns true if there are uncommitted changes, false otherwise + */ + static async hasUncommittedChanges(): Promise { + try { + const {stdout} = await exec('git status --porcelain'); + const status = stdout.trim(); + return status.length > 0; + } catch (error) { + return false; + } + } + + static async getChangedFileNames(fromRef: string, toRef = 'HEAD'): Promise { if (IS_CI) { const {data: changedFiles} = await GitHubUtils.octokit.pulls.listFiles({ - owner: 'Expensify', - repo: 'App', + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, // eslint-disable-next-line @typescript-eslint/naming-convention pull_number: context.payload.pull_request?.number ?? 0, }); @@ -378,28 +415,12 @@ class Git { return changedFiles.map((file) => file.filename); } - try { - // Get files changed in the current branch/commit - const mainBaseCommitHash = this.getMainBaseCommitHash(remote); - - // Get the diff output and check status - const gitDiffOutput = execSync(`git diff --diff-filter=AMR --name-only ${mainBaseCommitHash} HEAD`, { - encoding: 'utf8', - }); - - const files = gitDiffOutput.trim().split('\n'); - return files; - } catch (error) { - if (error instanceof Error && error.message === GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE) { - throw error; - } - - logError('Could not determine changed files:', error); - throw error; - } + // Get the diff output and check status + const diffResult = this.diff(fromRef, toRef); + const files = diffResult.files.map((file) => file.filePath); + return files; } } export default Git; -export {GIT_ERRORS}; export type {DiffResult, FileDiff, DiffHunk, DiffLine}; diff --git a/scripts/utils/Logger.ts b/scripts/utils/Logger.ts index 4666f776dee4..dc5a366ca565 100644 --- a/scripts/utils/Logger.ts +++ b/scripts/utils/Logger.ts @@ -8,10 +8,10 @@ const COLOR_BOLD = '\x1b[1m'; const EMOJIS = { // One column emojis need to be rendered with an extra space after to align with two column emojis INFO: '▶️ ', + WARN: '⚠️ ', // Two column emojis can be rendered as-is SUCCESS: '✅', - WARN: '⚠️', ERROR: '🔴', }; diff --git a/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx b/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx index ad51e201a581..31d1b7d21817 100644 --- a/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx +++ b/src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx @@ -725,7 +725,7 @@ function BaseSelectionListWithSections({ if (typeof textInputRef === 'function') { textInputRef(element as RNTextInput); } else { - // eslint-disable-next-line no-param-reassign + // eslint-disable-next-line no-param-reassign, react-compiler/react-compiler textInputRef.current = element as RNTextInput; } }} @@ -745,7 +745,7 @@ function BaseSelectionListWithSections({ spellCheck={false} iconLeft={textInputIconLeft} onSubmitEditing={selectFocusedOption} - blurOnSubmit={!!flattenedSections.allOptions.length} + submitBehavior={flattenedSections.allOptions.length ? 'blurAndSubmit' : 'submit'} isLoading={isLoadingNewOptions} testID="selection-list-text-input" shouldInterceptSwipe={shouldTextInputInterceptSwipe}