create-expo-updates-server 0.1.3 → 0.1.4

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.
Files changed (29) hide show
  1. package/dist/template/README.md +12 -7
  2. package/dist/template/app/api/admin/embedded-updates/route.test.ts +36 -1
  3. package/dist/template/app/api/admin/updates/route.test.ts +29 -1
  4. package/dist/template/app/updates/embedded/page.tsx +6 -2
  5. package/dist/template/app/updates/page.tsx +6 -2
  6. package/dist/template/docs/expo-app-setup.md +14 -3
  7. package/dist/template/docs/getting-started.md +12 -7
  8. package/dist/template/docs/getting-started.ru.md +13 -6
  9. package/dist/template/docs/migrations/2026-09-01-app-version-columns.sql +23 -0
  10. package/dist/template/docs/migrations/schema.sql +22 -0
  11. package/dist/template/package-lock.json +2 -2
  12. package/dist/template/package.json +1 -1
  13. package/dist/template/scripts/configure-expo-app.mjs +6 -0
  14. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +383 -3
  15. package/dist/template/scripts/lib/expo-app-configurator.mjs +165 -9
  16. package/dist/template/scripts/lib/expo-app-configurator.test.ts +658 -9
  17. package/dist/template/src/client/admin-types.ts +2 -0
  18. package/dist/template/src/server/lib/admin-embedded-updates.test.ts +57 -0
  19. package/dist/template/src/server/lib/admin-embedded-updates.ts +42 -25
  20. package/dist/template/src/server/lib/admin-updates.test.ts +61 -0
  21. package/dist/template/src/server/lib/admin-updates.ts +23 -3
  22. package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +23 -1
  23. package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +13 -4
  24. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +53 -7
  25. package/dist/template/templates/expo-app/scripts/ota-register-embedded/register-ios.sh +87 -0
  26. package/dist/template-manifest.json +65 -50
  27. package/package.json +1 -1
  28. package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +0 -36
  29. /package/dist/template/templates/expo-app/scripts/ota-register-embedded/{android-register-embedded-update.sh → register-android.sh} +0 -0
@@ -2,15 +2,336 @@ import fs from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { execFileSync } from "node:child_process";
5
+ import crypto from "node:crypto";
5
6
  import { afterEach, describe, expect, it } from "vitest";
6
7
  import { configureExpoApp } from "./expo-app-configurator.mjs";
7
8
 
8
9
  const temporaryDirectories: string[] = [];
