Skip to content

Commit cfabb28

Browse files
authored
fix(apple): fix ENOBUFS when reading/writing plists (#2443)
1 parent 6d6b81c commit cfabb28

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

ios/app.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,15 @@ export function makeProject(projectRoot, targetPlatform, options, fs = nodefs) {
295295
ReactTestAppUITests: project.uitestsBuildSettings,
296296
};
297297

298-
const pbxproj = openXcodeProject(project.xcodeprojPath, fs);
298+
const pbxproj = openXcodeProject(project.xcodeprojPath);
299299
for (const target of pbxproj.targets) {
300300
const { name: targetName } = target;
301301
if (typeof targetName !== "string" || !(targetName in mods)) {
302302
continue;
303303
}
304304

305305
const targetBuildSettings = Object.entries(mods[targetName]);
306-
for (const config of target.buildConfigurations) {
307-
const { buildSettings } = config;
306+
for (const { buildSettings } of target.buildConfigurations) {
308307
assertObject(buildSettings, "target.buildConfigurations[].buildSettings");
309308

310309
for (const [setting, value] of targetBuildSettings) {

ios/utils.mjs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { fileURLToPath } from "node:url";
99
* @typedef {import("../scripts/types.ts").JSONValue} JSONValue;
1010
*/
1111

12+
const MAX_BUFFER = 16 * 1024 * 1024; // 16 MB because some plists can get big
13+
1214
/**
1315
* @param {JSONValue} obj
1416
* @returns {obj is JSONObject}
@@ -66,10 +68,11 @@ export function jsonFromPlist(filename) {
6668
const args = ["-convert", "json", "-o", "-", filename];
6769
const plutil = spawnSync("/usr/bin/plutil", args, {
6870
stdio: ["ignore", "pipe", "inherit"],
71+
maxBuffer: MAX_BUFFER,
6972
});
7073

7174
if (plutil.status !== 0) {
72-
throw new Error(`Failed to read '${filename}'`);
75+
throw plutil.error ?? new Error(`Failed to read '${filename}'`);
7376
}
7477

7578
return JSON.parse(plutil.stdout.toString());
@@ -85,10 +88,11 @@ export function plistFromJSON(source, filename) {
8588
const plutil = spawnSync("/usr/bin/plutil", args, {
8689
stdio: ["pipe", "pipe", "inherit"],
8790
input: JSON.stringify(source),
91+
maxBuffer: MAX_BUFFER,
8892
});
8993

9094
if (plutil.status !== 0) {
91-
throw new Error(`Failed to generate '${filename}'`);
95+
throw plutil.error ?? new Error(`Failed to generate '${filename}'`);
9296
}
9397

9498
return plutil.stdout.toString();
@@ -124,3 +128,20 @@ export function resolveResources(appConfig, targetPlatform) {
124128

125129
return undefined;
126130
}
131+
132+
/**
133+
* @param {string} destination
134+
* @param {JSONObject} source
135+
* @returns {void}
136+
*/
137+
export function writePlistFromJSON(destination, source) {
138+
const args = ["-convert", "xml1", "-r", "-o", destination, "--", "-"];
139+
const plutil = spawnSync("/usr/bin/plutil", args, {
140+
stdio: ["pipe", "pipe", "inherit"],
141+
input: JSON.stringify(source),
142+
});
143+
144+
if (plutil.status !== 0) {
145+
throw plutil.error ?? new Error(`Failed to write '${destination}'`);
146+
}
147+
}

ios/xcode.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
isObject,
1111
isString,
1212
jsonFromPlist,
13-
plistFromJSON,
13+
writePlistFromJSON,
1414
} from "./utils.mjs";
1515

1616
/**
@@ -227,7 +227,7 @@ export function configureBuildSchemes(
227227
/**
228228
* @param {string} xcodeproj
229229
*/
230-
export function openXcodeProject(xcodeproj, fs = nodefs) {
230+
export function openXcodeProject(xcodeproj) {
231231
const projectPath = path.join(xcodeproj, "project.pbxproj");
232232
const pbxproj = jsonFromPlist(projectPath);
233233
assertObject(pbxproj.objects, "pbxproj.objects");
@@ -242,7 +242,7 @@ export function openXcodeProject(xcodeproj, fs = nodefs) {
242242

243243
return {
244244
save() {
245-
fs.writeFileSync(projectPath, plistFromJSON(pbxproj, projectPath));
245+
writePlistFromJSON(projectPath, pbxproj);
246246
},
247247
get targets() {
248248
return targets.map((target, index) => {

0 commit comments

Comments
 (0)