@hot-updater/apple-helper 1.2.0-rc.27 → 1.2.0-rc.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1622,7 +1622,16 @@ const listAscDevices = async ({ apiKey, fetch = globalThis.fetch }) => {
1622
1622
  return describingAccess(() => readPages(request, listPath()));
1623
1623
  };
1624
1624
  const keyOf = (udid) => (0, _hot_updater_protocol_native_artifact.normalizeIosUdid)(udid) ?? udid.toLowerCase();
1625
- const findDevices = async (request, udids) => new Map((await readPages(request, listPath({ "filter[udid]": udids.join(",") }))).map((device) => [keyOf(device.udid), device]));
1625
+ /**
1626
+ * The account's devices of these UDIDs, by their normalized form. The filter
1627
+ * names each UDID as given and in both cases: App Store Connect keeps a
1628
+ * device's own case, which a registry's lower-case copy may not match.
1629
+ */
1630
+ const findDevices = async (request, udids) => new Map((await readPages(request, listPath({ "filter[udid]": [...new Set(udids.flatMap((udid) => [
1631
+ udid.trim(),
1632
+ udid.trim().toLowerCase(),
1633
+ udid.trim().toUpperCase()
1634
+ ]))].join(",") }))).map((device) => [keyOf(device.udid), device]));
1626
1635
  /**
1627
1636
  * Registers devices with the Apple account, each at most once: a device that
1628
1637
  * is already there succeeds and changes nothing, so running it again is safe,
@@ -1688,6 +1697,38 @@ const addAscDevices = async ({ devices, apiKey, fetch = globalThis.fetch }) => {
1688
1697
  return outcomes;
1689
1698
  });
1690
1699
  };
1700
+ /** The Apple account's device for a UDID, in either case, or null. */
1701
+ const findAscDevice = async ({ udid, apiKey, fetch = globalThis.fetch }) => {
1702
+ const privateKey = await readPrivateKey(apiKey.keyPath);
1703
+ const request = createAppStoreConnectRequest({
1704
+ apiKey,
1705
+ privateKey,
1706
+ fetch
1707
+ });
1708
+ return describingAccess(async () => (await findDevices(request, [udid])).get(keyOf(udid)) ?? null);
1709
+ };
1710
+ /**
1711
+ * Changes a registered device's name or status in the Apple account: the name
1712
+ * App Store Connect shows, or `DISABLED`, which keeps it out of every new
1713
+ * profile of every app on the team. Disabling never returns its slot: the
1714
+ * account's device count resets only with its membership year.
1715
+ */
1716
+ const updateAscDevice = async ({ device, change, apiKey, fetch = globalThis.fetch }) => {
1717
+ const privateKey = await readPrivateKey(apiKey.keyPath);
1718
+ const request = createAppStoreConnectRequest({
1719
+ apiKey,
1720
+ privateKey,
1721
+ fetch
1722
+ });
1723
+ return describingAccess(async () => {
1724
+ const { data } = await retrying(() => request("name" in change ? `Renaming ${device.udid}` : `Disabling ${device.udid}`, "PATCH", `/v1/devices/${encodeURIComponent(device.id)}`, { data: {
1725
+ type: "devices",
1726
+ id: device.id,
1727
+ attributes: change
1728
+ } }));
1729
+ return deviceOf(data);
1730
+ });
1731
+ };
1691
1732
  //#endregion
1692
1733
  //#region src/utils/formatCommand.ts
1693
1734
  /**
@@ -2936,6 +2977,19 @@ const readBuiltApp = async (appPath) => {
2936
2977
  };
2937
2978
  };
2938
2979
  //#endregion
2980
+ //#region src/utils/readIpaSigning.ts
2981
+ /**
2982
+ * How an exported `.ipa` is signed: its distribution, team, the devices its
2983
+ * profiles list, and the bundle IDs they are for. Null for one it can't read.
2984
+ */
2985
+ const readIpaSigning = async (ipaPath) => {
2986
+ try {
2987
+ return await (0, _hot_updater_protocol_native_artifact.readIpaInstallInfo)((0, _hot_updater_protocol_native_artifact.blobSource)(await fs.default.openAsBlob(ipaPath)));
2988
+ } catch {
2989
+ return null;
2990
+ }
2991
+ };
2992
+ //#endregion
2939
2993
  //#region src/sandboxTestFlight.ts
2940
2994
  /**
2941
2995
  * The states of a version Apple hasn't approved, which still takes builds.
@@ -3626,6 +3680,55 @@ const patchSandboxSimulatorApp = async (appPath, schemeConfig) => {
3626
3680
  ]);
3627
3681
  };
3628
3682
  //#endregion
3683
+ //#region src/utils/savedAdHocProfiles.ts
3684
+ /**
3685
+ * Where Xcode and the system keep the provisioning profiles a Mac has saved:
3686
+ * older Xcode in `MobileDevice`, Xcode 16 and later in its `UserData`.
3687
+ */
3688
+ const provisioningProfileDirs = (home = os.default.homedir()) => [path.default.join(home, "Library", "MobileDevice", "Provisioning Profiles"), path.default.join(home, "Library", "Developer", "Xcode", "UserData", "Provisioning Profiles")];
3689
+ const PROFILE_FILE = /\.(?:mobileprovision|provisionprofile)$/u;
3690
+ /**
3691
+ * Deletes the ad hoc profiles Xcode made and saved on this Mac for one app's
3692
+ * bundle IDs in one team, so its next export asks Apple for a new one, which
3693
+ * lists every device the account has enabled now. A profile goes only when all
3694
+ * of these hold: Xcode manages it (`IsXcodeManaged`), it is an ad hoc profile,
3695
+ * its team is `teamId`, and its `application-identifier` is `<teamId>.<one of
3696
+ * bundleIds>`. A manual or development profile, another team's, and another
3697
+ * app's always stay. A file it can't read stays too.
3698
+ */
3699
+ const removeSavedAdHocProfiles = async ({ teamId, bundleIds, dirs = provisioningProfileDirs() }) => {
3700
+ const applicationIds = new Set(bundleIds.map((bundleId) => `${teamId}.${bundleId}`));
3701
+ const removed = [];
3702
+ const failed = [];
3703
+ for (const dir of dirs) {
3704
+ const names = await fs.default.promises.readdir(dir).catch(() => []);
3705
+ for (const name of names) {
3706
+ if (!PROFILE_FILE.test(name)) continue;
3707
+ const file = path.default.join(dir, name);
3708
+ let profile;
3709
+ try {
3710
+ profile = (0, _hot_updater_protocol_native_artifact.readProvisioningProfile)(await fs.default.promises.readFile(file));
3711
+ } catch {
3712
+ continue;
3713
+ }
3714
+ if (!profile.xcodeManaged || profile.distribution !== "ad-hoc" || profile.teamId !== teamId || profile.applicationIdentifier === null || !applicationIds.has(profile.applicationIdentifier)) continue;
3715
+ try {
3716
+ await fs.default.promises.rm(file);
3717
+ removed.push(profile.uuid ?? name);
3718
+ } catch (error) {
3719
+ failed.push({
3720
+ file,
3721
+ reason: error instanceof Error ? error.message : String(error)
3722
+ });
3723
+ }
3724
+ }
3725
+ }
3726
+ return {
3727
+ removed,
3728
+ failed
3729
+ };
3730
+ };
3731
+ //#endregion
3629
3732
  //#region src/buildIos.ts
