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
2 changes: 1 addition & 1 deletion packages/@expo/cli/src/events/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class LogStream extends EventEmitter implements NodeJS.WritableStream {

const outputLength = Buffer.byteLength(this.#output);
if (outputLength > written) {
const output = Buffer.from(this.#output).subarray(written).toString();
const output = Buffer.from(this.#output).subarray(written).toString('utf8');
this.#len -= this.#output.length - output.length;
this.#output = output;
} else {
Expand Down
12 changes: 9 additions & 3 deletions packages/@expo/cli/src/export/exportDomComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export function transformDomEntryForMd5Filename({
}): PlatformMetadata['assets'] {
const htmlContent = files.get(htmlOutputName);
assert(htmlContent);
const htmlMd5 = crypto.createHash('md5').update(htmlContent.contents.toString()).digest('hex');
const htmlMd5 = crypto
.createHash('md5')
.update(htmlContent.contents.toString('utf8'))
.digest('hex');
const htmlMd5Filename = `${DOM_COMPONENTS_BUNDLE_DIR}/${htmlMd5}.html`;
files.set(htmlMd5Filename, htmlContent);
files.delete(htmlOutputName);
Expand Down Expand Up @@ -167,7 +170,10 @@ export function transformNativeBundleForMd5Filename({
}) {
const htmlContent = files.get(htmlOutputName);
assert(htmlContent);
const htmlMd5 = crypto.createHash('md5').update(htmlContent.contents.toString()).digest('hex');
const htmlMd5 = crypto
.createHash('md5')
.update(htmlContent.contents.toString('utf8'))
.digest('hex');
const hash = crypto.createHash('md5').update(domComponentReference).digest('hex');
for (const artifact of nativeBundle.artifacts) {
if (artifact.type !== 'js') {
Expand All @@ -188,7 +194,7 @@ export function transformNativeBundleForMd5Filename({
const search = `${hash}.html`;
const replace = `${htmlMd5}.html`;
assert(search.length === replace.length);
assetEntity.contents = assetEntity.contents.toString().replaceAll(search, replace);
assetEntity.contents = assetEntity.contents.toString('utf8').replaceAll(search, replace);
}
}
}
Expand Down
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'));
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
2 changes: 1 addition & 1 deletion packages/@expo/cli/src/utils/plist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function parsePlistAsync(plistPath: string) {

export function parsePlistBuffer(contents: Buffer) {
if (contents[0] === CHAR_CHEVRON_OPEN) {
const info = plist.parse(contents.toString());
const info = plist.parse(contents.toString('utf8'));
if (Array.isArray(info)) return info[0];
return info;
} else if (contents[0] === CHAR_B_LOWER) {
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 @@ -58,7 +58,7 @@ describe('e2e: Android locales', () => {
},
};
const mockJSONFile = {
readAsync: (path) => JSON.parse(vol.readFileSync(path).toString()),
readAsync: (path) => JSON.parse(vol.readFileSync(path, 'utf8') as string),
};
jest.mock('../../utils/XML', () => mockXML);
jest.mock('@expo/json-file', () => mockJSONFile);
Expand All @@ -84,22 +84,25 @@ describe('e2e: Android locales', () => {
{ projectRoot }
);

expect(vol.readFileSync('/app/android/app/src/main/res/values-b+es/strings.xml').toString())
.toMatchInlineSnapshot(`
expect(
vol.readFileSync('/app/android/app/src/main/res/values-b+es/strings.xml', 'utf8') as string
).toMatchInlineSnapshot(`
"<resources>
<string name="CFBundleDisplayName">"spanish-name"</string>
</resources>"
`);
// backwards compatibility
expect(vol.readFileSync('/app/android/app/src/main/res/values-b+en/strings.xml').toString())
.toMatchInlineSnapshot(`
expect(
vol.readFileSync('/app/android/app/src/main/res/values-b+en/strings.xml', 'utf8') as string
).toMatchInlineSnapshot(`
"<resources>
<string name="CFBundleDisplayName">"us-name"</string>
<string name="app_name">"us-name"</string>
</resources>"
`);
expect(vol.readFileSync('/app/android/app/src/main/res/values-b+en+US/strings.xml').toString())
.toMatchInlineSnapshot(`
expect(
vol.readFileSync('/app/android/app/src/main/res/values-b+en+US/strings.xml', 'utf8') as string
).toMatchInlineSnapshot(`
"<resources>
<string name="app_name">"us-name"</string>
</resources>"
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')).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')).toMatch('package xyz.bront.app');
expect(fs.readFileSync(nestedClassPath, 'utf8')).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')).toMatch('package = "xyz.bront.app"');
expect(fs.readFileSync(buckPath, 'utf8')).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')).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');
contents = await setSplashScreenLegacyMainActivity(
exp,
{ backgroundColor: '#000020', resizeMode: 'native' },
Expand Down
4 changes: 2 additions & 2 deletions packages/expo-brownfield/plugin/src/common/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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))) {
Expand Down Expand Up @@ -55,7 +55,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
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class CustomReactPackage : TurboReactPackage() {
}`,
},
])('should handle $description', ({ content }) => {
expect(matchNativePackageClassName(path, Buffer.from(content))).toBe('CustomReactPackage');
expect(matchNativePackageClassName(path, content)).toBe('CustomReactPackage');
});

// these are not as exhaustive as they could be, but cover main cases
Expand All @@ -462,7 +462,7 @@ public class CustomReactPackage extends SomeOtherPackage {
content: '',
},
])('should return null for $description', ({ content }) => {
expect(matchNativePackageClassName(path, Buffer.from(content))).toBeNull();
expect(matchNativePackageClassName(path, content)).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function parseNativePackageClassNameAsync(
for await (const entry of scanFilesRecursively(androidDir, undefined, true)) {
if (entry.name.endsWith('Package.java') || entry.name.endsWith('Package.kt')) {
try {
const contents = await fs.readFile(entry.path);
const contents = await fs.readFile(entry.path, 'utf8');
const matched = matchNativePackageClassName(entry.path, contents);
if (matched) {
return matched;
Expand All @@ -162,7 +162,7 @@ export async function parseNativePackageClassNameAsync(
// Search all **/*.{java,kt} files
for await (const entry of scanFilesRecursively(androidDir, undefined, true)) {
if (entry.name.endsWith('.java') || entry.name.endsWith('.kt')) {
const contents = await fs.readFile(entry.path);
const contents = await fs.readFile(entry.path, 'utf8');
const matched = matchNativePackageClassName(entry.path, contents);
if (matched) {
return matched;
Expand All @@ -174,15 +174,15 @@ export async function parseNativePackageClassNameAsync(

let lazyReactPackageRegex: RegExp | null = null;
let lazyTurboReactPackageRegex: RegExp | null = null;
export function matchNativePackageClassName(_filePath: string, contents: Buffer): string | null {
const fileContents = contents.toString();
export function matchNativePackageClassName(_filePath: string, contents: string): string | null {


// [0] Match ReactPackage
if (!lazyReactPackageRegex) {
lazyReactPackageRegex =
/class\s+(\w+[^(\s]*)[\s\w():]*(\s+implements\s+|:)[\s\w():,]*[^{]*ReactPackage/;
}
const matchReactPackage = fileContents.match(lazyReactPackageRegex);
const matchReactPackage = contents.match(lazyReactPackageRegex);
if (matchReactPackage) {
return matchReactPackage[1];
}
Expand All @@ -192,7 +192,7 @@ export function matchNativePackageClassName(_filePath: string, contents: Buffer)
lazyTurboReactPackageRegex =
/class\s+(\w+[^(\s]*)[\s\w():]*(\s+extends\s+|:)[\s\w():,]*[^{]*(Base|Turbo)ReactPackage/;
}
const matchTurboReactPackage = fileContents.match(lazyTurboReactPackageRegex);
const matchTurboReactPackage = contents.match(lazyTurboReactPackageRegex);
if (matchTurboReactPackage) {
return matchTurboReactPackage[1];
}
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