From f0010ce42ab4c705fbf97f9c559d7e943102c5c3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 08:02:56 +0000 Subject: [PATCH] refactor: optimize readFileSync calls by directly passing encoding Replaced `readFileSync(...).toString()` with `readFileSync(..., 'utf8')` across `expo-brownfield` and `pod-install`. This avoids allocating an intermediate Buffer object and slightly improves performance by returning a string directly. Co-authored-by: vishnu-madhavan-git <237662584+vishnu-madhavan-git@users.noreply.github.com> --- .jules/bolt.md | 3 +++ packages/expo-brownfield/plugin/src/common/filesystem.ts | 9 +++++---- packages/pod-install/src/index.ts | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000000000..5bd728988b100a --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-18 - Avoid recording routine standard work +**Learning:** Only add journal entries for critical learnings like unexpected bottlenecks, failed optimizations, or surprising edge cases. Standard improvements like passing `utf8` directly to `readFileSync` (unless there is a surprise) do not need journaling. +**Action:** Do not journal standard optimizations. 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 = ( diff --git a/packages/pod-install/src/index.ts b/packages/pod-install/src/index.ts index 15184c3f113372..56650359e3df6b 100644 --- a/packages/pod-install/src/index.ts +++ b/packages/pod-install/src/index.ts @@ -41,7 +41,7 @@ async function runAsync(maybeProjectDirectory?: string): Promise { process.exit(1); } - const jsonData = JSON.parse(readFileSync(packageJsonPath).toString()); + const jsonData = JSON.parse(readFileSync(packageJsonPath, 'utf8')); const hasExpoPackage = jsonData.dependencies?.hasOwnProperty('expo'); if (hasExpoPackage) {