3630
3733
  /**
3631
3734
  * Builds a simulator `.app` for a `simulator` scheme, and otherwise archives
@@ -3636,7 +3739,7 @@ const patchSandboxSimulatorApp = async (appPath, schemeConfig) => {
3636
3739
  * once the caller has copied it out. A failed build removes it, and every
3637
3740
  * other directory the build used, itself.
3638
3741
  */
3639
- const buildIos = async ({ schemeConfig, minBundleId = (0, _hot_updater_cli_tools.createMinBundleId)(), credentials, sandbox, logHeader = [] }) => {
3742
+ const buildIos = async ({ schemeConfig, minBundleId = (0, _hot_updater_cli_tools.createMinBundleId)(), credentials, sandbox, logHeader = [], expectedDevices }) => {
3640
3743
  await assertXcodebuildExist();
3641
3744
  if (schemeConfig.simulator && schemeConfig.destination.length) {
3642
3745
  _hot_updater_cli_tools.p.log.error("The scheme option 'simulator' is not compatible with the 'destination' option.");
@@ -3651,7 +3754,8 @@ const buildIos = async ({ schemeConfig, minBundleId = (0, _hot_updater_cli_tools
3651
3754
  credentials,
3652
3755
  sandbox,
3653
3756
  buildDirectory,
3654
- logHeader
3757
+ logHeader,
3758
+ expectedDevices
3655
3759
  }),
3656
3760
  dispose: () => removeTmpDir(buildDirectory)
3657
3761
  };
@@ -3660,7 +3764,7 @@ const buildIos = async ({ schemeConfig, minBundleId = (0, _hot_updater_cli_tools
3660
3764
  throw error;
3661
3765
  }
3662
3766
  };
3663
- const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buildDirectory, logHeader }) => {
3767
+ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buildDirectory, logHeader, expectedDevices }) => {
3664
3768
  const iosProjectRoot = path.default.join((0, _hot_updater_cli_tools.getCwd)(), "ios");
3665
3769
  if (schemeConfig.simulator) {
3666
3770
  const appDir = path.default.join(buildDirectory, "app");
@@ -3698,7 +3802,8 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3698
3802
  minBundleId,
3699
3803
  sandbox,
3700
3804
  buildDirectory,
3701
- logHeader
3805
+ logHeader,
3806
+ expectedDevices
3702
3807
  });
3703
3808
  const registeredDevices = await exportsForRegisteredDevices(schemeConfig);
3704
3809
  const ownKeychain = registeredDevices || await exportsForAppStoreConnect(schemeConfig);
@@ -3713,7 +3818,8 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3713
3818
  sandbox,
3714
3819
  buildDirectory,
3715
3820
  logHeader,
3716
- authenticationArgs: signing.authenticationArgs
3821
+ authenticationArgs: signing.authenticationArgs,
3822
+ expectedDevices
3717
3823
  })
3718
3824
  });
3719
3825
  }
@@ -3722,7 +3828,7 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3722
3828
  * Archives a device build and exports its `.ipa`, or returns the
3723
3829
  * `.xcarchive` of a scheme it cannot export.
3724
3830
  */
3725
- const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirectory, logHeader, authenticationArgs }) => {
3831
+ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirectory, logHeader, authenticationArgs, expectedDevices }) => {
3726
3832
  const iosProjectRoot = path.default.join((0, _hot_updater_cli_tools.getCwd)(), "ios");
3727
3833
  const archiveDir = path.default.join(buildDirectory, "archive");
3728
3834
  const exportDir = path.default.join(buildDirectory, "export");
@@ -3761,18 +3867,51 @@ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirec
3761
3867
  logFilePath,
3762
3868
  builtApp: archivedAppPath ? await readBuiltApp(archivedAppPath) : void 0
3763
3869
  };
3764
- await fs.default.promises.mkdir(exportDir, { recursive: true });
3765
- const exportArchive = (exportOptionsPlist) => exportXcodeArchive({
3766
- archivePath,
3767
- exportPath: exportDir,
3768
- authenticationArgs,
3769
- exportExtraParams: schemeConfig.exportExtraParams,
3770
- exportOptionsPlist,
3771
- sourceDir: iosProjectRoot,
3772
- logPrefix: `ios-${schemeConfig.hotUpdaterSchemeName}-build`,
3773
- logFilePath: logFilePath ?? void 0,
3774
- title: schemeConfig.scheme
3775
- });
3870
+ let exportMethod;
3871
+ const runExport = async (exportOptionsPlist) => {
3872
+ exportMethod = await readExportMethod(exportOptionsPlist).catch(() => "") || void 0;
3873
+ await exportXcodeArchive({
3874
+ archivePath,
3875
+ exportPath: exportDir,
3876
+ authenticationArgs,
3877
+ exportExtraParams: schemeConfig.exportExtraParams,
3878
+ exportOptionsPlist,
3879
+ sourceDir: iosProjectRoot,
3880
+ logPrefix: `ios-${schemeConfig.hotUpdaterSchemeName}-build`,
3881
+ logFilePath: logFilePath ?? void 0,
3882
+ title: schemeConfig.scheme
3883
+ });
3884
+ };
3885
+ const exportOnce = async (exportOptionsPlist) => {
3886
+ await fs.default.promises.rm(exportDir, {
3887
+ recursive: true,
3888
+ force: true
3889
+ });
3890
+ await fs.default.promises.mkdir(exportDir, { recursive: true });
3891
+ try {
3892
+ await runExport(exportOptionsPlist);
3893
+ } finally {
3894
+ await keepOnlyIpas(exportDir);
3895
+ }
3896
+ };
3897
+ const exportArchive = async (exportOptionsPlist) => {
3898
+ await exportOnce(exportOptionsPlist);
3899
+ if (!expectedDevices?.length) return;
3900
+ const ipaFile = findIpa(exportDir);
3901
+ if (ipaFile === void 0) return;
3902
+ const signed = await readIpaSigning(path.default.join(exportDir, ipaFile));
3903
+ if (signed === null || signed.teamId === null) return;
3904
+ const missing = expectedDevices.filter((udid) => !signed.devices.includes(udid.toLowerCase()));
3905
+ if (missing.length === 0 || signed.distribution !== "ad-hoc") return;
3906
+ const { removed, failed } = await removeSavedAdHocProfiles({
3907
+ teamId: signed.teamId,
3908
+ bundleIds: signed.profileBundleIds
3909
+ });
3910
+ for (const { file, reason } of failed) _hot_updater_cli_tools.p.log.warn(`Couldn't delete the saved profile ${file}: ${reason}`);
3911
+ if (removed.length === 0) return;
3912
+ _hot_updater_cli_tools.p.log.info(`Exporting again · a saved ad hoc profile lacked ${missing.length} approved ${missing.length === 1 ? "device" : "devices"}`);
3913
+ await exportOnce(exportOptionsPlist);
3914
+ };
3776
3915
  const { exportOptionsPlist } = schemeConfig;