10
+ const appTemplateRoot = path.resolve("templates/expo-app");
11
+ const registrarRelativePath = path.join(
12
+ "scripts",
13
+ "ota-register-embedded",
14
+ "index.mjs",
15
+ );
16
+ const legacyRegistrarSha256 =
17
+ "29c48288d4804c072129da0ef60a12ad0892809eb8d57a14be94d039d990d6d7";
18
+ const manifestOnlyRegistrarSha256 =
19
+ "89997ef11a939ce00e65159bd8e04845f16b184d5192f8fb56b1bc4204b07bca";
20
+ const previousCanonicalIosRegistrarSha256 =
21
+ "37e0edac0397e5dc1d48d1641a8ed1f113495e3d24ce1d3c66c62e31c0ca7198";
22
+ const legacyAndroidRegistrar = `#!/bin/sh
23
+
24
+ set -eu
25
+
26
+ PROJECT_ROOT="$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)"
27
+ MANIFEST_PATH="$(find "$PROJECT_ROOT/android/app/build" -type f -name app.manifest 2>/dev/null | head -n 1 || true)"
28
+
29
+ if [ -z "$MANIFEST_PATH" ]; then
30
+ echo "Embedded update registration failed: Android app.manifest was not found." >&2
31
+ [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
32
+ exit 0
33
+ fi
34
+
35
+ if ! node "$PROJECT_ROOT/scripts/ota-register-embedded/index.mjs" \\
36
+ --manifest "$MANIFEST_PATH" \\
37
+ --platform android; then
38
+ [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
39
+ fi
40
+ `;
41
+ const legacyIosRegistrar = `#!/bin/sh
42
+
43
+ set -eu
44
+
45
+ if [ "\${CONFIGURATION:-Release}" = "Debug" ]; then
46
+ exit 0
47
+ fi
48
+
49
+ PROJECT_ROOT="\${CI_PRIMARY_REPOSITORY_PATH:-$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)}"
50
+ MANIFEST_PATH=""
51
+
52
+ for candidate in \\
53
+ "\${TARGET_BUILD_DIR:-}/\${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}/app.manifest" \\
54
+ "\${CI_ARCHIVE_PATH:-}/Products/Applications/"*.app/app.manifest
55
+ do
56
+ if [ -f "$candidate" ]; then
57
+ MANIFEST_PATH="$candidate"
58
+ break
59
+ fi
60
+ done
61
+
62
+ if [ -z "$MANIFEST_PATH" ] && [ -n "\${TARGET_BUILD_DIR:-}" ]; then
63
+ MANIFEST_PATH="$(find "$TARGET_BUILD_DIR" -type f -name app.manifest 2>/dev/null | head -n 1 || true)"
64
+ fi
65
+
66
+ if [ -z "$MANIFEST_PATH" ]; then
67
+ echo "Embedded update registration failed: iOS app.manifest was not found." >&2
68
+ [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
69
+ exit 0
70
+ fi
71
+
72
+ if ! node "$PROJECT_ROOT/scripts/ota-register-embedded/index.mjs" \\
73
+ --manifest "$MANIFEST_PATH" \\
74
+ --platform ios; then
75
+ [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
76
+ fi
77
+ `;
78
+ const legacyXcodeCloudHook = `#!/bin/sh
79
+
80
+ set -eu
81
+
82
+ export OTA_EMBEDDED_REGISTER_STRICT="\${OTA_EMBEDDED_REGISTER_STRICT:-true}"
83
+ sh "\${CI_PRIMARY_REPOSITORY_PATH}/ci_scripts/register-embedded-update.sh"
84
+ `;
85
+ const legacyIosPlugin = `const { withXcodeProject } = require("expo/config-plugins");
86
+
87
+ const PHASE_NAME = "Register Expo embedded update";
88
+
89
+ module.exports = function withOtaEmbeddedRegistration(config) {
90
+ return withXcodeProject(config, (projectConfig) => {
91
+ const project = projectConfig.modResults;
92
+ const phases =
93
+ project.hash.project.objects.PBXShellScriptBuildPhase || {};
94
+ const phaseExists = Object.values(phases).some(
95
+ (phase) =>
96
+ phase &&
97
+ typeof phase === "object" &&
98
+ phase.name === \`"\${PHASE_NAME}"\`,
99
+ );
100
+
101
+ if (!phaseExists) {
102
+ project.addBuildPhase(
103
+ [],
104
+ "PBXShellScriptBuildPhase",
105
+ PHASE_NAME,
106
+ project.getFirstTarget().uuid,
107
+ {
108
+ shellPath: "/bin/sh",
109
+ shellScript:
110
+ 'OTA_EMBEDDED_REGISTER_STRICT=true sh "$PROJECT_DIR/../ci_scripts/register-embedded-update.sh"',
111
+ },
112
+ );
113
+ }
114
+
115
+ return projectConfig;
116
+ });
117
+ };
118
+ `;
119
+ const previousCanonicalIosRegistrar = `#!/bin/sh
120
+
121
+ set -eu
122
+
123
+ if [ "\${CONFIGURATION:-Release}" = "Debug" ]; then
124
+ exit 0
125
+ fi
126
+
127
+ fail_registration() {
128
+ echo "Embedded update registration failed: $1" >&2
129
+ if [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ]; then
130
+ exit 1
131
+ fi
132
+ exit 0
133
+ }
134
+
135
+ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)" ||
136
+ fail_registration "unable to resolve the registration script directory."
137
+ PROJECT_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)" ||
138
+ fail_registration "unable to resolve the Expo project root."
139
+ REGISTRAR_PATH="$PROJECT_ROOT/scripts/ota-register-embedded/index.mjs"
140
+ MANIFEST_PATH=""
141
+
142
+ if [ ! -f "$REGISTRAR_PATH" ]; then
143
+ fail_registration "registrar was not found at $REGISTRAR_PATH."
144
+ fi
145
+
146
+ if [ -n "\${TARGET_BUILD_DIR:-}" ] &&
147
+ [ -n "\${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}" ] &&
148
+ [ -f "$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/app.manifest" ]; then
149
+ MANIFEST_PATH="$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/app.manifest"
150
+ fi
151
+
152
+ if [ -z "$MANIFEST_PATH" ] && [ -n "\${CI_ARCHIVE_PATH:-}" ]; then
153
+ for candidate in "$CI_ARCHIVE_PATH"/Products/Applications/*.app/app.manifest; do
154
+ if [ -f "$candidate" ]; then
155
+ MANIFEST_PATH="$candidate"
156
+ break
157
+ fi
158
+ done
159
+ fi
160
+
161
+ if [ -z "$MANIFEST_PATH" ] && [ -n "\${TARGET_BUILD_DIR:-}" ]; then
162
+ MANIFEST_PATH="$(find "$TARGET_BUILD_DIR" -type f -name app.manifest 2>/dev/null | head -n 1 || true)"
163
+ fi
164
+
165
+ if [ -z "$MANIFEST_PATH" ]; then
166
+ fail_registration "iOS app.manifest was not found."
167
+ fi
168
+
169
+ if ! node "$REGISTRAR_PATH" \\
170
+ --manifest "$MANIFEST_PATH" \\
171
+ --platform ios; then
172
+ if [ "\${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ]; then
173
+ exit 1
174
+ fi
175
+ fi
176
+ `;
177
+
178
+ if (
179
+ crypto
180
+ .createHash("sha256")
181
+ .update(previousCanonicalIosRegistrar)
182
+ .digest("hex") !== previousCanonicalIosRegistrarSha256
183
+ ) {
184
+ throw new Error("Previous canonical iOS registrar fixture hash changed");
185
+ }
186
+
187
+ function readCurrentRegistrar() {
188
+ return fs.readFileSync(
189
+ path.join(appTemplateRoot, registrarRelativePath),
190
+ "utf8",
191
+ );
192
+ }
193
+
194
+ function createManifestOnlyRegistrar() {
195
+ const manifestOnly = readCurrentRegistrar()
196
+ .replace(
197
+ `
198
+ export function readExpoAppVersion(appRoot, readFile = fs.readFileSync) {
199
+ try {
200
+ const appJson = JSON.parse(
201
+ readFile(path.join(appRoot, "app.json"), "utf8"),
202
+ );
203
+ const appVersion = appJson?.expo?.version;
204
+ return typeof appVersion === "string" && appVersion.trim()
205
+ ? appVersion.trim()
206
+ : null;
207
+ } catch {
208
+ return null;
209
+ }
210
+ }
211
+
212
+ export function parseEmbeddedManifestForProject(
213
+ content,
214
+ appRoot,
215
+ fallbackDate = new Date(),
216
+ readFile = fs.readFileSync,
217
+ ) {
218
+ const fields = parseEmbeddedManifest(content, fallbackDate);
219
+ return {
220
+ ...fields,
221
+ appVersion: fields.appVersion || readExpoAppVersion(appRoot, readFile),
222
+ };
223
+ }
224
+ `,
225
+ "",
226
+ )
227
+ .replace(
228
+ `function readChannel(appRoot, explicitChannel) {
229
+ const configuredChannel =
230
+ explicitChannel || process.env.EXPO_UPDATE_CHANNEL;
231
+ if (configuredChannel) {
232
+ return configuredChannel.trim().toLowerCase();
233
+ }
234
+
235
+ const appJson = JSON.parse(
236
+ fs.readFileSync(path.join(appRoot, "app.json"), "utf8"),
237
+ );
238
+ return String(
239
+ appJson.expo?.updates?.requestHeaders?.["expo-channel-name"] ||
240
+ `,
241
+ `function readChannel(appRoot, explicitChannel) {
242
+ if (explicitChannel) {
243
+ return explicitChannel.trim().toLowerCase();
244
+ }
245
+
246
+ const appJson = JSON.parse(
247
+ fs.readFileSync(path.join(appRoot, "app.json"), "utf8"),
248
+ );
249
+ return String(
250
+ process.env.EXPO_UPDATE_CHANNEL ||
251
+ appJson.expo?.updates?.requestHeaders?.["expo-channel-name"] ||
252
+ `,
253
+ )
254
+ .replace(
255
+ ` const fields = parseEmbeddedManifestForProject(
256
+ fs.readFileSync(manifestPath, "utf8"),
257
+ ROOT_DIR,
258
+ fs.statSync(manifestPath).mtime,
259
+ );
260
+ `,
261
+ ` const fields = parseEmbeddedManifest(
262
+ fs.readFileSync(manifestPath, "utf8"),
263
+ fs.statSync(manifestPath).mtime,
264
+ );
265
+ `,
266
+ );
267
+
268
+ const digest = crypto
269
+ .createHash("sha256")
270
+ .update(manifestOnly)
271
+ .digest("hex");
272
+ if (digest !== manifestOnlyRegistrarSha256) {
273
+ throw new Error(`Manifest-only registrar fixture hash changed: ${digest}`);
274
+ }
275
+
276
+ return manifestOnly;
277
+ }
278
+
279
+ function createLegacyRegistrar() {
280
+ const legacy = createManifestOnlyRegistrar()
281
+ .replace(
282
+ ` const appVersion =
283
+ readPath(manifest, [
284
+ ["extra", "expoClient", "version"],
285
+ ["expoClient", "version"],
286
+ ["version"],
287
+ ]) ||
288
+ readPath(root, [
289
+ ["extra", "expoClient", "version"],
290
+ ["expoClient", "version"],
291
+ ["version"],
292
+ ]);
293
+ `,
294
+ "",
295
+ )
296
+ .replace(
297
+ ` appVersion: typeof appVersion === "string" ? appVersion : null,
298
+ `,
299
+ "",
300
+ )
301
+ .replace(
302
+ " embedded_update_id, app_version, created_at, channel, platform, is_embedded\n" +
303
+ " ) VALUES ($1, $2, $3, $4, $5, true)",
304
+ " embedded_update_id, created_at, channel, platform, is_embedded\n" +
305
+ " ) VALUES ($1, $2, $3, $4, true)",
306
+ )
307
+ .replace(
308
+ ` app_version = COALESCE(
309
+ NULLIF(BTRIM(EXCLUDED.app_version), ''),
310
+ ota_embedded_updates.app_version
311
+ ),
312
+ `,
313
+ "",
314
+ )
315
+ .replace(" input.appVersion || null,\n", "");
316
+
317
+ const digest = crypto
318
+ .createHash("sha256")
319
+ .update(legacy)
320
+ .digest("hex");
321
+ if (digest !== legacyRegistrarSha256) {
322
+ throw new Error(`Legacy registrar fixture hash changed: ${digest}`);
323
+ }
324
+
325
+ return legacy;
326
+ }
9
327
 
