From 1fcad389674ad83b89d77e6bd427504111d558c2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:14:58 -0700 Subject: [PATCH] Skip updating ICU types if they are unchanged --- ts/scripts/generate-icu-types.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ts/scripts/generate-icu-types.ts b/ts/scripts/generate-icu-types.ts index 9e1c78ef90b7..7dc7a7fb809e 100644 --- a/ts/scripts/generate-icu-types.ts +++ b/ts/scripts/generate-icu-types.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only import fs from 'fs/promises'; +import { createHash } from 'crypto'; import path from 'path'; import ts from 'typescript'; import prettier from 'prettier'; @@ -236,12 +237,27 @@ async function main() { 'build', 'ICUMessageParams.d.ts' ); + + let oldHash: string | undefined; + try { + oldHash = createHash('sha512') + .update(await fs.readFile(destinationPath)) + .digest('hex'); + } catch { + // Ignore errors + } + const prettierConfig = await prettier.resolveConfig(destinationPath); const output = prettier.format(unformattedOutput, { ...prettierConfig, filepath: destinationPath, }); + const newHash = createHash('sha512').update(output).digest('hex'); + if (oldHash === newHash) { + console.log('ICUMessageParams.d.ts is unchanged'); + } + await fs.writeFile(destinationPath, output); } main().catch(error => {