3777
3916
  if (exportOptionsPlist && !schemeConfig.sandbox) await exportArchive(exportOptionsPlist);
3778
3917
  else {
@@ -3783,16 +3922,17 @@ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirec
3783
3922
  await removeTmpDir(exportOptionsDir);
3784
3923
  }
3785
3924
  }
3786
- await keepOnlyIpas(exportDir);
3787
- const ipaFile = fs.default.readdirSync(exportDir).find((file) => file.endsWith(".ipa"));
3925
+ const ipaFile = findIpa(exportDir);
3788
3926
  if (!ipaFile) throw new Error("IPA file not found after export");
3789
3927
  return {
3790
3928
  buildDirectory,
3791
3929
  buildArtifactPath: path.default.join(exportDir, ipaFile),
3792
3930
  logFilePath,
3931
+ ...exportMethod === void 0 ? {} : { exportMethod },
3793
3932
  builtApp: archivedAppPath ? await readBuiltApp(archivedAppPath) : void 0
3794
3933
  };
3795
3934
  };
3935
+ const findIpa = (exportDir) => fs.default.readdirSync(exportDir).find((file) => file.endsWith(".ipa"));
3796
3936
  /**
3797
3937
  * Leaves only the `.ipa` in an export's folder. Xcode writes `Packaging.log`
3798
3938
  * beside it, which holds the API key's bearer token for its 20 minutes, and the
@@ -3972,9 +4112,11 @@ exports.assertTestFlightExportOptions = assertTestFlightExportOptions;
3972
4112
  exports.buildIos = buildIos;
3973
4113
  exports.distributeTestFlightBuild = distributeTestFlightBuild;
3974
4114
  exports.enrichNativeBuildIosScheme = enrichNativeBuildIosScheme;
4115
+ exports.exportsForRegisteredDevices = exportsForRegisteredDevices;
3975
4116
  exports.extractAppBundle = extractAppBundle;
3976
4117
  exports.extractBuiltInBundle = extractBuiltInBundle;
3977
4118
  exports.extractSimulatorApp = extractSimulatorApp;
4119
+ exports.findAscDevice = findAscDevice;
3978
4120
  exports.findInternalBetaGroup = findInternalBetaGroup;
3979
4121
  exports.findTestFlightBuild = findTestFlightBuild;
3980
4122
  exports.installOnSimulator = installOnSimulator;
@@ -3984,8 +4126,11 @@ exports.issueAscApiKey = issueAscApiKey;
3984
4126
  exports.listAscDevices = listAscDevices;
3985
4127
  exports.listSimulators = listSimulators;
3986
4128
  exports.prepareSandboxArchive = prepareSandboxArchive;
4129
+ exports.provisioningProfileDirs = provisioningProfileDirs;
3987
4130
  exports.readIpaHasExportComplianceKey = readIpaHasExportComplianceKey;
3988
4131
  exports.readTestFlightBuildStatus = readTestFlightBuildStatus;
4132
+ exports.removeSavedAdHocProfiles = removeSavedAdHocProfiles;
3989
4133
  exports.resolveTestFlightUploadKey = resolveTestFlightUploadKey;
3990
4134
  exports.selectSimulator = selectSimulator;
4135
+ exports.updateAscDevice = updateAscDevice;
3991
4136
  exports.uploadToTestFlight = uploadToTestFlight;
package/dist/index.d.cts CHANGED
@@ -201,6 +201,28 @@ declare const addAscDevices: ({ devices, apiKey, fetch }: {
201
201
  apiKey: AppStoreConnectApiKey;
202
202
  fetch?: typeof globalThis.fetch;
203
203
  }) => Promise<AscDeviceOutcome[]>;
204
+ /** The Apple account's device for a UDID, in either case, or null. */
205
+ declare const findAscDevice: ({ udid, apiKey, fetch }: {
206
+ udid: string;
207
+ apiKey: AppStoreConnectApiKey;
208
+ fetch?: typeof globalThis.fetch;
209
+ }) => Promise<AscDevice | null>;
210
+ /**
211
+ * Changes a registered device's name or status in the Apple account: the name
212
+ * App Store Connect shows, or `DISABLED`, which keeps it out of every new
213
+ * profile of every app on the team. Disabling never returns its slot: the
214
+ * account's device count resets only with its membership year.
215
+ */
216
+ declare const updateAscDevice: ({ device, change, apiKey, fetch }: {
217
+ device: Pick<AscDevice, "id" | "udid">;
218
+ change: {
219
+ readonly name: string;
220
+ } | {
221
+ readonly status: "DISABLED";
222
+ };
223
+ apiKey: AppStoreConnectApiKey;
224
+ fetch?: typeof globalThis.fetch;
225
+ }) => Promise<AscDevice>;
204
226
  //#endregion
205
227
  //#region src/sandboxTestFlight.d.ts
206
228
  /** What a sandbox build must fit in App Store Connect. */
