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 @@
## 2026-04-24 - Optimization: Direct encoding in fs.readFileSync
**Learning:** In Node.js components of the codebase, avoid unnecessary intermediate memory allocations by passing the encoding string directly to fs.readFileSync (e.g., `fs.readFileSync(file, 'utf8')`) instead of calling `.toString()` on the resulting Buffer. This serves as a valid micro-optimization.
**Action:** Replaced instances of `fs.readFileSync(...).toString()` with `fs.readFileSync(..., 'utf8')` and correctly updated type assertions (`as string`) in TypeScript tests utilizing memfs.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('devices info', () => {
const file = path.join(projectRoot, '.expo', 'devices.json');
expect(fs.existsSync(file)).toBe(true);

const { devices } = JSON.parse(fs.readFileSync(file, 'utf8').toString());
const { devices } = JSON.parse(fs.readFileSync(file, 'utf8') as string);
expect(devices.length).toBe(1);
expect(devices[0].installationId).toBe('test-device-id');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@expo/config-plugins/src/android/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ public class SomeClass {
await renamePackageOnDisk({ android: { package: 'xyz.bront.app' } }, '/myapp');
const mainActivityPath = '/myapp/android/app/src/main/java/xyz/bront/app/MainActivity.java';
expect(fs.existsSync(mainActivityPath)).toBeTruthy();
expect(fs.readFileSync(mainActivityPath).toString()).toMatch('package xyz.bront.app');
expect(fs.readFileSync(mainActivityPath, 'utf8') as string).toMatch('package xyz.bront.app');

const nestedClassPath =
'/myapp/android/app/src/main/java/xyz/bront/app/example/SomeClass.java';
expect(fs.existsSync(nestedClassPath)).toBeTruthy();
expect(fs.readFileSync(nestedClassPath).toString()).toMatch('package xyz.bront.app');
expect(fs.readFileSync(nestedClassPath).toString()).not.toMatch('com.lololol');
expect(fs.readFileSync(nestedClassPath, 'utf8') as string).toMatch('package xyz.bront.app');
expect(fs.readFileSync(nestedClassPath, 'utf8') as string).not.toMatch('com.lololol');

const buckPath = '/myapp/android/app/BUCK';
expect(fs.readFileSync(buckPath).toString()).toMatch('package = "xyz.bront.app"');
expect(fs.readFileSync(buckPath).toString()).not.toMatch('com.lololol');
expect(fs.readFileSync(buckPath, 'utf8') as string).toMatch('package = "xyz.bront.app"');
expect(fs.readFileSync(buckPath, 'utf8') as string).not.toMatch('com.lololol');
});

it('does not clobber itself if package has similar parts', async () => {
await renamePackageOnDisk({ android: { package: 'com.bront' } }, '/myapp');
const mainActivityPath = '/myapp/android/app/src/main/java/com/bront/MainActivity.java';
expect(fs.existsSync(mainActivityPath)).toBeTruthy();
expect(fs.readFileSync(mainActivityPath).toString()).toMatch('package com.bront');
expect(fs.readFileSync(mainActivityPath, 'utf8') as string).toMatch('package com.bront');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe(setSplashScreenLegacyMainActivity, () => {
},
};
const mainActivity = await AndroidConfig.Paths.getMainActivityAsync('/app');
let contents = fs.readFileSync(mainActivity.path).toString();
let contents = fs.readFileSync(mainActivity.path, 'utf8') as string;
contents = await setSplashScreenLegacyMainActivity(
exp,
{ backgroundColor: '#000020', resizeMode: 'native' },
Expand Down