Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-11-20 - Optimize readFileSync by removing intermediate buffer allocations
**Learning:** Calling `.toString()` on the buffer returned by `fs.readFileSync` allocates unnecessary memory for the intermediate Buffer object.
**Action:** Always pass the encoding, such as `utf8`, directly to `fs.readFileSync(filepath, "utf8")` when the goal is to read the file contents as a string.
9 changes: 5 additions & 4 deletions packages/expo-brownfield/plugin/src/common/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion packages/pod-install/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function runAsync(maybeProjectDirectory?: string): Promise<void> {
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) {
Expand Down