From 46c6bffea6695bb61be45911a453415ae0c5135f Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 5 Mar 2026 11:59:53 -0800 Subject: [PATCH 1/5] Stop writing codegen files if it just changes new lines --- packages/@react-native-windows/codegen/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/@react-native-windows/codegen/src/index.ts b/packages/@react-native-windows/codegen/src/index.ts index 507732b8eac..8bd2f93c50a 100644 --- a/packages/@react-native-windows/codegen/src/index.ts +++ b/packages/@react-native-windows/codegen/src/index.ts @@ -109,7 +109,8 @@ function checkFilesForChanges( } const currentContents = fs.readFileSync(fileName, 'utf8'); - if (currentContents !== contents) { + // The current file may be saved using crlf, in which case the new lines may differ from the new output + if (currentContents.replaceAll("\r\n", "\n") === contents) { console.log(`- ${fileName} has changed`); hasChanges = true; continue; @@ -146,7 +147,8 @@ function writeMapToFiles(map: Map, outputDir: string) { if (fs.existsSync(fileName)) { const currentContents = fs.readFileSync(fileName, 'utf8'); // Don't update the files if there are no changes as this breaks incremental builds - if (currentContents === contents) { + // The current file may be saved using crlf, in which case the new lines may differ from the new output + if (currentContents.replaceAll("\r\n", "\n") === contents) { continue; } } From e3b54199ab957208908efd17b7322e1f31950e88 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 5 Mar 2026 12:00:08 -0800 Subject: [PATCH 2/5] Change files --- ...ndows-codegen-e4cfdc4a-a4b9-4a36-8902-cc9aa78db21c.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@react-native-windows-codegen-e4cfdc4a-a4b9-4a36-8902-cc9aa78db21c.json diff --git a/change/@react-native-windows-codegen-e4cfdc4a-a4b9-4a36-8902-cc9aa78db21c.json b/change/@react-native-windows-codegen-e4cfdc4a-a4b9-4a36-8902-cc9aa78db21c.json new file mode 100644 index 00000000000..f077c5efef8 --- /dev/null +++ b/change/@react-native-windows-codegen-e4cfdc4a-a4b9-4a36-8902-cc9aa78db21c.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Stop writing codegen files if it just changes new lines", + "packageName": "@react-native-windows/codegen", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} From bb14d01138b40c25c5608aaa29c952698c6336d5 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 5 Mar 2026 12:26:59 -0800 Subject: [PATCH 3/5] format --- packages/@react-native-windows/codegen/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@react-native-windows/codegen/src/index.ts b/packages/@react-native-windows/codegen/src/index.ts index 8bd2f93c50a..d7217285e4b 100644 --- a/packages/@react-native-windows/codegen/src/index.ts +++ b/packages/@react-native-windows/codegen/src/index.ts @@ -110,7 +110,7 @@ function checkFilesForChanges( const currentContents = fs.readFileSync(fileName, 'utf8'); // The current file may be saved using crlf, in which case the new lines may differ from the new output - if (currentContents.replaceAll("\r\n", "\n") === contents) { + if (currentContents.replaceAll('\r\n', '\n') === contents) { console.log(`- ${fileName} has changed`); hasChanges = true; continue; @@ -148,7 +148,7 @@ function writeMapToFiles(map: Map, outputDir: string) { const currentContents = fs.readFileSync(fileName, 'utf8'); // Don't update the files if there are no changes as this breaks incremental builds // The current file may be saved using crlf, in which case the new lines may differ from the new output - if (currentContents.replaceAll("\r\n", "\n") === contents) { + if (currentContents.replaceAll('\r\n', '\n') === contents) { continue; } } From 97ef64e92e3c48529c7bde5f4a663d6962a4755c Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 5 Mar 2026 18:01:32 -0800 Subject: [PATCH 4/5] fix --- .../codegen/src/index.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@react-native-windows/codegen/src/index.ts b/packages/@react-native-windows/codegen/src/index.ts index d7217285e4b..220bd4d4f44 100644 --- a/packages/@react-native-windows/codegen/src/index.ts +++ b/packages/@react-native-windows/codegen/src/index.ts @@ -8,22 +8,22 @@ import path from 'path'; import fs from '@react-native-windows/fs'; import globby from 'globby'; -import type {CppStringTypes} from './generators/GenerateNM2'; -import {createNM2Generator} from './generators/GenerateNM2'; -import {createComponentGenerator} from './generators/GenerateComponentWindows'; +import type { CppStringTypes } from './generators/GenerateNM2'; +import { createNM2Generator } from './generators/GenerateNM2'; +import { createComponentGenerator } from './generators/GenerateComponentWindows'; import { generateTypeScript, setOptionalTurboModule, } from './generators/GenerateTypeScript'; -import type {SchemaType} from '@react-native/codegen/lib/CodegenSchema'; -import type {Parser} from '@react-native/codegen/lib/parsers/parser'; +import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema'; +import type { Parser } from '@react-native/codegen/lib/parsers/parser'; -export type {CppStringTypes} from './generators/GenerateNM2'; +export type { CppStringTypes } from './generators/GenerateNM2'; // Load @react-native/codegen from react-native const rnPath = path.dirname(require.resolve('react-native/package.json')); const rncodegenPath = path.dirname( - require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}), + require.resolve('@react-native/codegen/package.json', { paths: [rnPath] }), ); function getParser(isTypeScript: boolean): Parser { @@ -88,7 +88,7 @@ function checkFilesForChanges( outputDir = path.resolve(outputDir); const globbyDir = outputDir.replace(/\\/g, '/'); const allExistingFiles = globby - .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true}) + .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], { absolute: true }) .map(_ => path.normalize(_)); const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort(); @@ -110,7 +110,7 @@ function checkFilesForChanges( const currentContents = fs.readFileSync(fileName, 'utf8'); // The current file may be saved using crlf, in which case the new lines may differ from the new output - if (currentContents.replaceAll('\r\n', '\n') === contents) { + if (currentContents.replaceAll('\r\n', '\n') !== contents) { console.log(`- ${fileName} has changed`); hasChanges = true; continue; @@ -129,7 +129,7 @@ function writeMapToFiles(map: Map, outputDir: string) { // This ensures that we delete any generated files from modules that have been deleted const allExistingFiles = globby.sync( [`${globbyDir}/**`, `${globbyDir}/**/.*`], - {absolute: true}, + { absolute: true }, ); const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort(); @@ -142,7 +142,7 @@ function writeMapToFiles(map: Map, outputDir: string) { for (const [fileName, contents] of map) { try { - fs.mkdirSync(path.dirname(fileName), {recursive: true}); + fs.mkdirSync(path.dirname(fileName), { recursive: true }); if (fs.existsSync(fileName)) { const currentContents = fs.readFileSync(fileName, 'utf8'); @@ -204,11 +204,11 @@ export function combineSchemas(files: string[]): SchemaType { contents.includes('extends TurboModule')) ) { const schema = parseFile(filename); - merged.modules = {...merged.modules, ...schema.modules}; + merged.modules = { ...merged.modules, ...schema.modules }; } return merged; }, - {modules: {}}, + { modules: {} }, ); } @@ -228,7 +228,7 @@ export function generate( moduleSpecName, schema, }: Options, - {/*generators,*/ test}: Config, + {/*generators,*/ test }: Config, ): boolean { schemaValidator.validate(schema); @@ -412,6 +412,6 @@ export function runCodeGen(options: CodeGenOptions): boolean { moduleSpecName, schema, }, - {generators: [], test: options.test}, + { generators: [], test: options.test }, ); } From 922f9b1fb9dcd6ad413bcb68ecd78f0308ed62ee Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 5 Mar 2026 18:25:49 -0800 Subject: [PATCH 5/5] format --- .../codegen/src/index.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/@react-native-windows/codegen/src/index.ts b/packages/@react-native-windows/codegen/src/index.ts index 220bd4d4f44..79a7968f520 100644 --- a/packages/@react-native-windows/codegen/src/index.ts +++ b/packages/@react-native-windows/codegen/src/index.ts @@ -8,22 +8,22 @@ import path from 'path'; import fs from '@react-native-windows/fs'; import globby from 'globby'; -import type { CppStringTypes } from './generators/GenerateNM2'; -import { createNM2Generator } from './generators/GenerateNM2'; -import { createComponentGenerator } from './generators/GenerateComponentWindows'; +import type {CppStringTypes} from './generators/GenerateNM2'; +import {createNM2Generator} from './generators/GenerateNM2'; +import {createComponentGenerator} from './generators/GenerateComponentWindows'; import { generateTypeScript, setOptionalTurboModule, } from './generators/GenerateTypeScript'; -import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema'; -import type { Parser } from '@react-native/codegen/lib/parsers/parser'; +import type {SchemaType} from '@react-native/codegen/lib/CodegenSchema'; +import type {Parser} from '@react-native/codegen/lib/parsers/parser'; -export type { CppStringTypes } from './generators/GenerateNM2'; +export type {CppStringTypes} from './generators/GenerateNM2'; // Load @react-native/codegen from react-native const rnPath = path.dirname(require.resolve('react-native/package.json')); const rncodegenPath = path.dirname( - require.resolve('@react-native/codegen/package.json', { paths: [rnPath] }), + require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}), ); function getParser(isTypeScript: boolean): Parser { @@ -88,7 +88,7 @@ function checkFilesForChanges( outputDir = path.resolve(outputDir); const globbyDir = outputDir.replace(/\\/g, '/'); const allExistingFiles = globby - .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], { absolute: true }) + .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true}) .map(_ => path.normalize(_)); const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort(); @@ -129,7 +129,7 @@ function writeMapToFiles(map: Map, outputDir: string) { // This ensures that we delete any generated files from modules that have been deleted const allExistingFiles = globby.sync( [`${globbyDir}/**`, `${globbyDir}/**/.*`], - { absolute: true }, + {absolute: true}, ); const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort(); @@ -142,7 +142,7 @@ function writeMapToFiles(map: Map, outputDir: string) { for (const [fileName, contents] of map) { try { - fs.mkdirSync(path.dirname(fileName), { recursive: true }); + fs.mkdirSync(path.dirname(fileName), {recursive: true}); if (fs.existsSync(fileName)) { const currentContents = fs.readFileSync(fileName, 'utf8'); @@ -204,11 +204,11 @@ export function combineSchemas(files: string[]): SchemaType { contents.includes('extends TurboModule')) ) { const schema = parseFile(filename); - merged.modules = { ...merged.modules, ...schema.modules }; + merged.modules = {...merged.modules, ...schema.modules}; } return merged; }, - { modules: {} }, + {modules: {}}, ); } @@ -228,7 +228,7 @@ export function generate( moduleSpecName, schema, }: Options, - {/*generators,*/ test }: Config, + {/*generators,*/ test}: Config, ): boolean { schemaValidator.validate(schema); @@ -412,6 +412,6 @@ export function runCodeGen(options: CodeGenOptions): boolean { moduleSpecName, schema, }, - { generators: [], test: options.test }, + {generators: [], test: options.test}, ); }