diff --git a/ios/app.mjs b/ios/app.mjs index fda2ee01b..353b21cda 100644 --- a/ios/app.mjs +++ b/ios/app.mjs @@ -295,7 +295,7 @@ export function makeProject(projectRoot, targetPlatform, options, fs = nodefs) { ReactTestAppUITests: project.uitestsBuildSettings, }; - const pbxproj = openXcodeProject(project.xcodeprojPath, fs); + const pbxproj = openXcodeProject(project.xcodeprojPath); for (const target of pbxproj.targets) { const { name: targetName } = target; if (typeof targetName !== "string" || !(targetName in mods)) { @@ -303,8 +303,7 @@ export function makeProject(projectRoot, targetPlatform, options, fs = nodefs) { } const targetBuildSettings = Object.entries(mods[targetName]); - for (const config of target.buildConfigurations) { - const { buildSettings } = config; + for (const { buildSettings } of target.buildConfigurations) { assertObject(buildSettings, "target.buildConfigurations[].buildSettings"); for (const [setting, value] of targetBuildSettings) { diff --git a/ios/utils.mjs b/ios/utils.mjs index 85019e002..b74ee6fe5 100644 --- a/ios/utils.mjs +++ b/ios/utils.mjs @@ -9,6 +9,8 @@ import { fileURLToPath } from "node:url"; * @typedef {import("../scripts/types.ts").JSONValue} JSONValue; */ +const MAX_BUFFER = 16 * 1024 * 1024; // 16 MB because some plists can get big + /** * @param {JSONValue} obj * @returns {obj is JSONObject} @@ -66,10 +68,11 @@ export function jsonFromPlist(filename) { const args = ["-convert", "json", "-o", "-", filename]; const plutil = spawnSync("/usr/bin/plutil", args, { stdio: ["ignore", "pipe", "inherit"], + maxBuffer: MAX_BUFFER, }); if (plutil.status !== 0) { - throw new Error(`Failed to read '${filename}'`); + throw plutil.error ?? new Error(`Failed to read '${filename}'`); } return JSON.parse(plutil.stdout.toString()); @@ -85,10 +88,11 @@ export function plistFromJSON(source, filename) { const plutil = spawnSync("/usr/bin/plutil", args, { stdio: ["pipe", "pipe", "inherit"], input: JSON.stringify(source), + maxBuffer: MAX_BUFFER, }); if (plutil.status !== 0) { - throw new Error(`Failed to generate '${filename}'`); + throw plutil.error ?? new Error(`Failed to generate '${filename}'`); } return plutil.stdout.toString(); @@ -124,3 +128,20 @@ export function resolveResources(appConfig, targetPlatform) { return undefined; } + +/** + * @param {string} destination + * @param {JSONObject} source + * @returns {void} + */ +export function writePlistFromJSON(destination, source) { + const args = ["-convert", "xml1", "-r", "-o", destination, "--", "-"]; + const plutil = spawnSync("/usr/bin/plutil", args, { + stdio: ["pipe", "pipe", "inherit"], + input: JSON.stringify(source), + }); + + if (plutil.status !== 0) { + throw plutil.error ?? new Error(`Failed to write '${destination}'`); + } +} diff --git a/ios/xcode.mjs b/ios/xcode.mjs index 00bbe80b0..35c45cd29 100644 --- a/ios/xcode.mjs +++ b/ios/xcode.mjs @@ -10,7 +10,7 @@ import { isObject, isString, jsonFromPlist, - plistFromJSON, + writePlistFromJSON, } from "./utils.mjs"; /** @@ -227,7 +227,7 @@ export function configureBuildSchemes( /** * @param {string} xcodeproj */ -export function openXcodeProject(xcodeproj, fs = nodefs) { +export function openXcodeProject(xcodeproj) { const projectPath = path.join(xcodeproj, "project.pbxproj"); const pbxproj = jsonFromPlist(projectPath); assertObject(pbxproj.objects, "pbxproj.objects"); @@ -242,7 +242,7 @@ export function openXcodeProject(xcodeproj, fs = nodefs) { return { save() { - fs.writeFileSync(projectPath, plistFromJSON(pbxproj, projectPath)); + writePlistFromJSON(projectPath, pbxproj); }, get targets() { return targets.map((target, index) => {