From cfb0666bf75d72c083e438440009b3c92a61a653 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 2 May 2026 07:54:00 +0000 Subject: [PATCH] refactor: pass encoding to readFileSync instead of toString Pass the 'utf8' encoding directly to `fs.readFileSync` to avoid intermediate Buffer allocation, reducing memory footprint and GC churn during build/config processes. Co-authored-by: vishnu-madhavan-git <237662584+vishnu-madhavan-git@users.noreply.github.com> --- packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts | 4 ++-- packages/@expo/config-plugins/src/android/Package.ts | 4 ++-- packages/expo-brownfield/plugin/src/common/filesystem.ts | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts b/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts index dab487df678413..8fe635d49973c9 100644 --- a/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts +++ b/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts @@ -35,8 +35,8 @@ export function mergeGitIgnorePaths( return null; } - const targetGitIgnore = fs.readFileSync(targetGitIgnorePath).toString(); - const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath).toString(); + const targetGitIgnore = fs.readFileSync(targetGitIgnorePath, 'utf8'); + const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath, 'utf8'); const merged = mergeGitIgnoreContents(targetGitIgnore, sourceGitIgnore); // Only rewrite the file if it was modified. if (merged.contents) { diff --git a/packages/@expo/config-plugins/src/android/Package.ts b/packages/@expo/config-plugins/src/android/Package.ts index 96222ebf4ba553..052004d5ed719e 100644 --- a/packages/@expo/config-plugins/src/android/Package.ts +++ b/packages/@expo/config-plugins/src/android/Package.ts @@ -125,7 +125,7 @@ export async function renameJniOnDiskForType({ filesToUpdate.forEach((filepath: string) => { try { if (fs.lstatSync(filepath).isFile() && ['.h', '.cpp'].includes(path.extname(filepath))) { - let contents = fs.readFileSync(filepath).toString(); + let contents = fs.readFileSync(filepath, 'utf8'); contents = contents.replace( new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\/'), 'g'), transformJavaClassDescriptor(packageName) @@ -207,7 +207,7 @@ export async function renamePackageOnDiskForType({ filesToUpdate.forEach((filepath: string) => { try { if (fs.lstatSync(filepath).isFile()) { - let contents = fs.readFileSync(filepath).toString(); + let contents = fs.readFileSync(filepath, 'utf8'); if (path.extname(filepath) === '.kt') { contents = replacePackageName(contents, currentPackageName, kotlinSanitizedPackageName); } else { diff --git a/packages/expo-brownfield/plugin/src/common/filesystem.ts b/packages/expo-brownfield/plugin/src/common/filesystem.ts index dfbcceaeb05b2d..a1f9762a7c0c0c 100644 --- a/packages/expo-brownfield/plugin/src/common/filesystem.ts +++ b/packages/expo-brownfield/plugin/src/common/filesystem.ts @@ -26,13 +26,14 @@ const maybeReadOverwrittenTemplate = (template: string, platform?: PlatformStrin try { accessSync(path.join(process.cwd(), '.brownfield-templates')); if (existsSync(path.join(process.cwd(), '.brownfield-templates', template))) { - return readFileSync(path.join(process.cwd(), '.brownfield-templates', template)).toString(); + return readFileSync(path.join(process.cwd(), '.brownfield-templates', template), 'utf8'); } if (existsSync(path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template))) { return readFileSync( - path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template) - ).toString(); + path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template), + 'utf8' + ); } // eslint-disable-next-line no-empty } catch {} @@ -55,7 +56,7 @@ const readTemplate = (template: string, platform?: PlatformString): string => { throw new Error(`Template ${template} doesn't exist at ${templatePath}`); } - return readFileSync(templatePath).toString(); + return readFileSync(templatePath, 'utf8'); }; const createFileFromTemplateInternal = (