diff --git a/src/cli.ts b/src/cli.ts index bd3d486..9d86040 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -709,21 +709,17 @@ export function resolveOnboardTarget( options: OnboardOptions = {}, cwd: string = process.cwd(), ): OnboardTarget { - try { - return detectOnboardTarget(inputPath, options, cwd); - } catch (error) { - const sourcePath = path.resolve(cwd, inputPath); - const requested = options.platform; - const shouldBuildIos = - existsSync(sourcePath) && - isDirectory(sourcePath) && - hasIosProjectMarker(sourcePath) && - (requested === "ios" || (!requested && !hasAndroidProjectMarker(sourcePath))); - if (shouldBuildIos) { - return buildIosProjectForOnboarding(sourcePath, cwd, options.runCommand ?? runNativeBuildCommand); - } - throw error; + const sourcePath = path.resolve(cwd, inputPath); + const requested = options.platform; + const shouldBuildIos = + existsSync(sourcePath) && + isDirectory(sourcePath) && + hasIosProjectMarker(sourcePath) && + (requested === "ios" || (!requested && !hasAndroidProjectMarker(sourcePath))); + if (shouldBuildIos) { + return buildIosProjectForOnboarding(sourcePath, cwd, options.runCommand ?? runNativeBuildCommand); } + return detectOnboardTarget(inputPath, options, cwd); } export function detectOnboardTarget( diff --git a/test/cli.test.ts b/test/cli.test.ts index 78a6716..b006daf 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -444,6 +444,40 @@ test("onboard builds and stages an iOS project when no built app exists", () => } }); +test("onboard builds an iOS project instead of reusing stale app output", () => { + const dir = mkdtempSync(path.join(tmpdir(), "nativeproof-onboard-ios-stale-")); + try { + const iosRepo = path.join(dir, "ios", "sample-mobile-ios"); + mkdirSync(path.join(iosRepo, "Example.xcodeproj"), { recursive: true }); + mkdirSync(path.join(iosRepo, "build", "Debug-iphonesimulator", "Old.app"), { recursive: true }); + + const runCommand: NativeBuildCommandRunner = (_command, args) => { + if (args.includes("-list")) { + return { + code: 0, + stdout: JSON.stringify({ project: { name: "Example", schemes: ["Example"] } }), + stderr: "", + }; + } + + const derivedDataPath = args[args.indexOf("-derivedDataPath") + 1]; + if (typeof derivedDataPath !== "string") { + throw new Error("expected -derivedDataPath in xcodebuild args"); + } + mkdirSync(path.join(derivedDataPath, "Build", "Products", "Debug-iphonesimulator", "New.app"), { + recursive: true, + }); + return { code: 0, stdout: "", stderr: "" }; + }; + + const result = onboard(dir, "./ios/sample-mobile-ios", { runCommand }); + assert.equal(result.target.appPath, "./build/ios/New.app"); + assert.ok(existsSync(path.join(dir, "build", "ios", "New.app"))); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + test("onboard reports an iOS project build that produces no simulator app", () => { const dir = mkdtempSync(path.join(tmpdir(), "nativeproof-onboard-ios-build-fail-")); try {