@@ -372,7 +394,7 @@ declare const readTestFlightBuildStatus: ({ bundleId, shortVersion, bundleVersio
372
394
  * once the caller has copied it out. A failed build removes it, and every
373
395
  * other directory the build used, itself.
374
396
  */
375
- declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logHeader }: {
397
+ declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logHeader, expectedDevices }: {
376
398
  schemeConfig: EnrichedNativeBuildIosScheme;
377
399
  /** The MIN_BUNDLE_ID the build compiles in. */
378
400
  minBundleId?: string;
@@ -385,11 +407,23 @@ declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logH
385
407
  sandbox?: SandboxArchivePlan;
386
408
  /** Lines the build log starts with, such as the native build key. */
387
409
  logHeader?: string[];
410
+ /**
411
+ * The UDIDs an ad hoc export must list, as the device registry expects: when
412
+ * the `.ipa` lacks one, Xcode's saved ad hoc profiles of the app are deleted
413
+ * and it exports once more, so Xcode asks Apple for a profile with every
414
+ * enabled device.
415
+ */
416
+ expectedDevices?: readonly string[];
388
417
  }) => Promise<{
389
418
  buildDirectory: string;
390
419
  buildArtifactPath: string;
391
420
  /** The build log, which an archive's export appends to, or null. */
392
421
  logFilePath: string | null;
422
+ /**
423
+ * The `method` of the export options the `.ipa` was exported with, as
424
+ * they say it; absent for an archive, a simulator app, or none read.
425
+ */
426
+ exportMethod?: string;
393
427
  /** What the built app reports, from its Info.plist. */
394
428
  builtApp?: {
395
429
  appVersion: string | null;
@@ -452,6 +486,37 @@ declare const installPodsIfNeeded: (sourceDir: string) => Promise<PodInstallStep
452
486
  */
453
487
  declare const readIpaHasExportComplianceKey: (ipaPath: string) => Promise<boolean>;
454
488
  //#endregion
489
+ //#region src/utils/savedAdHocProfiles.d.ts
490
+ /**
491
+ * Where Xcode and the system keep the provisioning profiles a Mac has saved:
492
+ * older Xcode in `MobileDevice`, Xcode 16 and later in its `UserData`.
493
+ */
494
+ declare const provisioningProfileDirs: (home?: string) => string[];
495
+ /** What deleting saved profiles came to. */
496
+ interface SavedAdHocProfileRemoval {
497
+ /** The UUIDs, or file names, of the profiles deleted. */
498
+ readonly removed: readonly string[];
499
+ /** Profiles that matched but couldn't be deleted, with why. */
500
+ readonly failed: readonly {
501
+ readonly file: string;
502
+ readonly reason: string;
503
+ }[];
504
+ }
505
+ /**
506
+ * Deletes the ad hoc profiles Xcode made and saved on this Mac for one app's
507
+ * bundle IDs in one team, so its next export asks Apple for a new one, which
508
+ * lists every device the account has enabled now. A profile goes only when all
509
+ * of these hold: Xcode manages it (`IsXcodeManaged`), it is an ad hoc profile,
510
+ * its team is `teamId`, and its `application-identifier` is `<teamId>.<one of
511
+ * bundleIds>`. A manual or development profile, another team's, and another
512
+ * app's always stay. A file it can't read stays too.
513
+ */
514
+ declare const removeSavedAdHocProfiles: ({ teamId, bundleIds, dirs }: {
515
+ readonly teamId: string;
516
+ readonly bundleIds: readonly string[];
517
+ readonly dirs?: readonly string[];
518
+ }) => Promise<SavedAdHocProfileRemoval>;
519
+ //#endregion
455
520
  //#region src/utils/xcodeSigning.d.ts
456
521
  /**
457
522
  * Refuses a sandbox scheme's App Store Connect export that turns internal
@@ -459,6 +524,13 @@ declare const readIpaHasExportComplianceKey: (ipaPath: string) => Promise<boolea
459
524
  * method's `.ipa` never reaches App Store Connect.
460
525
  */
461
526
  declare const assertSandboxExportOptions: (schemeName: string, exportOptionsPlist: string) => Promise<void>;
527
+ /**
528
+ * Whether a device build exports for the devices its profile lists: with
529
+ * `release-testing`, or `ad-hoc`, Xcode's older name for it. On an empty
530
+ * keychain with the API key, Apple's cloud-managed distribution certificate
531
+ * signs it, as it does an App Store Connect export.
532
+ */
533
+ declare const exportsForRegisteredDevices: ({ exportOptionsPlist }: EnrichedNativeBuildIosScheme) => Promise<boolean>;
462
534
  //#endregion
463
535
  //#region src/utils/extractBuiltInBundle.d.ts
464
536
  /**
@@ -487,4 +559,4 @@ declare const archiveAppBundle: ({ appPath, outputPath }: {
487
559
  outputPath: string;
488
560
  }) => Promise<void>;
489
561
  //#endregion
490
- export { ASC_INTEGRATIONS_URL, type AppleDeviceType, type AscApiKeyRole, type AscDevice, type AscDeviceOutcome, type AscTeam, type EnrichedNativeBuildIosScheme, type InternalBetaGroup, type IssueAscApiKey, type IssueAscApiKeyRequest, type IssuedAscApiKey, type SandboxArchivePlan, type Simulator, TestFlightBuildExistsError, type TestFlightBuildState, type TestFlightBuildStatus, type TestFlightGroupOutcome, type UploadToTestFlightResult, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, readIpaHasExportComplianceKey, readTestFlightBuildStatus, resolveTestFlightUploadKey, selectSimulator, uploadToTestFlight };
562
+ export { ASC_INTEGRATIONS_URL, type AppleDeviceType, type AscApiKeyRole, type AscDevice, type AscDeviceOutcome, type AscTeam, type EnrichedNativeBuildIosScheme, type InternalBetaGroup, type IssueAscApiKey, type IssueAscApiKeyRequest, type IssuedAscApiKey, type SandboxArchivePlan, type SavedAdHocProfileRemoval, type Simulator, TestFlightBuildExistsError, type TestFlightBuildState, type TestFlightBuildStatus, type TestFlightGroupOutcome, type UploadToTestFlightResult, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, exportsForRegisteredDevices, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findAscDevice, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, provisioningProfileDirs, readIpaHasExportComplianceKey, readTestFlightBuildStatus, removeSavedAdHocProfiles, resolveTestFlightUploadKey, selectSimulator, updateAscDevice, uploadToTestFlight };
package/dist/index.d.mts CHANGED
@@ -202,6 +202,28 @@ declare const addAscDevices: ({ devices, apiKey, fetch }: {
202
202
  apiKey: AppStoreConnectApiKey;
203
203
  fetch?: typeof globalThis.fetch;
204
204
  }) => Promise<AscDeviceOutcome[]>;
205
+ /** The Apple account's device for a UDID, in either case, or null. */
206
+ declare const findAscDevice: ({ udid, apiKey, fetch }: {
207
+ udid: string;
208
+ apiKey: AppStoreConnectApiKey;
209
+ fetch?: typeof globalThis.fetch;
210
+ }) => Promise<AscDevice | null>;
211
+ /**
212
+ * Changes a registered device's name or status in the Apple account: the name
213
+ * App Store Connect shows, or `DISABLED`, which keeps it out of every new
214
+ * profile of every app on the team. Disabling never returns its slot: the
215
+ * account's device count resets only with its membership year.
216
+ */
217
+ declare const updateAscDevice: ({ device, change, apiKey, fetch }: {
218
+ device: Pick<AscDevice, "id" | "udid">;
219
+ change: {
220
+ readonly name: string;
221
+ } | {
222
+ readonly status: "DISABLED";
223
+ };
224
+ apiKey: AppStoreConnectApiKey;
225
+ fetch?: typeof globalThis.fetch;
226
+ }) => Promise<AscDevice>;
205
227
  //#endregion
206
228
  //#region src/sandboxTestFlight.d.ts
207
229
  /** What a sandbox build must fit in App Store Connect. */
@@ -373,7 +395,7 @@ declare const readTestFlightBuildStatus: ({ bundleId, shortVersion, bundleVersio
373
395
  * once the caller has copied it out. A failed build removes it, and every
374
396
  * other directory the build used, itself.
375
397
  */
376
- declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logHeader }: {
398
+ declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logHeader, expectedDevices }: {
377
399
  schemeConfig: EnrichedNativeBuildIosScheme;
378
400
  /** The MIN_BUNDLE_ID the build compiles in. */
379
401
  minBundleId?: string;
@@ -386,11 +408,23 @@ declare const buildIos: ({ schemeConfig, minBundleId, credentials, sandbox, logH
386
408
  sandbox?: SandboxArchivePlan;
387
409
  /** Lines the build log starts with, such as the native build key. */
388
410
  logHeader?: string[];
411
+ /**
412
+ * The UDIDs an ad hoc export must list, as the device registry expects: when
413
+ * the `.ipa` lacks one, Xcode's saved ad hoc profiles of the app are deleted
414
+ * and it exports once more, so Xcode asks Apple for a profile with every
415
+ * enabled device.
416
+ */
417
+ expectedDevices?: readonly string[];
389
418
  }) => Promise<{
390
419
  buildDirectory: string;
391
420
  buildArtifactPath: string;
392
421
  /** The build log, which an archive's export appends to, or null. */
393
422
  logFilePath: string | null;
423
+ /**
424
+ * The `method` of the export options the `.ipa` was exported with, as
425
+ * they say it; absent for an archive, a simulator app, or none read.
426
+ */
427
+ exportMethod?: string;
394
428
  /** What the built app reports, from its Info.plist. */
395
429
  builtApp?: {
396
430
  appVersion: string | null;
@@ -453,6 +487,37 @@ declare const installPodsIfNeeded: (sourceDir: string) => Promise<PodInstallStep
453
487
  */
454
488
  declare const readIpaHasExportComplianceKey: (ipaPath: string) => Promise<boolean>;
455
489
  //#endregion
490
+ //#region src/utils/savedAdHocProfiles.d.ts
491
+ /**
492
+ * Where Xcode and the system keep the provisioning profiles a Mac has saved:
493
+ * older Xcode in `MobileDevice`, Xcode 16 and later in its `UserData`.
494
+ */
495
+ declare const provisioningProfileDirs: (home?: string) => string[];
496
+ /** What deleting saved profiles came to. */
497
+ interface SavedAdHocProfileRemoval {
498
+ /** The UUIDs, or file names, of the profiles deleted. */
499
+ readonly removed: readonly string[];
500
+ /** Profiles that matched but couldn't be deleted, with why. */
501
+ readonly failed: readonly {
502
+ readonly file: string;
503
+ readonly reason: string;
504
+ }[];
505
+ }
506
+ /**
507
+ * Deletes the ad hoc profiles Xcode made and saved on this Mac for one app's
508
+ * bundle IDs in one team, so its next export asks Apple for a new one, which
509
+ * lists every device the account has enabled now. A profile goes only when all
510
+ * of these hold: Xcode manages it (`IsXcodeManaged`), it is an ad hoc profile,
511
+ * its team is `teamId`, and its `application-identifier` is `<teamId>.<one of
512
+ * bundleIds>`. A manual or development profile, another team's, and another
513
+ * app's always stay. A file it can't read stays too.
514
+ */
515
+ declare const removeSavedAdHocProfiles: ({ teamId, bundleIds, dirs }: {
516
+ readonly teamId: string;
517
+ readonly bundleIds: readonly string[];
518
+ readonly dirs?: readonly string[];
519
+ }) => Promise<SavedAdHocProfileRemoval>;
520
+ //#endregion
456
521
  //#region src/utils/xcodeSigning.d.ts
457
522
  /**
458
523
  * Refuses a sandbox scheme's App Store Connect export that turns internal
@@ -460,6 +525,13 @@ declare const readIpaHasExportComplianceKey: (ipaPath: string) => Promise<boolea
460
525
  * method's `.ipa` never reaches App Store Connect.
461
526
  */
462
527
  declare const assertSandboxExportOptions: (schemeName: string, exportOptionsPlist: string) => Promise<void>;
528
+ /**
529
+ * Whether a device build exports for the devices its profile lists: with
530
+ * `release-testing`, or `ad-hoc`, Xcode's older name for it. On an empty
531
+ * keychain with the API key, Apple's cloud-managed distribution certificate
532
+ * signs it, as it does an App Store Connect export.
533
+ */
534
+ declare const exportsForRegisteredDevices: ({ exportOptionsPlist }: EnrichedNativeBuildIosScheme) => Promise<boolean>;
463
535
  //#endregion
464
536
  //#region src/utils/extractBuiltInBundle.d.ts
465
537
  /**
@@ -488,4 +560,4 @@ declare const archiveAppBundle: ({ appPath, outputPath }: {
488
560
  outputPath: string;
489
561
  }) => Promise<void>;
490
562
  //#endregion
491
- export { ASC_INTEGRATIONS_URL, type AppleDeviceType, type AscApiKeyRole, type AscDevice, type AscDeviceOutcome, type AscTeam, type EnrichedNativeBuildIosScheme, type InternalBetaGroup, type IssueAscApiKey, type IssueAscApiKeyRequest, type IssuedAscApiKey, type SandboxArchivePlan, type Simulator, TestFlightBuildExistsError, type TestFlightBuildState, type TestFlightBuildStatus, type TestFlightGroupOutcome, type UploadToTestFlightResult, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, readIpaHasExportComplianceKey, readTestFlightBuildStatus, resolveTestFlightUploadKey, selectSimulator, uploadToTestFlight };
563
+ export { ASC_INTEGRATIONS_URL, type AppleDeviceType, type AscApiKeyRole, type AscDevice, type AscDeviceOutcome, type AscTeam, type EnrichedNativeBuildIosScheme, type InternalBetaGroup, type IssueAscApiKey, type IssueAscApiKeyRequest, type IssuedAscApiKey, type SandboxArchivePlan, type SavedAdHocProfileRemoval, type Simulator, TestFlightBuildExistsError, type TestFlightBuildState, type TestFlightBuildStatus, type TestFlightGroupOutcome, type UploadToTestFlightResult, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, exportsForRegisteredDevices, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findAscDevice, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, provisioningProfileDirs, readIpaHasExportComplianceKey, readTestFlightBuildStatus, removeSavedAdHocProfiles, resolveTestFlightUploadKey, selectSimulator, updateAscDevice, uploadToTestFlight };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import crypto from "node:crypto";
2
2
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
3
3
  import { BuildFailedError, BuildLogger, colors, createCredentialResolver, createMinBundleId, getCwd, getReactNativeMetadatas, isCI, p, parseSecretReference, registerSecretValue } from "@hot-updater/cli-tools";
4
- import { SANDBOX_INFO_PLIST_KEY, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, SANDBOX_URL_TYPE_NAME, isRecordedUrlSchemeSyntax, isSandboxUrlScheme, normalizeIosUdid, recordedSandboxUrlScheme, sandboxChannelOf, sandboxUrlSchemeOf } from "@hot-updater/protocol/native-artifact";
4
+ import { SANDBOX_INFO_PLIST_KEY, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, SANDBOX_URL_TYPE_NAME, blobSource, isRecordedUrlSchemeSyntax, isSandboxUrlScheme, normalizeIosUdid, readIpaInstallInfo, readProvisioningProfile, recordedSandboxUrlScheme, sandboxChannelOf, sandboxUrlSchemeOf } from "@hot-updater/protocol/native-artifact";
5
5
  import crypto$1 from "crypto";
6
6
  import fs from "fs";
7
7
  import path from "path";
@@ -1594,7 +1594,16 @@ const listAscDevices = async ({ apiKey, fetch = globalThis.fetch }) => {
1594
1594
  return describingAccess(() => readPages(request, listPath()));
1595
1595
  };
1596
1596
  const keyOf = (udid) => normalizeIosUdid(udid) ?? udid.toLowerCase();
1597
- const findDevices = async (request, udids) => new Map((await readPages(request, listPath({ "filter[udid]": udids.join(",") }))).map((device) => [keyOf(device.udid), device]));
1597
+ /**
1598
+ * The account's devices of these UDIDs, by their normalized form. The filter
1599
+ * names each UDID as given and in both cases: App Store Connect keeps a
1600
+ * device's own case, which a registry's lower-case copy may not match.
1601
+ */
1602
+ const findDevices = async (request, udids) => new Map((await readPages(request, listPath({ "filter[udid]": [...new Set(udids.flatMap((udid) => [
1603
+ udid.trim(),
1604
+ udid.trim().toLowerCase(),
1605
+ udid.trim().toUpperCase()
1606
+ ]))].join(",") }))).map((device) => [keyOf(device.udid), device]));
1598
1607
  /**
1599
1608
  * Registers devices with the Apple account, each at most once: a device that
1600
1609
  * is already there succeeds and changes nothing, so running it again is safe,
@@ -1660,6 +1669,38 @@ const addAscDevices = async ({ devices, apiKey, fetch = globalThis.fetch }) => {
1660
1669
  return outcomes;
1661
1670
  });
1662
1671
  };
1672
+ /** The Apple account's device for a UDID, in either case, or null. */
1673
+ const findAscDevice = async ({ udid, apiKey, fetch = globalThis.fetch }) => {
1674
+ const privateKey = await readPrivateKey(apiKey.keyPath);
1675
+ const request = createAppStoreConnectRequest({
1676
+ apiKey,
1677
+ privateKey,
1678
+ fetch
1679
+ });
1680
+ return describingAccess(async () => (await findDevices(request, [udid])).get(keyOf(udid)) ?? null);
1681
+ };
1682
+ /**
1683
+ * Changes a registered device's name or status in the Apple account: the name
1684
+ * App Store Connect shows, or `DISABLED`, which keeps it out of every new
1685
+ * profile of every app on the team. Disabling never returns its slot: the
1686
+ * account's device count resets only with its membership year.
1687
+ */
1688
+ const updateAscDevice = async ({ device, change, apiKey, fetch = globalThis.fetch }) => {
1689
+ const privateKey = await readPrivateKey(apiKey.keyPath);
1690
+ const request = createAppStoreConnectRequest({
1691
+ apiKey,
1692
+ privateKey,
1693
+ fetch
1694
+ });
1695
+ return describingAccess(async () => {
1696
+ const { data } = await retrying(() => request("name" in change ? `Renaming ${device.udid}` : `Disabling ${device.udid}`, "PATCH", `/v1/devices/${encodeURIComponent(device.id)}`, { data: {
1697
+ type: "devices",
1698
+ id: device.id,
1699
+ attributes: change
1700
+ } }));
1701
+ return deviceOf(data);
1702
+ });
1703
+ };
1663
1704
  //#endregion
1664
1705
  //#region src/utils/formatCommand.ts
1665
1706
  /**
@@ -2908,6 +2949,19 @@ const readBuiltApp = async (appPath) => {
2908
2949
  };
2909
2950
  };
2910
2951
  //#endregion
2952
+ //#region src/utils/readIpaSigning.ts
2953
+ /**
2954
+ * How an exported `.ipa` is signed: its distribution, team, the devices its
2955
+ * profiles list, and the bundle IDs they are for. Null for one it can't read.
2956
+ */
2957
+ const readIpaSigning = async (ipaPath) => {
2958
+ try {
2959
+ return await readIpaInstallInfo(blobSource(await fs.openAsBlob(ipaPath)));
2960
+ } catch {
2961
+ return null;
2962
+ }
2963
+ };
2964
+ //#endregion
2911
2965
  //#region src/sandboxTestFlight.ts
2912
2966
  /**
2913
2967
  * The states of a version Apple hasn't approved, which still takes builds.
@@ -3598,6 +3652,55 @@ const patchSandboxSimulatorApp = async (appPath, schemeConfig) => {
3598
3652
  ]);
3599
3653
  };
3600
3654
  //#endregion
3655
+ //#region src/utils/savedAdHocProfiles.ts
3656
+ /**
3657
+ * Where Xcode and the system keep the provisioning profiles a Mac has saved:
3658
+ * older Xcode in `MobileDevice`, Xcode 16 and later in its `UserData`.
3659
+ */
3660
+ const provisioningProfileDirs = (home = os.homedir()) => [path.join(home, "Library", "MobileDevice", "Provisioning Profiles"), path.join(home, "Library", "Developer", "Xcode", "UserData", "Provisioning Profiles")];
3661
+ const PROFILE_FILE = /\.(?:mobileprovision|provisionprofile)$/u;
3662
+ /**
3663
+ * Deletes the ad hoc profiles Xcode made and saved on this Mac for one app's
3664
+ * bundle IDs in one team, so its next export asks Apple for a new one, which
3665
+ * lists every device the account has enabled now. A profile goes only when all
3666
+ * of these hold: Xcode manages it (`IsXcodeManaged`), it is an ad hoc profile,
3667
+ * its team is `teamId`, and its `application-identifier` is `<teamId>.<one of
3668
+ * bundleIds>`. A manual or development profile, another team's, and another
3669
+ * app's always stay. A file it can't read stays too.
3670
+ */
3671
+ const removeSavedAdHocProfiles = async ({ teamId, bundleIds, dirs = provisioningProfileDirs() }) => {
3672
+ const applicationIds = new Set(bundleIds.map((bundleId) => `${teamId}.${bundleId}`));
3673
+ const removed = [];
3674
+ const failed = [];
3675
+ for (const dir of dirs) {
3676
+ const names = await fs.promises.readdir(dir).catch(() => []);
3677
+ for (const name of names) {
3678
+ if (!PROFILE_FILE.test(name)) continue;
3679
+ const file = path.join(dir, name);
3680
+ let profile;
3681
+ try {
3682
+ profile = readProvisioningProfile(await fs.promises.readFile(file));
3683
+ } catch {
3684
+ continue;
3685
+ }
3686
+ if (!profile.xcodeManaged || profile.distribution !== "ad-hoc" || profile.teamId !== teamId || profile.applicationIdentifier === null || !applicationIds.has(profile.applicationIdentifier)) continue;
3687
+ try {
3688
+ await fs.promises.rm(file);
3689
+ removed.push(profile.uuid ?? name);
3690
+ } catch (error) {
3691
+ failed.push({
3692
+ file,
3693
+ reason: error instanceof Error ? error.message : String(error)
3694
+ });
3695
+ }
3696
+ }
3697
+ }
3698
+ return {
3699
+ removed,
3700
+ failed
3701
+ };
3702
+ };
3703
+ //#endregion
3601
3704
  //#region src/buildIos.ts
3602
3705
  /**
3603
3706
  * Builds a simulator `.app` for a `simulator` scheme, and otherwise archives
@@ -3608,7 +3711,7 @@ const patchSandboxSimulatorApp = async (appPath, schemeConfig) => {
3608
3711
  * once the caller has copied it out. A failed build removes it, and every
3609
3712
  * other directory the build used, itself.
3610
3713
  */
3611
- const buildIos = async ({ schemeConfig, minBundleId = createMinBundleId(), credentials, sandbox, logHeader = [] }) => {
3714
+ const buildIos = async ({ schemeConfig, minBundleId = createMinBundleId(), credentials, sandbox, logHeader = [], expectedDevices }) => {
3612
3715
  await assertXcodebuildExist();
3613
3716
  if (schemeConfig.simulator && schemeConfig.destination.length) {
3614
3717
  p.log.error("The scheme option 'simulator' is not compatible with the 'destination' option.");
@@ -3623,7 +3726,8 @@ const buildIos = async ({ schemeConfig, minBundleId = createMinBundleId(), crede
3623
3726
  credentials,
3624
3727
  sandbox,
3625
3728
  buildDirectory,
3626
- logHeader
3729
+ logHeader,
3730
+ expectedDevices
3627
3731
  }),
3628
3732
  dispose: () => removeTmpDir(buildDirectory)
3629
3733
  };
@@ -3632,7 +3736,7 @@ const buildIos = async ({ schemeConfig, minBundleId = createMinBundleId(), crede
3632
3736
  throw error;
3633
3737
  }
3634
3738
  };
3635
- const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buildDirectory, logHeader }) => {
3739
+ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buildDirectory, logHeader, expectedDevices }) => {
3636
3740
  const iosProjectRoot = path.join(getCwd(), "ios");
3637
3741
  if (schemeConfig.simulator) {
3638
3742
  const appDir = path.join(buildDirectory, "app");
@@ -3670,7 +3774,8 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3670
3774
  minBundleId,
3671
3775
  sandbox,
3672
3776
  buildDirectory,
3673
- logHeader
3777
+ logHeader,
3778
+ expectedDevices
3674
3779
  });
3675
3780
  const registeredDevices = await exportsForRegisteredDevices(schemeConfig);
3676
3781
  const ownKeychain = registeredDevices || await exportsForAppStoreConnect(schemeConfig);
@@ -3685,7 +3790,8 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3685
3790
  sandbox,
3686
3791
  buildDirectory,
3687
3792
  logHeader,
3688
- authenticationArgs: signing.authenticationArgs
3793
+ authenticationArgs: signing.authenticationArgs,
3794
+ expectedDevices
3689
3795
  })
3690
3796
  });
3691
3797
  }
