@hot-updater/apple-helper 1.2.0-rc.24 → 1.2.0-rc.25
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 +110 -15
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +111 -16
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -2028,8 +2028,8 @@ const PRECOMPILES = /* @__PURE__ */ new Set([
|
|
|
2028
2028
|
const plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
2029
2029
|
/**
|
|
2030
2030
|
* Reads the phase of an `xcodebuild` build, archive, or export from its raw
|
|
2031
|
-
* output: `Compiling React-Core · 412 files`, `Linking
|
|
2032
|
-
* `Signing
|
|
2031
|
+
* output: `Compiling React-Core · 412 files`, `Linking ExampleApp`,
|
|
2032
|
+
* `Signing ExampleApp`, `Bundling JavaScript`, with the target each
|
|
2033
2033
|
* action's line names.
|
|
2034
2034
|
*/
|
|
2035
2035
|
const createXcodebuildPhaseReader = () => {
|
|
@@ -3342,7 +3342,6 @@ const readTestFlightBuildStatus = async ({ bundleId, shortVersion, bundleVersion
|
|
|
3342
3342
|
};
|
|
3343
3343
|
//#endregion
|
|
3344
3344
|
//#region src/utils/sandboxInfoPlist.ts
|
|
3345
|
-
const URL_TYPE_NAME = "hot-updater-sandbox";
|
|
3346
3345
|
const CAMERA_USAGE = "Scans the QR code of a preview to open it in this build.";
|
|
3347
3346
|
const LOCAL_NETWORK_USAGE = "Connects to the dev server you choose on this network.";
|
|
3348
3347
|
const ATS_KEY = "NSAppTransportSecurity";
|
|
@@ -3372,12 +3371,8 @@ const setString = (plist, key, value) => plutil([
|
|
|
3372
3371
|
value,
|
|
3373
3372
|
plist
|
|
3374
3373
|
]);
|
|
3375
|
-
/**
|
|
3376
|
-
const
|
|
3377
|
-
const urlType = JSON.stringify({
|
|
3378
|
-
CFBundleURLName: URL_TYPE_NAME,
|
|
3379
|
-
CFBundleURLSchemes: [urlScheme]
|
|
3380
|
-
});
|
|
3374
|
+
/** The app's own URL types, or null when it has none. */
|
|
3375
|
+
const readUrlTypes = async (plist) => {
|
|
3381
3376
|
const { stdout, exitCode } = await (0, execa.execa)("plutil", [
|
|
3382
3377
|
"-extract",
|
|
3383
3378
|
"CFBundleURLTypes",
|
|
@@ -3386,7 +3381,35 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3386
3381
|
"-",
|
|
3387
3382
|
plist
|
|
3388
3383
|
], { reject: false });
|
|
3389
|
-
|
|
3384
|
+
return exitCode === 0 ? JSON.parse(stdout) : null;
|
|
3385
|
+
};
|
|
3386
|
+
const isSandboxUrlType = (type) => type?.CFBundleURLName === _hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME;
|
|
3387
|
+
/**
|
|
3388
|
+
* Appends a URL type with the sandbox's scheme to the app's own, or, in an
|
|
3389
|
+
* app an earlier patch made a sandbox app, replaces the one that patch added.
|
|
3390
|
+
*/
|
|
3391
|
+
const addUrlScheme = async (plist, urlScheme, existing, patchedBefore) => {
|
|
3392
|
+
const urlType = JSON.stringify({
|
|
3393
|
+
CFBundleURLName: _hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME,
|
|
3394
|
+
CFBundleURLSchemes: [urlScheme]
|
|
3395
|
+
});
|
|
3396
|
+
const patched = patchedBefore ? existing?.findIndex(isSandboxUrlType) ?? -1 : -1;
|
|
3397
|
+
if (patched !== -1) {
|
|
3398
|
+
await plutil([
|
|
3399
|
+
"-remove",
|
|
3400
|
+
`CFBundleURLTypes.${patched}`,
|
|
3401
|
+
plist
|
|
3402
|
+
]);
|
|
3403
|
+
await plutil([
|
|
3404
|
+
"-insert",
|
|
3405
|
+
`CFBundleURLTypes.${patched}`,
|
|
3406
|
+
"-json",
|
|
3407
|
+
urlType,
|
|
3408
|
+
plist
|
|
3409
|
+
]);
|
|
3410
|
+
return;
|
|
3411
|
+
}
|
|
3412
|
+
if (existing === null) {
|
|
3390
3413
|
await plutil([
|
|
3391
3414
|
"-insert",
|
|
3392
3415
|
"CFBundleURLTypes",
|
|
@@ -3396,7 +3419,6 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3396
3419
|
]);
|
|
3397
3420
|
return;
|
|
3398
3421
|
}
|
|
3399
|
-
const existing = JSON.parse(stdout);
|
|
3400
3422
|
await plutil([
|
|
3401
3423
|
"-insert",
|
|
3402
3424
|
`CFBundleURLTypes.${existing.length}`,
|
|
@@ -3405,6 +3427,16 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3405
3427
|
plist
|
|
3406
3428
|
]);
|
|
3407
3429
|
};
|
|
3430
|
+
/** The schemes a URL type lists. */
|
|
3431
|
+
const schemesOf = (type) => {
|
|
3432
|
+
const schemes = type?.CFBundleURLSchemes;
|
|
3433
|
+
return Array.isArray(schemes) ? schemes : [];
|
|
3434
|
+
};
|
|
3435
|
+
/** Whether URL types list `urlScheme`, as iOS compares schemes: ignoring case. */
|
|
3436
|
+
const registersUrlScheme = (urlTypes, urlScheme) => urlTypes.some((type) => {
|
|
3437
|
+
const schemes = type?.CFBundleURLSchemes;
|
|
3438
|
+
return Array.isArray(schemes) && schemes.some((scheme) => typeof scheme === "string" && scheme.toLowerCase() === urlScheme.toLowerCase());
|
|
3439
|
+
});
|
|
3408
3440
|
const hasKey = async (plist, key) => {
|
|
3409
3441
|
const { exitCode } = await (0, execa.execa)("plutil", [
|
|
3410
3442
|
"-extract",
|
|
@@ -3446,13 +3478,21 @@ const addSandboxPermissions = async (plist) => {
|
|
|
3446
3478
|
};
|
|
3447
3479
|
/**
|
|
3448
3480
|
* The app's dedicated URL scheme, default channel, and the sandbox's key. The
|
|
3449
|
-
* URL scheme and App Store Connect's app come
|
|
3450
|
-
* `bundleIdentifier`, while Xcode's build settings decide
|
|
3451
|
-
* app of another ID stops here, before anything is signed
|
|
3481
|
+
* URL scheme, unless the scheme sets one, and App Store Connect's app come
|
|
3482
|
+
* from the scheme's `bundleIdentifier`, while Xcode's build settings decide
|
|
3483
|
+
* the app's ID, so an app of another ID stops here, before anything is signed
|
|
3484
|
+
* or uploaded.
|
|
3452
3485
|
*/
|
|
3453
3486
|
const patchAppInfoPlist = async (plist, scheme) => {
|
|
3454
3487
|
const built = await readValue(plist, "CFBundleIdentifier");
|
|
3455
3488
|
if (built !== scheme.bundleIdentifier) throw refusal(`The sandbox scheme ${scheme.hotUpdaterSchemeName} sets bundleIdentifier ${scheme.bundleIdentifier}, but Xcode built ${built ?? "no bundle ID"}.\nSet bundleIdentifier to the ID its configuration builds.`);
|
|
3489
|
+
const urlScheme = scheme.sandboxUrlScheme ?? (0, _hot_updater_protocol_native_artifact.sandboxUrlSchemeOf)(scheme.bundleIdentifier);
|
|
3490
|
+
const urlTypes = await readUrlTypes(plist);
|
|
3491
|
+
const patchedBefore = await readValue(plist, _hot_updater_protocol_native_artifact.SANDBOX_INFO_PLIST_KEY) === "true";
|
|
3492
|
+
const appUrlTypes = (urlTypes ?? []).filter((type) => !(patchedBefore && isSandboxUrlType(type)));
|
|
3493
|
+
if (appUrlTypes.some(isSandboxUrlType)) throw refusal(`The app has a URL type named ${_hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME}, the name a sandbox build registers its URL scheme under.\nRename the app's URL type.`);
|
|
3494
|
+
if (patchedBefore) await refuseForeignSandboxUrlTypes(plist, urlTypes ?? [], scheme);
|
|
3495
|
+
if (registersUrlScheme(appUrlTypes, urlScheme)) throw refusal(`The sandbox scheme ${scheme.hotUpdaterSchemeName} registers URL scheme ${urlScheme}, which the app registers itself.\nSet sandbox.urlScheme to a scheme the app doesn't register.`);
|
|
3456
3496
|
await setString(plist, "HOT_UPDATER_CHANNEL", (0, _hot_updater_protocol_native_artifact.sandboxChannelOf)(scheme.hotUpdaterSchemeName));
|
|
3457
3497
|
await plutil([
|
|
3458
3498
|
"-replace",
|
|
@@ -3461,9 +3501,64 @@ const patchAppInfoPlist = async (plist, scheme) => {
|
|
|
3461
3501
|
"true",
|
|
3462
3502
|
plist
|
|
3463
3503
|
]);
|
|
3464
|
-
await addUrlScheme(plist,
|
|
3504
|
+
await addUrlScheme(plist, urlScheme, urlTypes, patchedBefore);
|
|
3505
|
+
await setString(plist, _hot_updater_protocol_native_artifact.SANDBOX_URL_SCHEME_INFO_PLIST_KEY, urlScheme);
|
|
3465
3506
|
await addSandboxPermissions(plist);
|
|
3466
3507
|
};
|
|
3508
|
+
/**
|
|
3509
|
+
* A key's value as written, or undefined when the plist has no such key:
|
|
3510
|
+
* strings, numbers and booleans as they are, and any other type as itself
|
|
3511
|
+
* named, which no rule takes. `-extract … json` refuses a lone scalar.
|
|
3512
|
+
*/
|
|
3513
|
+
const readTyped = async (plist, key) => {
|
|
3514
|
+
const type = await (0, execa.execa)("plutil", [
|
|
3515
|
+
"-type",
|
|
3516
|
+
key,
|
|
3517
|
+
plist
|
|
3518
|
+
], { reject: false });
|
|
3519
|
+
if (type.exitCode !== 0) return void 0;
|
|
3520
|
+
const { stdout } = await (0, execa.execa)("plutil", [
|
|
3521
|
+
"-extract",
|
|
3522
|
+
key,
|
|
3523
|
+
"raw",
|
|
3524
|
+
"-o",
|
|
3525
|
+
"-",
|
|
3526
|
+
plist
|
|
3527
|
+
], {
|
|
3528
|
+
reject: false,
|
|
3529
|
+
stripFinalNewline: false
|
|
3530
|
+
});
|
|
3531
|
+
const raw = stdout.endsWith("\n") ? stdout.slice(0, -1) : stdout;
|
|
3532
|
+
switch (type.stdout.trim()) {
|
|
3533
|
+
case "string": return raw;
|
|
3534
|
+
case "integer":
|
|
3535
|
+
case "float": return Number(raw);
|
|
3536
|
+
case "bool": return raw === "true";
|
|
3537
|
+
default: return `<${type.stdout.trim()}>`;
|
|
3538
|
+
}
|
|
3539
|
+
};
|
|
3540
|
+
/**
|
|
3541
|
+
* Refuses, in an app an earlier patch made a sandbox app, what replacing its
|
|
3542
|
+
* URL type of the sandbox's name could break: by `recordedSandboxUrlScheme`'s
|
|
3543
|
+
* rule, the one URL type of the name must hold the one scheme the patch
|
|
3544
|
+
* recorded alone. A prerelease's patch recorded none, and registered one with
|
|
3545
|
+
* the derived scheme's prefix.
|
|
3546
|
+
*/
|
|
3547
|
+
const refuseForeignSandboxUrlTypes = async (plist, urlTypes, scheme) => {
|
|
3548
|
+
const named = urlTypes.filter(isSandboxUrlType);
|
|
3549
|
+
const value = await readTyped(plist, _hot_updater_protocol_native_artifact.SANDBOX_URL_SCHEME_INFO_PLIST_KEY);
|
|
3550
|
+
const recorded = (0, _hot_updater_protocol_native_artifact.recordedSandboxUrlScheme)(value, named);
|
|
3551
|
+
if (typeof recorded === "string") return;
|
|
3552
|
+
const schemes = named.flatMap(schemesOf);
|
|
3553
|
+
if (recorded === void 0) {
|
|
3554
|
+
const only = named.length === 1 && schemes.length === 1 ? schemes[0] : null;
|
|
3555
|
+
if (typeof only === "string" && (0, _hot_updater_protocol_native_artifact.isSandboxUrlScheme)(only)) return;
|
|
3556
|
+
} else if (!(0, _hot_updater_protocol_native_artifact.isRecordedUrlSchemeSyntax)(value)) throw refusal(`The app's Info.plist records sandbox URL scheme ${JSON.stringify(value)} in ${_hot_updater_protocol_native_artifact.SANDBOX_URL_SCHEME_INFO_PLIST_KEY}, which isn't a URL scheme.\nBuild the app again: a new build records none.`);
|
|
3557
|
+
const keep = (0, _hot_updater_protocol_native_artifact.isRecordedUrlSchemeSyntax)(value) ? value : (0, _hot_updater_protocol_native_artifact.sandboxUrlSchemeOf)(scheme.bundleIdentifier);
|
|
3558
|
+
const holds = schemes.map(String).join(", ") || "no scheme";
|
|
3559
|
+
const found = named.length === 1 ? `The app's ${_hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME} URL type holds ${holds}.` : `The app has ${named.length} ${_hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME} URL types${named.length === 0 ? "" : `, holding ${holds}`}.`;
|
|
3560
|
+
throw refusal(`${found}\nKeep exactly one ${_hot_updater_protocol_native_artifact.SANDBOX_URL_TYPE_NAME} URL type, holding only ${keep}, and move the rest to a URL type of the app's own.`);
|
|
3561
|
+
};
|
|
3467
3562
|
/** The Info.plist of each app extension inside an `.app`. */
|
|
3468
3563
|
const extensionInfoPlists = (appPath) => ["PlugIns", "Extensions"].flatMap((directory) => {
|
|
3469
3564
|
const extensions = path.default.join(appPath, directory);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CredentialRequest, CredentialResolver, Credentials } from "@hot-updater/cli-tools";
|
|
1
|
+
import { CredentialRequest, CredentialResolver, Credentials, ResolvedNativeBuildIosScheme } from "@hot-updater/cli-tools";
|
|
2
2
|
import { NativeBuildIosScheme } from "@hot-updater/plugin-core";
|
|
3
3
|
//#region src/ascApiKey.d.ts
|
|
4
4
|
/** Where team API keys are listed and revoked in App Store Connect. */
|
|
@@ -63,11 +63,11 @@ declare const issueAscApiKey: IssueAscApiKey;
|
|
|
63
63
|
/**
|
|
64
64
|
* Validated scheme filled nullish values with default values.
|
|
65
65
|
*/
|
|
66
|
-
type EnrichedNativeBuildIosScheme =
|
|
66
|
+
type EnrichedNativeBuildIosScheme = ResolvedNativeBuildIosScheme & Required<Pick<ResolvedNativeBuildIosScheme, "platform" | "installPods" | "configuration" | "destination" | "simulator">> & {
|
|
67
67
|
hotUpdaterSchemeName: string;
|
|
68
68
|
};
|
|
69
69
|
declare const enrichNativeBuildIosScheme: ({ scheme, hotUpdaterSchemeName }: {
|
|
70
|
-
scheme:
|
|
70
|
+
scheme: ResolvedNativeBuildIosScheme;
|
|
71
71
|
hotUpdaterSchemeName: string;
|
|
72
72
|
}) => Promise<EnrichedNativeBuildIosScheme>;
|
|
73
73
|
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CredentialRequest, CredentialResolver, Credentials } from "@hot-updater/cli-tools";
|
|
1
|
+
import { CredentialRequest, CredentialResolver, Credentials, ResolvedNativeBuildIosScheme } from "@hot-updater/cli-tools";
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import { NativeBuildIosScheme } from "@hot-updater/plugin-core";
|
|
4
4
|
//#region src/ascApiKey.d.ts
|
|
@@ -64,11 +64,11 @@ declare const issueAscApiKey: IssueAscApiKey;
|
|
|
64
64
|
/**
|
|
65
65
|
* Validated scheme filled nullish values with default values.
|
|
66
66
|
*/
|
|
67
|
-
type EnrichedNativeBuildIosScheme =
|
|
67
|
+
type EnrichedNativeBuildIosScheme = ResolvedNativeBuildIosScheme & Required<Pick<ResolvedNativeBuildIosScheme, "platform" | "installPods" | "configuration" | "destination" | "simulator">> & {
|
|
68
68
|
hotUpdaterSchemeName: string;
|
|
69
69
|
};
|
|
70
70
|
declare const enrichNativeBuildIosScheme: ({ scheme, hotUpdaterSchemeName }: {
|
|
71
|
-
scheme:
|
|
71
|
+
scheme: ResolvedNativeBuildIosScheme;
|
|
72
72
|
hotUpdaterSchemeName: string;
|
|
73
73
|
}) => Promise<EnrichedNativeBuildIosScheme>;
|
|
74
74
|
//#endregion
|
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, normalizeIosUdid, sandboxChannelOf, sandboxUrlSchemeOf } from "@hot-updater/protocol/native-artifact";
|
|
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";
|
|
5
5
|
import crypto$1 from "crypto";
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
@@ -2000,8 +2000,8 @@ const PRECOMPILES = /* @__PURE__ */ new Set([
|
|
|
2000
2000
|
const plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
2001
2001
|
/**
|
|
2002
2002
|
* Reads the phase of an `xcodebuild` build, archive, or export from its raw
|
|
2003
|
-
* output: `Compiling React-Core · 412 files`, `Linking
|
|
2004
|
-
* `Signing
|
|
2003
|
+
* output: `Compiling React-Core · 412 files`, `Linking ExampleApp`,
|
|
2004
|
+
* `Signing ExampleApp`, `Bundling JavaScript`, with the target each
|
|
2005
2005
|
* action's line names.
|
|
2006
2006
|
*/
|
|
2007
2007
|
const createXcodebuildPhaseReader = () => {
|
|
@@ -3314,7 +3314,6 @@ const readTestFlightBuildStatus = async ({ bundleId, shortVersion, bundleVersion
|
|
|
3314
3314
|
};
|
|
3315
3315
|
//#endregion
|
|
3316
3316
|
//#region src/utils/sandboxInfoPlist.ts
|
|
3317
|
-
const URL_TYPE_NAME = "hot-updater-sandbox";
|
|
3318
3317
|
const CAMERA_USAGE = "Scans the QR code of a preview to open it in this build.";
|
|
3319
3318
|
const LOCAL_NETWORK_USAGE = "Connects to the dev server you choose on this network.";
|
|
3320
3319
|
const ATS_KEY = "NSAppTransportSecurity";
|
|
@@ -3344,12 +3343,8 @@ const setString = (plist, key, value) => plutil([
|
|
|
3344
3343
|
value,
|
|
3345
3344
|
plist
|
|
3346
3345
|
]);
|
|
3347
|
-
/**
|
|
3348
|
-
const
|
|
3349
|
-
const urlType = JSON.stringify({
|
|
3350
|
-
CFBundleURLName: URL_TYPE_NAME,
|
|
3351
|
-
CFBundleURLSchemes: [urlScheme]
|
|
3352
|
-
});
|
|
3346
|
+
/** The app's own URL types, or null when it has none. */
|
|
3347
|
+
const readUrlTypes = async (plist) => {
|
|
3353
3348
|
const { stdout, exitCode } = await execa("plutil", [
|
|
3354
3349
|
"-extract",
|
|
3355
3350
|
"CFBundleURLTypes",
|
|
@@ -3358,7 +3353,35 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3358
3353
|
"-",
|
|
3359
3354
|
plist
|
|
3360
3355
|
], { reject: false });
|
|
3361
|
-
|
|
3356
|
+
return exitCode === 0 ? JSON.parse(stdout) : null;
|
|
3357
|
+
};
|
|
3358
|
+
const isSandboxUrlType = (type) => type?.CFBundleURLName === SANDBOX_URL_TYPE_NAME;
|
|
3359
|
+
/**
|
|
3360
|
+
* Appends a URL type with the sandbox's scheme to the app's own, or, in an
|
|
3361
|
+
* app an earlier patch made a sandbox app, replaces the one that patch added.
|
|
3362
|
+
*/
|
|
3363
|
+
const addUrlScheme = async (plist, urlScheme, existing, patchedBefore) => {
|
|
3364
|
+
const urlType = JSON.stringify({
|
|
3365
|
+
CFBundleURLName: SANDBOX_URL_TYPE_NAME,
|
|
3366
|
+
CFBundleURLSchemes: [urlScheme]
|
|
3367
|
+
});
|
|
3368
|
+
const patched = patchedBefore ? existing?.findIndex(isSandboxUrlType) ?? -1 : -1;
|
|
3369
|
+
if (patched !== -1) {
|
|
3370
|
+
await plutil([
|
|
3371
|
+
"-remove",
|
|
3372
|
+
`CFBundleURLTypes.${patched}`,
|
|
3373
|
+
plist
|
|
3374
|
+
]);
|
|
3375
|
+
await plutil([
|
|
3376
|
+
"-insert",
|
|
3377
|
+
`CFBundleURLTypes.${patched}`,
|
|
3378
|
+
"-json",
|
|
3379
|
+
urlType,
|
|
3380
|
+
plist
|
|
3381
|
+
]);
|
|
3382
|
+
return;
|
|
3383
|
+
}
|
|
3384
|
+
if (existing === null) {
|
|
3362
3385
|
await plutil([
|
|
3363
3386
|
"-insert",
|
|
3364
3387
|
"CFBundleURLTypes",
|
|
@@ -3368,7 +3391,6 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3368
3391
|
]);
|
|
3369
3392
|
return;
|
|
3370
3393
|
}
|
|
3371
|
-
const existing = JSON.parse(stdout);
|
|
3372
3394
|
await plutil([
|
|
3373
3395
|
"-insert",
|
|
3374
3396
|
`CFBundleURLTypes.${existing.length}`,
|
|
@@ -3377,6 +3399,16 @@ const addUrlScheme = async (plist, urlScheme) => {
|
|
|
3377
3399
|
plist
|
|
3378
3400
|
]);
|
|
3379
3401
|
};
|
|
3402
|
+
/** The schemes a URL type lists. */
|
|
3403
|
+
const schemesOf = (type) => {
|
|
3404
|
+
const schemes = type?.CFBundleURLSchemes;
|
|
3405
|
+
return Array.isArray(schemes) ? schemes : [];
|
|
3406
|
+
};
|
|
3407
|
+
/** Whether URL types list `urlScheme`, as iOS compares schemes: ignoring case. */
|
|
3408
|
+
const registersUrlScheme = (urlTypes, urlScheme) => urlTypes.some((type) => {
|
|
3409
|
+
const schemes = type?.CFBundleURLSchemes;
|
|
3410
|
+
return Array.isArray(schemes) && schemes.some((scheme) => typeof scheme === "string" && scheme.toLowerCase() === urlScheme.toLowerCase());
|
|
3411
|
+
});
|
|
3380
3412
|
const hasKey = async (plist, key) => {
|
|
3381
3413
|
const { exitCode } = await execa("plutil", [
|
|
3382
3414
|
"-extract",
|
|
@@ -3418,13 +3450,21 @@ const addSandboxPermissions = async (plist) => {
|
|
|
3418
3450
|
};
|
|
3419
3451
|
/**
|
|
3420
3452
|
* The app's dedicated URL scheme, default channel, and the sandbox's key. The
|
|
3421
|
-
* URL scheme and App Store Connect's app come
|
|
3422
|
-
* `bundleIdentifier`, while Xcode's build settings decide
|
|
3423
|
-
* app of another ID stops here, before anything is signed
|
|
3453
|
+
* URL scheme, unless the scheme sets one, and App Store Connect's app come
|
|
3454
|
+
* from the scheme's `bundleIdentifier`, while Xcode's build settings decide
|
|
3455
|
+
* the app's ID, so an app of another ID stops here, before anything is signed
|
|
3456
|
+
* or uploaded.
|
|
3424
3457
|
*/
|
|
3425
3458
|
const patchAppInfoPlist = async (plist, scheme) => {
|
|
3426
3459
|
const built = await readValue(plist, "CFBundleIdentifier");
|
|
3427
3460
|
if (built !== scheme.bundleIdentifier) throw refusal(`The sandbox scheme ${scheme.hotUpdaterSchemeName} sets bundleIdentifier ${scheme.bundleIdentifier}, but Xcode built ${built ?? "no bundle ID"}.\nSet bundleIdentifier to the ID its configuration builds.`);
|
|
3461
|
+
const urlScheme = scheme.sandboxUrlScheme ?? sandboxUrlSchemeOf(scheme.bundleIdentifier);
|
|
3462
|
+
const urlTypes = await readUrlTypes(plist);
|
|
3463
|
+
const patchedBefore = await readValue(plist, SANDBOX_INFO_PLIST_KEY) === "true";
|
|
3464
|
+
const appUrlTypes = (urlTypes ?? []).filter((type) => !(patchedBefore && isSandboxUrlType(type)));
|
|
3465
|
+
if (appUrlTypes.some(isSandboxUrlType)) throw refusal(`The app has a URL type named ${SANDBOX_URL_TYPE_NAME}, the name a sandbox build registers its URL scheme under.\nRename the app's URL type.`);
|
|
3466
|
+
if (patchedBefore) await refuseForeignSandboxUrlTypes(plist, urlTypes ?? [], scheme);
|
|
3467
|
+
if (registersUrlScheme(appUrlTypes, urlScheme)) throw refusal(`The sandbox scheme ${scheme.hotUpdaterSchemeName} registers URL scheme ${urlScheme}, which the app registers itself.\nSet sandbox.urlScheme to a scheme the app doesn't register.`);
|
|
3428
3468
|
await setString(plist, "HOT_UPDATER_CHANNEL", sandboxChannelOf(scheme.hotUpdaterSchemeName));
|
|
3429
3469
|
await plutil([
|
|
3430
3470
|
"-replace",
|
|
@@ -3433,9 +3473,64 @@ const patchAppInfoPlist = async (plist, scheme) => {
|
|
|
3433
3473
|
"true",
|
|
3434
3474
|
plist
|
|
3435
3475
|
]);
|
|
3436
|
-
await addUrlScheme(plist,
|
|
3476
|
+
await addUrlScheme(plist, urlScheme, urlTypes, patchedBefore);
|
|
3477
|
+
await setString(plist, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, urlScheme);
|
|
3437
3478
|
await addSandboxPermissions(plist);
|
|
3438
3479
|
};
|
|
3480
|
+
/**
|
|
3481
|
+
* A key's value as written, or undefined when the plist has no such key:
|
|
3482
|
+
* strings, numbers and booleans as they are, and any other type as itself
|
|
3483
|
+
* named, which no rule takes. `-extract … json` refuses a lone scalar.
|
|
3484
|
+
*/
|
|
3485
|
+
const readTyped = async (plist, key) => {
|
|
3486
|
+
const type = await execa("plutil", [
|
|
3487
|
+
"-type",
|
|
3488
|
+
key,
|
|
3489
|
+
plist
|
|
3490
|
+
], { reject: false });
|
|
3491
|
+
if (type.exitCode !== 0) return void 0;
|
|
3492
|
+
const { stdout } = await execa("plutil", [
|
|
3493
|
+
"-extract",
|
|
3494
|
+
key,
|
|
3495
|
+
"raw",
|
|
3496
|
+
"-o",
|
|
3497
|
+
"-",
|
|
3498
|
+
plist
|
|
3499
|
+
], {
|
|
3500
|
+
reject: false,
|
|
3501
|
+
stripFinalNewline: false
|
|
3502
|
+
});
|
|
3503
|
+
const raw = stdout.endsWith("\n") ? stdout.slice(0, -1) : stdout;
|
|
3504
|
+
switch (type.stdout.trim()) {
|
|
3505
|
+
case "string": return raw;
|
|
3506
|
+
case "integer":
|
|
3507
|
+
case "float": return Number(raw);
|
|
3508
|
+
case "bool": return raw === "true";
|
|
3509
|
+
default: return `<${type.stdout.trim()}>`;
|
|
3510
|
+
}
|
|
3511
|
+
};
|
|
3512
|
+
/**
|
|
3513
|
+
* Refuses, in an app an earlier patch made a sandbox app, what replacing its
|
|
3514
|
+
* URL type of the sandbox's name could break: by `recordedSandboxUrlScheme`'s
|
|
3515
|
+
* rule, the one URL type of the name must hold the one scheme the patch
|
|
3516
|
+
* recorded alone. A prerelease's patch recorded none, and registered one with
|
|
3517
|
+
* the derived scheme's prefix.
|
|
3518
|
+
*/
|
|
3519
|
+
const refuseForeignSandboxUrlTypes = async (plist, urlTypes, scheme) => {
|
|
3520
|
+
const named = urlTypes.filter(isSandboxUrlType);
|
|
3521
|
+
const value = await readTyped(plist, SANDBOX_URL_SCHEME_INFO_PLIST_KEY);
|
|
3522
|
+
const recorded = recordedSandboxUrlScheme(value, named);
|
|
3523
|
+
if (typeof recorded === "string") return;
|
|
3524
|
+
const schemes = named.flatMap(schemesOf);
|
|
3525
|
+
if (recorded === void 0) {
|
|
3526
|
+
const only = named.length === 1 && schemes.length === 1 ? schemes[0] : null;
|
|
3527
|
+
if (typeof only === "string" && isSandboxUrlScheme(only)) return;
|
|
3528
|
+
} else if (!isRecordedUrlSchemeSyntax(value)) throw refusal(`The app's Info.plist records sandbox URL scheme ${JSON.stringify(value)} in ${SANDBOX_URL_SCHEME_INFO_PLIST_KEY}, which isn't a URL scheme.\nBuild the app again: a new build records none.`);
|
|
3529
|
+
const keep = isRecordedUrlSchemeSyntax(value) ? value : sandboxUrlSchemeOf(scheme.bundleIdentifier);
|
|
3530
|
+
const holds = schemes.map(String).join(", ") || "no scheme";
|
|
3531
|
+
const found = named.length === 1 ? `The app's ${SANDBOX_URL_TYPE_NAME} URL type holds ${holds}.` : `The app has ${named.length} ${SANDBOX_URL_TYPE_NAME} URL types${named.length === 0 ? "" : `, holding ${holds}`}.`;
|
|
3532
|
+
throw refusal(`${found}\nKeep exactly one ${SANDBOX_URL_TYPE_NAME} URL type, holding only ${keep}, and move the rest to a URL type of the app's own.`);
|
|
3533
|
+
};
|
|
3439
3534
|
/** The Info.plist of each app extension inside an `.app`. */
|
|
3440
3535
|
const extensionInfoPlists = (appPath) => ["PlugIns", "Extensions"].flatMap((directory) => {
|
|
3441
3536
|
const extensions = path.join(appPath, directory);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/apple-helper",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.25",
|
|
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/cli-tools": "1.2.0-rc.
|
|
33
|
-
"@hot-updater/
|
|
34
|
-
"@hot-updater/
|
|
32
|
+
"@hot-updater/cli-tools": "1.2.0-rc.25",
|
|
33
|
+
"@hot-updater/plugin-core": "1.2.0-rc.25",
|
|
34
|
+
"@hot-updater/protocol": "1.2.0-rc.25"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20"
|