10
328
  function createFixture() {
11
329
  const root = fs.mkdtempSync(path.join(os.tmpdir(), "ota-expo-config-"));
12
330
  temporaryDirectories.push(root);
13
331
 
332
+ const templateRoot = path.join(root, "expo-app-template");
333
+ fs.cpSync(appTemplateRoot, templateRoot, { recursive: true });
334
+
14
335
  const appRoot = path.join(root, "app");
15
336
  fs.mkdirSync(appRoot, { recursive: true });
16
337
  fs.writeFileSync(
@@ -69,7 +390,7 @@ function createFixture() {
69
390
  certificatePath,
70
391
  ]);
71
392
 
72
- return { appRoot, certificatePath };
393
+ return { appRoot, certificatePath, templateRoot };
73
394
  }
74
395
 
75
396
  function createRunner() {
@@ -101,7 +422,7 @@ afterEach(() => {
101
422
 
102
423
  describe("configureExpoApp", () => {
103
424
  it("configures receiving, publishing and native prebuild", () => {
104
- const { appRoot, certificatePath } = createFixture();
425
+ const { appRoot, certificatePath, templateRoot } = createFixture();
105
426
  const { calls, commandRunner } = createRunner();
106
427
 
107
428
  const result = configureExpoApp(
@@ -113,7 +434,7 @@ describe("configureExpoApp", () => {
113
434
  runtimeVersion: "1.2.3",
114
435
  platform: "all",
115
436
  },
116
- { commandRunner },
437
+ { commandRunner, templateRoot },
117
438
  );
118
439
 
119
440
  const appJson = JSON.parse(
@@ -131,6 +452,7 @@ describe("configureExpoApp", () => {
131
452
  platform: "all",
132
453
  packageManager: "npm",
133
454
  publisherEnvConfigured: false,
455
+ migrationWarnings: [],
134
456
  });
135
457
 
136
458
  expect(appJson.expo.runtimeVersion).toBe("1.2.3");
@@ -157,7 +479,7 @@ describe("configureExpoApp", () => {
157
479
  "node scripts/ota-publish/index.mjs",
158
480
  );
159
481
  expect(packageJson.scripts["ota:build:android:apk"]).toContain(
160
- "scripts/ota-register-embedded/android-register-embedded-update.sh",
482
+ "scripts/ota-register-embedded/register-android.sh",
161
483
  );
162
484
  expect(
163
485
  fs.readFileSync(
@@ -222,7 +544,17 @@ describe("configureExpoApp", () => {
222
544
  appRoot,
223
545
  "scripts",
224
546
  "ota-register-embedded",
225
- "android-register-embedded-update.sh",
547
+ "register-android.sh",
548
+ ),
549
+ ),
550
+ ).toBe(true);
551
+ expect(
552
+ fs.existsSync(
553
+ path.join(
554
+ appRoot,
555
+ "scripts",
556
+ "ota-register-embedded",
557
+ "register-ios.sh",
226
558
  ),
227
559
  ),
228
560
  ).toBe(true);
@@ -239,7 +571,7 @@ describe("configureExpoApp", () => {
239
571
  fs.existsSync(
240
572
  path.join(appRoot, "ci_scripts", "register-embedded-update.sh"),
241
573
  ),
242
- ).toBe(true);
574
+ ).toBe(false);
243
575
  expect(
244
576
  fs.existsSync(
245
577
  path.join(appRoot, "ci_scripts", "ci_post_xcodebuild.sh"),
@@ -277,7 +609,7 @@ describe("configureExpoApp", () => {
277
609
  });
278
610
 
279
611
  it("creates publisher credentials from local Docker settings", () => {
280
- const { appRoot, certificatePath } = createFixture();
612
+ const { appRoot, certificatePath, templateRoot } = createFixture();
281
613
  const serverRoot = path.dirname(appRoot);
282
614
  fs.writeFileSync(
283
615
  path.join(serverRoot, ".env"),
@@ -305,6 +637,7 @@ describe("configureExpoApp", () => {
305
637
  {
306
638
  commandRunner: createRunner().commandRunner,
307
639
  serverRoot,
640
+ templateRoot,
308
641
  },
309
642
  );
310
643
 
@@ -328,7 +661,7 @@ describe("configureExpoApp", () => {
328
661
  });
329
662
 
330
663
  it("stops an existing Android Gradle daemon before prebuild", () => {
331
- const { appRoot, certificatePath } = createFixture();
664
+ const { appRoot, certificatePath, templateRoot } = createFixture();
332
665
  const gradleWrapper = path.join(appRoot, "android", "gradlew");
333
666
  fs.mkdirSync(path.dirname(gradleWrapper), { recursive: true });
334
667
  fs.writeFileSync(gradleWrapper, "#!/bin/sh\n");
@@ -343,7 +676,7 @@ describe("configureExpoApp", () => {
343
676
  runtimeVersion: "1.0.0",
344
677
  platform: "android",
345
678
  },
346
- { commandRunner },
679
+ { commandRunner, templateRoot },
347
680
  );
348
681
 
349
682
  const stopIndex = calls.findIndex(
@@ -460,4 +793,320 @@ describe("configureExpoApp", () => {
460
793
  originalAppJson,
461
794
  );
462
795
  });
796
+
797
+ it("upgrades the exact legacy embedded registrar without force", () => {
798
+ const { appRoot, certificatePath, templateRoot } = createFixture();
799
+ const registrarPath = path.join(appRoot, registrarRelativePath);
800
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
801
+ fs.writeFileSync(registrarPath, createLegacyRegistrar());
802
+
803
+ configureExpoApp(
804
+ {
805
+ app: appRoot,
806
+ certificate: certificatePath,
807
+ serverUrl: "https://updates.example.com",
808
+ channel: "production",
809
+ runtimeVersion: "1.0.0",
810
+ },
811
+ {
812
+ commandRunner: createRunner().commandRunner,
813
+ templateRoot,
814
+ },
815
+ );
816
+
817
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
818
+ readCurrentRegistrar(),
819
+ );
820
+ });
821
+
822
+ it("upgrades the manifest-only embedded registrar without force", () => {
823
+ const { appRoot, certificatePath, templateRoot } = createFixture();
824
+ const registrarPath = path.join(appRoot, registrarRelativePath);
825
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
826
+ fs.writeFileSync(registrarPath, createManifestOnlyRegistrar());
827
+
828
+ configureExpoApp(
829
+ {
830
+ app: appRoot,
831
+ certificate: certificatePath,
832
+ serverUrl: "https://updates.example.com",
833
+ channel: "production",
834
+ runtimeVersion: "1.0.0",
835
+ },
836
+ {
837
+ commandRunner: createRunner().commandRunner,
838
+ templateRoot,
839
+ },
840
+ );
841
+
842
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
843
+ readCurrentRegistrar(),
844
+ );
845
+ });
846
+
847
+ it("rejects a customized legacy embedded registrar without force", () => {
848
+ const { appRoot, certificatePath, templateRoot } = createFixture();
849
+ const registrarPath = path.join(appRoot, registrarRelativePath);
850
+ const customizedRegistrar =
851
+ `${createLegacyRegistrar()}\n// User customization.\n`;
852
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
853
+ fs.writeFileSync(registrarPath, customizedRegistrar);
854
+
855
+ expect(() =>
856
+ configureExpoApp(
857
+ {
858
+ app: appRoot,
859
+ certificate: certificatePath,
860
+ serverUrl: "https://updates.example.com",
861
+ channel: "production",
862
+ runtimeVersion: "1.0.0",
863
+ },
864
+ {
865
+ commandRunner: createRunner().commandRunner,
866
+ templateRoot,
867
+ },
868
+ ),
869
+ ).toThrow(`Refusing to overwrite ${registrarPath}`);
870
+
871
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
872
+ customizedRegistrar,
873
+ );
874
+ });
875
+
876
+ it("accepts the identical current embedded registrar idempotently", () => {
877
+ const { appRoot, certificatePath, templateRoot } = createFixture();
878
+ const registrarPath = path.join(appRoot, registrarRelativePath);
879
+ const currentRegistrar = readCurrentRegistrar();
880
+ const options = {
881
+ app: appRoot,
882
+ certificate: certificatePath,
883
+ serverUrl: "https://updates.example.com",
884
+ channel: "production",
885
+ runtimeVersion: "1.0.0",
886
+ };
887
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
888
+ fs.writeFileSync(registrarPath, currentRegistrar);
889
+
890
+ const firstRunner = createRunner();
891
+ const secondRunner = createRunner();
892
+ configureExpoApp(options, {
893
+ commandRunner: firstRunner.commandRunner,
894
+ templateRoot,
895
+ });
896
+ configureExpoApp(options, {
897
+ commandRunner: secondRunner.commandRunner,
898
+ templateRoot,
899
+ });
900
+
901
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
902
+ currentRegistrar,
903
+ );
904
+ });
905
+
906
+ it("upgrades the previous canonical iOS registrar without force", () => {
907
+ const { appRoot, certificatePath, templateRoot } = createFixture();
908
+ const registrarPath = path.join(
909
+ appRoot,
910
+ "scripts",
911
+ "ota-register-embedded",
912
+ "register-ios.sh",
913
+ );
914
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
915
+ fs.writeFileSync(registrarPath, previousCanonicalIosRegistrar);
916
+
917
+ configureExpoApp(
918
+ {
919
+ app: appRoot,
920
+ certificate: certificatePath,
921
+ serverUrl: "https://updates.example.com",
922
+ channel: "production",
923
+ runtimeVersion: "1.0.0",
924
+ },
925
+ {
926
+ commandRunner: createRunner().commandRunner,
927
+ templateRoot,
928
+ },
929
+ );
930
+
931
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
932
+ fs.readFileSync(
933
+ path.join(
934
+ appTemplateRoot,
935
+ "scripts",
936
+ "ota-register-embedded",
937
+ "register-ios.sh",
938
+ ),
939
+ "utf8",
940
+ ),
941
+ );
942
+ });
943
+
944
+ it("rejects a customized previous iOS registrar without force", () => {
945
+ const { appRoot, certificatePath, templateRoot } = createFixture();
946
+ const registrarPath = path.join(
947
+ appRoot,
948
+ "scripts",
949
+ "ota-register-embedded",
950
+ "register-ios.sh",
951
+ );
952
+ const customizedRegistrar =
953
+ `${previousCanonicalIosRegistrar}\n# User customization.\n`;
954
+ fs.mkdirSync(path.dirname(registrarPath), { recursive: true });
955
+ fs.writeFileSync(registrarPath, customizedRegistrar);
956
+
957
+ expect(() =>
958
+ configureExpoApp(
959
+ {
960
+ app: appRoot,
961
+ certificate: certificatePath,
962
+ serverUrl: "https://updates.example.com",
963
+ channel: "production",
964
+ runtimeVersion: "1.0.0",
965
+ },
966
+ {
967
+ commandRunner: createRunner().commandRunner,
968
+ templateRoot,
969
+ },
970
+ ),
971
+ ).toThrow(`Refusing to overwrite ${registrarPath}`);
972
+
973
+ expect(fs.readFileSync(registrarPath, "utf8")).toBe(
974
+ customizedRegistrar,
975
+ );
976
+ });
977
+
978
+ it("migrates exact legacy platform registrars without force", () => {
979
+ const { appRoot, certificatePath, templateRoot } = createFixture();
980
+ const legacyAndroidPath = path.join(
981
+ appRoot,
982
+ "scripts",
983
+ "ota-register-embedded",
984
+ "android-register-embedded-update.sh",
985
+ );
986
+ const legacyIosPath = path.join(
987
+ appRoot,
988
+ "ci_scripts",
989
+ "register-embedded-update.sh",
990
+ );
991
+ const xcodeCloudHookPath = path.join(
992
+ appRoot,
993
+ "ci_scripts",
994
+ "ci_post_xcodebuild.sh",
995
+ );
996
+ const iosPluginPath = path.join(
997
+ appRoot,
998
+ "plugins",
999
+ "with-ota-embedded-registration.js",
1000
+ );
1001
+ fs.mkdirSync(path.dirname(legacyAndroidPath), { recursive: true });
1002
+ fs.mkdirSync(path.dirname(legacyIosPath), { recursive: true });
1003
+ fs.mkdirSync(path.dirname(iosPluginPath), { recursive: true });
1004
+ fs.writeFileSync(legacyAndroidPath, legacyAndroidRegistrar);
1005
+ fs.writeFileSync(legacyIosPath, legacyIosRegistrar);
1006
+ fs.writeFileSync(xcodeCloudHookPath, legacyXcodeCloudHook);
1007
+ fs.writeFileSync(iosPluginPath, legacyIosPlugin);
1008
+
1009
+ const packagePath = path.join(appRoot, "package.json");
1010
+ const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
1011
+ packageJson.scripts["ota:build:android:apk"] =
1012
+ "build && sh scripts/ota-register-embedded/android-register-embedded-update.sh";
1013
+ fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
1014
+
1015
+ const result = configureExpoApp(
1016
+ {
1017
+ app: appRoot,
1018
+ certificate: certificatePath,
1019
+ serverUrl: "https://updates.example.com",
1020
+ channel: "production",
1021
+ runtimeVersion: "1.0.0",
1022
+ },
1023
+ {
1024
+ commandRunner: createRunner().commandRunner,
1025
+ templateRoot,
1026
+ },
1027
+ );
1028
+
1029
+ const configuredPackage = JSON.parse(
1030
+ fs.readFileSync(packagePath, "utf8"),
1031
+ );
1032
+ expect(result.migrationWarnings).toEqual([]);
1033
+ expect(fs.existsSync(legacyAndroidPath)).toBe(false);
1034
+ expect(fs.existsSync(legacyIosPath)).toBe(false);
1035
+ expect(fs.readFileSync(xcodeCloudHookPath, "utf8")).toContain(
1036
+ "scripts/ota-register-embedded/register-ios.sh",
1037
+ );
1038
+ expect(fs.readFileSync(iosPluginPath, "utf8")).toContain(
1039
+ "scripts/ota-register-embedded/register-ios.sh",
1040
+ );
1041
+ expect(
1042
+ fs.existsSync(
1043
+ path.join(
1044
+ appRoot,
1045
+ "scripts",
1046
+ "ota-register-embedded",
1047
+ "register-android.sh",
1048
+ ),
1049
+ ),
1050
+ ).toBe(true);
1051
+ expect(
1052
+ fs.existsSync(
1053
+ path.join(
1054
+ appRoot,
1055
+ "scripts",
1056
+ "ota-register-embedded",
1057
+ "register-ios.sh",
1058
+ ),
1059
+ ),
1060
+ ).toBe(true);
1061
+ expect(
1062
+ configuredPackage.scripts["ota:build:android:apk"],
1063
+ ).toContain("scripts/ota-register-embedded/register-android.sh");
1064
+ });
1065
+
1066
+ it("preserves and reports customized obsolete platform registrars", () => {
1067
+ const { appRoot, certificatePath, templateRoot } = createFixture();
1068
+ const legacyAndroidPath = path.join(
1069
+ appRoot,
1070
+ "scripts",
1071
+ "ota-register-embedded",
1072
+ "android-register-embedded-update.sh",
1073
+ );
1074
+ const legacyIosPath = path.join(
1075
+ appRoot,
1076
+ "ci_scripts",
1077
+ "register-embedded-update.sh",
1078
+ );
1079
+ fs.mkdirSync(path.dirname(legacyAndroidPath), { recursive: true });
1080
+ fs.mkdirSync(path.dirname(legacyIosPath), { recursive: true });
1081
+ fs.writeFileSync(legacyAndroidPath, "# custom Android registrar\n");
1082
+ fs.writeFileSync(legacyIosPath, "# custom iOS registrar\n");
1083
+
1084
+ const result = configureExpoApp(
1085
+ {
1086
+ app: appRoot,
1087
+ certificate: certificatePath,
1088
+ serverUrl: "https://updates.example.com",
1089
+ channel: "production",
1090
+ runtimeVersion: "1.0.0",
1091
+ },
1092
+ {
1093
+ commandRunner: createRunner().commandRunner,
1094
+ templateRoot,
1095
+ },
1096
+ );
1097
+
1098
+ expect(fs.readFileSync(legacyAndroidPath, "utf8")).toBe(
1099
+ "# custom Android registrar\n",
1100
+ );
1101
+ expect(fs.readFileSync(legacyIosPath, "utf8")).toBe(
1102
+ "# custom iOS registrar\n",
1103
+ );
1104
+ expect(result.migrationWarnings).toHaveLength(2);
1105
+ expect(result.migrationWarnings.join("\n")).toContain(
1106
+ "Preserved customized legacy Android registrar",
1107
+ );
1108
+ expect(result.migrationWarnings.join("\n")).toContain(
1109
+ "Preserved customized legacy iOS registrar",
1110
+ );
1111
+ });
463
1112
  });