@@ -3694,7 +3800,7 @@ const buildInto = async ({ schemeConfig, minBundleId, credentials, sandbox, buil
3694
3800
  * Archives a device build and exports its `.ipa`, or returns the
3695
3801
  * `.xcarchive` of a scheme it cannot export.
3696
3802
  */
3697
- const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirectory, logHeader, authenticationArgs }) => {
3803
+ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirectory, logHeader, authenticationArgs, expectedDevices }) => {
3698
3804
  const iosProjectRoot = path.join(getCwd(), "ios");
3699
3805
  const archiveDir = path.join(buildDirectory, "archive");
3700
3806
  const exportDir = path.join(buildDirectory, "export");
@@ -3733,18 +3839,51 @@ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirec
3733
3839
  logFilePath,
3734
3840
  builtApp: archivedAppPath ? await readBuiltApp(archivedAppPath) : void 0
3735
3841
  };
3736
- await fs.promises.mkdir(exportDir, { recursive: true });
3737
- const exportArchive = (exportOptionsPlist) => exportXcodeArchive({
3738
- archivePath,
3739
- exportPath: exportDir,
3740
- authenticationArgs,
3741
- exportExtraParams: schemeConfig.exportExtraParams,
3742
- exportOptionsPlist,
3743
- sourceDir: iosProjectRoot,
3744
- logPrefix: `ios-${schemeConfig.hotUpdaterSchemeName}-build`,
3745
- logFilePath: logFilePath ?? void 0,
3746
- title: schemeConfig.scheme
3747
- });
3842
+ let exportMethod;
3843
+ const runExport = async (exportOptionsPlist) => {
3844
+ exportMethod = await readExportMethod(exportOptionsPlist).catch(() => "") || void 0;
3845
+ await exportXcodeArchive({
3846
+ archivePath,
3847
+ exportPath: exportDir,
3848
+ authenticationArgs,
3849
+ exportExtraParams: schemeConfig.exportExtraParams,
3850
+ exportOptionsPlist,
3851
+ sourceDir: iosProjectRoot,
3852
+ logPrefix: `ios-${schemeConfig.hotUpdaterSchemeName}-build`,
3853
+ logFilePath: logFilePath ?? void 0,
3854
+ title: schemeConfig.scheme
3855
+ });
3856
+ };
3857
+ const exportOnce = async (exportOptionsPlist) => {
3858
+ await fs.promises.rm(exportDir, {
3859
+ recursive: true,
3860
+ force: true
3861
+ });
3862
+ await fs.promises.mkdir(exportDir, { recursive: true });
3863
+ try {
3864
+ await runExport(exportOptionsPlist);
3865
+ } finally {
3866
+ await keepOnlyIpas(exportDir);
3867
+ }
3868
+ };
3869
+ const exportArchive = async (exportOptionsPlist) => {
3870
+ await exportOnce(exportOptionsPlist);
3871
+ if (!expectedDevices?.length) return;
3872
+ const ipaFile = findIpa(exportDir);
3873
+ if (ipaFile === void 0) return;
3874
+ const signed = await readIpaSigning(path.join(exportDir, ipaFile));
3875
+ if (signed === null || signed.teamId === null) return;
3876
+ const missing = expectedDevices.filter((udid) => !signed.devices.includes(udid.toLowerCase()));
3877
+ if (missing.length === 0 || signed.distribution !== "ad-hoc") return;
3878
+ const { removed, failed } = await removeSavedAdHocProfiles({
3879
+ teamId: signed.teamId,
3880
+ bundleIds: signed.profileBundleIds
3881
+ });
3882
+ for (const { file, reason } of failed) p.log.warn(`Couldn't delete the saved profile ${file}: ${reason}`);
3883
+ if (removed.length === 0) return;
3884
+ p.log.info(`Exporting again · a saved ad hoc profile lacked ${missing.length} approved ${missing.length === 1 ? "device" : "devices"}`);
3885
+ await exportOnce(exportOptionsPlist);
3886
+ };
3748
3887
  const { exportOptionsPlist } = schemeConfig;
3749
3888
  if (exportOptionsPlist && !schemeConfig.sandbox) await exportArchive(exportOptionsPlist);
3750
3889
  else {
@@ -3755,16 +3894,17 @@ const archiveAndExport = async ({ schemeConfig, minBundleId, sandbox, buildDirec
3755
3894
  await removeTmpDir(exportOptionsDir);
3756
3895
  }
3757
3896
  }
3758
- await keepOnlyIpas(exportDir);
3759
- const ipaFile = fs.readdirSync(exportDir).find((file) => file.endsWith(".ipa"));
3897
+ const ipaFile = findIpa(exportDir);
3760
3898
  if (!ipaFile) throw new Error("IPA file not found after export");
3761
3899
  return {
3762
3900
  buildDirectory,
3763
3901
  buildArtifactPath: path.join(exportDir, ipaFile),
3764
3902
  logFilePath,
3903
+ ...exportMethod === void 0 ? {} : { exportMethod },
3765
3904
  builtApp: archivedAppPath ? await readBuiltApp(archivedAppPath) : void 0
3766
3905
  };
3767
3906
  };
3907
+ const findIpa = (exportDir) => fs.readdirSync(exportDir).find((file) => file.endsWith(".ipa"));
3768
3908
  /**
3769
3909
  * Leaves only the `.ipa` in an export's folder. Xcode writes `Packaging.log`
3770
3910
  * beside it, which holds the API key's bearer token for its 20 minutes, and the
@@ -3932,4 +4072,4 @@ const enrichNativeBuildIosScheme = async ({ scheme, hotUpdaterSchemeName }) => {
3932
4072
  };
3933
4073
  };
3934
4074
  //#endregion
3935
- export { ASC_INTEGRATIONS_URL, TestFlightBuildExistsError, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, readIpaHasExportComplianceKey, readTestFlightBuildStatus, resolveTestFlightUploadKey, selectSimulator, uploadToTestFlight };
4075
+ export { ASC_INTEGRATIONS_URL, TestFlightBuildExistsError, addAscDevices, applyTestFlightGroup, archiveAppBundle, assertBuildIsInternalOnly, assertIpaIsInternalOnly, assertSandboxExportOptions, assertTestFlightExportOptions, buildIos, distributeTestFlightBuild, enrichNativeBuildIosScheme, exportsForRegisteredDevices, extractAppBundle, extractBuiltInBundle, extractSimulatorApp, findAscDevice, findInternalBetaGroup, findTestFlightBuild, installOnSimulator, installPodsIfNeeded, isVersionTrainClosed, issueAscApiKey, listAscDevices, listSimulators, prepareSandboxArchive, provisioningProfileDirs, readIpaHasExportComplianceKey, readTestFlightBuildStatus, removeSavedAdHocProfiles, resolveTestFlightUploadKey, selectSimulator, updateAscDevice, uploadToTestFlight };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/apple-helper",
3
- "version": "1.2.0-rc.27",
3
+ "version": "1.2.0-rc.28",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -29,9 +29,9 @@
29
29
  "dependencies": {
30
30
  "execa": "9.5.2",
31
31
  "fast-xml-parser": "5.8.0",
32
- "@hot-updater/plugin-core": "1.2.0-rc.27",
33
- "@hot-updater/protocol": "1.2.0-rc.27",
34
- "@hot-updater/cli-tools": "1.2.0-rc.27"
32
+ "@hot-updater/plugin-core": "1.2.0-rc.28",
33
+ "@hot-updater/protocol": "1.2.0-rc.28",
34
+ "@hot-updater/cli-tools": "1.2.0-rc.28"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^20"