create-expo-updates-server 0.2.1 → 0.4.0

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 (103) hide show
  1. package/dist/template/README.md +1 -1
  2. package/dist/template/app/updates/[encodedKey]/page.tsx +55 -33
  3. package/dist/template/app/updates/devices/page.tsx +13 -7
  4. package/dist/template/app/updates/embedded/page.tsx +25 -13
  5. package/dist/template/app/updates/emergency-redirects/page.tsx +70 -38
  6. package/dist/template/app/updates/page.tsx +33 -20
  7. package/dist/template/components/admin/admin-shell.tsx +11 -5
  8. package/dist/template/components/admin/language-switcher.tsx +5 -2
  9. package/dist/template/components/ui/dialog.tsx +13 -4
  10. package/dist/template/components/ui/sheet.tsx +6 -2
  11. package/dist/template/components/ui/sidebar.tsx +62 -17
  12. package/dist/template/docs/admin-ui.md +18 -24
  13. package/dist/template/docs/device-targeting.md +4 -5
  14. package/dist/template/docs/expo-app-setup.md +8 -12
  15. package/dist/template/docs/getting-started.md +5 -5
  16. package/dist/template/docs/getting-started.ru.md +11 -544
  17. package/dist/template/docs/index.md +1 -1
  18. package/dist/template/docs/installation-telemetry.md +4 -4
  19. package/dist/template/docs/operations-guide.md +1 -1
  20. package/dist/template/docs/ota-client-lifecycle.md +46 -42
  21. package/dist/template/docs/ota-emergency-recovery.md +34 -57
  22. package/dist/template/docs/ru/admin-ui.md +29 -0
  23. package/dist/template/docs/ru/device-targeting.md +59 -0
  24. package/dist/template/docs/ru/doctor.md +98 -0
  25. package/dist/template/docs/ru/expo-app-setup.md +497 -0
  26. package/dist/template/docs/ru/getting-started.md +391 -0
  27. package/dist/template/docs/ru/index.md +50 -0
  28. package/dist/template/docs/ru/installation-telemetry.md +125 -0
  29. package/dist/template/docs/ru/npm-installer.md +71 -0
  30. package/dist/template/docs/ru/operations-guide.md +317 -0
  31. package/dist/template/docs/ru/ota-client-lifecycle.md +167 -0
  32. package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
  33. package/dist/template/docs/ru/ota-update-policy.md +67 -0
  34. package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
  35. package/dist/template/docs/ru/supabase-setup.md +120 -0
  36. package/dist/template/docs/uk/admin-ui.md +29 -0
  37. package/dist/template/docs/uk/device-targeting.md +59 -0
  38. package/dist/template/docs/uk/doctor.md +98 -0
  39. package/dist/template/docs/uk/expo-app-setup.md +497 -0
  40. package/dist/template/docs/uk/getting-started.md +391 -0
  41. package/dist/template/docs/uk/index.md +50 -0
  42. package/dist/template/docs/uk/installation-telemetry.md +125 -0
  43. package/dist/template/docs/uk/npm-installer.md +71 -0
  44. package/dist/template/docs/uk/operations-guide.md +317 -0
  45. package/dist/template/docs/uk/ota-client-lifecycle.md +167 -0
  46. package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
  47. package/dist/template/docs/uk/ota-update-policy.md +67 -0
  48. package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
  49. package/dist/template/docs/uk/supabase-setup.md +120 -0
  50. package/dist/template/package-lock.json +589 -0
  51. package/dist/template/package.json +2 -0
  52. package/dist/template/scripts/lib/device-identity.test.ts +2 -2
  53. package/dist/template/scripts/lib/doctor.mjs +3 -3
  54. package/dist/template/scripts/lib/doctor.test.mjs +1 -1
  55. package/dist/template/scripts/lib/ota-client-configurator.mjs +116 -34
  56. package/dist/template/scripts/lib/ota-client-configurator.test.ts +210 -61
  57. package/dist/template/scripts/lib/ota-client.test.ts +1 -1
  58. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +435 -118
  59. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +243 -86
  60. package/dist/template/scripts/lib/ota-update-controller.test.ts +10 -9
  61. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +154 -0
  62. package/dist/template/scripts/tests/fixtures/react-native-ui.tsx +34 -0
  63. package/dist/template/scripts/tests/ota-client-types.mjs +69 -0
  64. package/dist/template/src/client/devices/analytics.tsx +21 -8
  65. package/dist/template/src/client/devices/device-name.tsx +3 -1
  66. package/dist/template/src/client/devices/registry.tsx +38 -19
  67. package/dist/template/src/client/devices/version-adoption-chart.tsx +22 -10
  68. package/dist/template/src/client/distribution-control.tsx +27 -14
  69. package/dist/template/src/client/guard-action-combobox.test.ts +1 -1
  70. package/dist/template/src/client/guard-action-combobox.tsx +16 -10
  71. package/dist/template/src/client/i18n/en.json +203 -1
  72. package/dist/template/src/client/i18n/language-switching.test.tsx +224 -0
  73. package/dist/template/src/client/i18n/messages.test.ts +102 -19
  74. package/dist/template/src/client/i18n/messages.ts +31 -16
  75. package/dist/template/src/client/i18n/provider.tsx +6 -3
  76. package/dist/template/src/client/i18n/ru.json +488 -0
  77. package/dist/template/src/client/i18n/uk.json +488 -0
  78. package/dist/template/src/client/i18n/use-formatters.ts +5 -0
  79. package/dist/template/src/client/update-audience-editor.tsx +18 -11
  80. package/dist/template/src/client/update-policy-editor.tsx +64 -39
  81. package/dist/template/templates/expo-app/ota-client/README.md +16 -2
  82. package/dist/template/templates/expo-app/ota-client/controller.ts +107 -0
  83. package/dist/template/templates/expo-app/ota-client/device-identity.ts +48 -0
  84. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +18 -9
  85. package/dist/template/templates/expo-app/ota-client/index.ts +16 -0
  86. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +97 -0
  87. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +293 -0
  88. package/dist/template/templates/expo-app/ota-client/runtime.ts +153 -0
  89. package/dist/template/templates/expo-app/ota-client/types.ts +85 -0
  90. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +25 -0
  91. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +196 -0
  92. package/dist/template/tsconfig.json +3 -1
  93. package/dist/template/vitest.config.mts +3 -0
  94. package/dist/template-manifest.json +302 -127
  95. package/package.json +1 -1
  96. package/dist/template/templates/expo-app/ota-client/controller.js +0 -60
  97. package/dist/template/templates/expo-app/ota-client/device-identity.js +0 -26
  98. package/dist/template/templates/expo-app/ota-client/index.d.ts +0 -47
  99. package/dist/template/templates/expo-app/ota-client/index.js +0 -3
  100. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +0 -48
  101. package/dist/template/templates/expo-app/ota-client/model/update-controller.js +0 -182
  102. package/dist/template/templates/expo-app/ota-client/runtime.js +0 -112
  103. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +0 -56
@@ -13,6 +13,7 @@
13
13
  "lint": "eslint",
14
14
  "docs:dev": "vitepress dev docs",
15
15
  "docs:build": "vitepress build docs",
16
+ "docs:test": "node --test docs/.vitepress/i18n.check.mjs",
16
17
  "docs:preview": "vitepress preview docs",
17
18
  "emergency:import": "node scripts/import-emergency-redirects.mjs",
18
19
  "docker:sync-db-password": "sh scripts/sync-docker-database-password.sh",
@@ -53,6 +54,7 @@
53
54
  "@types/react-dom": "^19",
54
55
  "eslint": "^9",
55
56
  "eslint-config-next": "16.1.6",
57
+ "jsdom": "^27.0.1",
56
58
  "tailwindcss": "^4",
57
59
  "vitepress": "^1.6.4",
58
60
  "vitest": "^4.1.11"
@@ -1,10 +1,10 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
- import { createDeviceIdentity } from '../../templates/expo-app/ota-client/device-identity.js';
3
+ import { createDeviceIdentity } from '../../templates/expo-app/ota-client/device-identity';
4
4
  const digest = async (v: string) => createHash('sha256').update(v).digest('hex');
5
5
  function options(platform = 'android', store = new Map<string, string>()) {
6
6
  return { platform, scope: 'com.example:https://updates.example.com', androidId: () => 'abc123', digest,
7
- uuid: randomUUID, readSecure: async (k: string) => store.get(k), writeSecure: async (k: string, v: string) => { store.set(k, v); } };
7
+ uuid: randomUUID, readSecure: async (k: string) => store.get(k) ?? null, writeSecure: async (k: string, v: string) => { store.set(k, v); } };
8
8
  }
9
9
  describe('device identity independent of installation state', () => {
10
10
  it('recognizes Android reinstalls, isolates app/server and signing identity changes', async () => {
@@ -64,7 +64,7 @@ async function inspectApplication(appRoot, serverUrl, add) {
64
64
  try { require.resolve(name); return false; } catch { return true; }
65
65
  });
66
66
  add('app.dependencies', missing.length ? 'fail' : 'pass', missing.length ? `Missing client dependencies: ${missing.join(', ')}.` : 'Client dependencies are declared and resolvable.', missing.length ? 'Run configure-app or install the documented Expo-compatible client dependencies in the app.' : undefined);
67
- const clientFiles = ['index.js', 'runtime.js', 'controller.js', 'device-identity.js', 'model/update-controller.js', 'model/hooks/useOtaUpdates.js', 'ui/ota-update-gate.js'];
67
+ const clientFiles = ['index.ts', 'types.ts', 'runtime.ts', 'controller.ts', 'device-identity.ts', 'model/update-controller.ts', 'model/hooks/useOtaUpdates.ts', 'ui/ota-updates.tsx', 'ui/ota-update-gate.tsx'];
68
68
  const clientFilesPresent = (await Promise.all(clientFiles.map((file) => exists(path.join(appRoot, 'ota-client', file))))).every(Boolean);
69
69
  add('app.client', clientFilesPresent ? 'pass' : 'fail', clientFilesPresent ? 'Generated client implementation files are present.' : 'Generated client implementation files are incomplete.', clientFilesPresent ? undefined : 'Run configure-app or copy the complete ota-client directory using the manual integration guide.');
70
70
  const updates = expo.updates || {};
@@ -102,10 +102,10 @@ async function inspectApplication(appRoot, serverUrl, add) {
102
102
  } else {
103
103
  const changes = await Promise.all(plan.files.map(async ([file, content]) => content !== await fs.readFile(path.join(appRoot, file), 'utf8')));
104
104
  if (changes.some(Boolean)) throw new Error('root');
105
- add('app.root', 'pass', 'Recognized root hook/gate wiring is present (source inspection only).');
105
+ add('app.root', 'pass', 'Recognized root OTA component wiring is present (source inspection only).');
106
106
  }
107
107
  } catch {
108
- add('app.root', 'fail', 'Root hook/gate or bootstrap metadata is missing or unsupported.', 'Run configure-app or review manual hook integration. Doctor never applies the patch.');
108
+ add('app.root', 'fail', 'Root OTA component or bootstrap metadata is missing or unsupported.', 'Run configure-app or review manual component integration. Doctor never applies the patch.');
109
109
  }
110
110
  try {
111
111
  const publisher = await readDoctorEnv(path.join(appRoot, '.env.ota'));
@@ -210,7 +210,7 @@ describe('doctor read-only contract', () => {
210
210
  expect(valid.checks.filter((item) => item.status === 'fail')).toEqual([]);
211
211
  expect(check(valid, 'app.root').status).toBe('pass');
212
212
  expect(await fs.readFile(path.join(app, 'App.tsx'), 'utf8')).toBe(source);
213
- await fs.unlink(path.join(app, 'ota-client/runtime.js'));
213
+ await fs.unlink(path.join(app, 'ota-client/runtime.ts'));
214
214
  expect(check(await offline(cwd, { app }), 'app.client').status).toBe('fail');
215
215
  config.expo.updates.requestHeaders['expo-channel-name'] = 'Test'; config.expo.runtimeVersion = ' v1 ';
216
216
  await fs.writeFile(path.join(app, 'app.json'), JSON.stringify(config));
@@ -1,69 +1,151 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { planOtaRootHook } from './ota-root-hook-patcher.mjs';
4
- const ENTRY = 'ota-entry.js';
5
- const META = 'ota-client-entry.json';
6
- const extensions = ['tsx', 'ts', 'jsx', 'js', 'mjs', 'cjs'];
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { planOtaRootHook } from "./ota-root-hook-patcher.mjs";
4
+ const ENTRY = "ota-entry.js";
5
+ const META = "ota-client-entry.json";
6
+ const extensions = ["tsx", "ts", "jsx", "js", "mjs", "cjs"];
7
7
  function hasEntry(root, entry, platform) {
8
- const suffixes = platform === 'web' ? ['web', ''] : [platform, 'native', ''];
9
- return suffixes.some((suffix) => extensions.some((ext) => fs.existsSync(path.join(root, `${entry}${suffix ? `.${suffix}` : ''}.${ext}`))));
8
+ const suffixes = platform === "web" ? ["web", ""] : [platform, "native", ""];
9
+ return suffixes.some((suffix) =>
10
+ extensions.some((ext) =>
11
+ fs.existsSync(
12
+ path.join(root, `${entry}${suffix ? `.${suffix}` : ""}.${ext}`),
13
+ ),
14
+ ),
15
+ );
10
16
  }
11
17
 
12
18
  // Preflight every generated file before the main configurator changes the project.
13
- export function planOtaClient({ appRoot, templateRoot, packageJson, manifestUrl, channel, force }) {
19
+ export function planOtaClient({
20
+ appRoot,
21
+ templateRoot,
22
+ packageJson,
23
+ manifestUrl,
24
+ channel,
25
+ force,
26
+ }) {
14
27
  let entry = packageJson.main;
15
28
  if (entry === ENTRY || entry === `./${ENTRY}`) {
16
- const metadata = JSON.parse(fs.readFileSync(path.join(appRoot, META), 'utf8'));
29
+ const metadata = JSON.parse(
30
+ fs.readFileSync(path.join(appRoot, META), "utf8"),
31
+ );
17
32
  entry = metadata.originalEntry;
18
- if (typeof entry !== 'string' || entry.includes('ota-entry')) throw new Error('Invalid original OTA entry metadata');
33
+ if (typeof entry !== "string" || entry.includes("ota-entry"))
34
+ throw new Error("Invalid original OTA entry metadata");
19
35
  } else if (!entry) {
20
- entry = '__platform_default__';
21
- } else if (typeof entry !== 'string' || entry.includes('ota-entry')) {
22
- throw new Error('Invalid application main entry');
23
- } else if (!entry.startsWith('.') && (fs.existsSync(path.join(appRoot, entry)) || ['android', 'ios', 'web'].some((platform) => hasEntry(appRoot, entry, platform)))) {
36
+ entry = "__platform_default__";
37
+ } else if (typeof entry !== "string" || entry.includes("ota-entry")) {
38
+ throw new Error("Invalid application main entry");
39
+ } else if (
40
+ !entry.startsWith(".") &&
41
+ (fs.existsSync(path.join(appRoot, entry)) ||
42
+ ["android", "ios", "web"].some((platform) =>
43
+ hasEntry(appRoot, entry, platform),
44
+ ))
45
+ ) {
24
46
  entry = `./${entry}`;
25
47
  }
26
48
  const heartbeatUrl = new URL(manifestUrl);
27
- heartbeatUrl.pathname = heartbeatUrl.pathname.replace(/\/manifest\/?$/, '/device-heartbeat');
28
- heartbeatUrl.search = '';
29
- heartbeatUrl.hash = '';
30
- const existingConfigPath = path.join(appRoot, 'ota-client/config.json');
31
- const existingConfig = fs.existsSync(existingConfigPath) ? JSON.parse(fs.readFileSync(existingConfigPath, 'utf8')) : {};
49
+ heartbeatUrl.pathname = heartbeatUrl.pathname.replace(
50
+ /\/manifest\/?$/,
51
+ "/device-heartbeat",
52
+ );
53
+ heartbeatUrl.search = "";
54
+ heartbeatUrl.hash = "";
55
+ const existingConfigPath = path.join(appRoot, "ota-client/config.json");
56
+ const existingConfig = fs.existsSync(existingConfigPath)
57
+ ? JSON.parse(fs.readFileSync(existingConfigPath, "utf8"))
58
+ : {};
32
59
  // Preserve the namespace when a tunnel URL changes; runtime/channel are deliberately excluded.
33
- const identityNamespace = existingConfig.identityNamespace || new URL(manifestUrl).origin;
60
+ const identityNamespace =
61
+ existingConfig.identityNamespace || new URL(manifestUrl).origin;
34
62
  const defaultEntries = [];
35
- if (entry === '__platform_default__') {
36
- for (const platform of ['android', 'ios', 'web']) {
37
- const source = hasEntry(appRoot, 'index', platform) ? 'require("./index");' : "require('expo').registerRootComponent(require('./App').default);";
38
- defaultEntries.push([`ota-original-entry.${platform}.js`, `// Generated default ${platform} entry.\n${source}\n`]);
63
+ if (entry === "__platform_default__") {
64
+ for (const platform of ["android", "ios", "web"]) {
65
+ const source = hasEntry(appRoot, "index", platform)
66
+ ? 'require("./index");'
67
+ : "require('expo').registerRootComponent(require('./App').default);";
68
+ defaultEntries.push([
69
+ `ota-original-entry.${platform}.js`,
70
+ `// Generated default ${platform} entry.\n${source}\n`,
71
+ ]);
39
72
  }
40
73
  }
41
- const original = entry === '__platform_default__' ? "require('./ota-original-entry');" : entry === '__app_fallback__'
42
- ? "require('expo').registerRootComponent(require('./App').default);"
43
- : `require(${JSON.stringify(entry)});`;
74
+ const original =
75
+ entry === "__platform_default__"
76
+ ? "require('./ota-original-entry');"
77
+ : entry === "__app_fallback__"
78
+ ? "require('expo').registerRootComponent(require('./App').default);"
79
+ : `require(${JSON.stringify(entry)});`;
44
80
  const rootHookPlan = planOtaRootHook({ appRoot, originalEntry: entry });
45
81
  const files = [
46
82
  ...defaultEntries,
47
- [ENTRY, `// Generated by configure-app. Original entry is preserved in ${META}.\nrequire('./ota-client').start();\n${original}\n`],
83
+ [
84
+ ENTRY,
85
+ `// Generated by configure-app. Original entry is preserved in ${META}.\nrequire('./ota-client/runtime').start();\n${original}\n`,
86
+ ],
48
87
  [META, `${JSON.stringify({ originalEntry: entry }, null, 2)}\n`],
49
- ['ota-client/config.json', `${JSON.stringify({ channel, heartbeatUrl: heartbeatUrl.toString(), identityNamespace }, null, 2)}\n`],
50
- ...['index.js', 'index.d.ts', 'runtime.js', 'controller.js', 'device-identity.js', 'model/update-controller.js', 'model/hooks/useOtaUpdates.js', 'ui/ota-update-gate.js', 'docs/update-lifecycle.md', 'README.md'].map((name) => [`ota-client/${name}`, fs.readFileSync(path.join(templateRoot, 'ota-client', name), 'utf8')]),
88
+ [
89
+ "ota-client/config.json",
90
+ `${JSON.stringify({ channel, heartbeatUrl: heartbeatUrl.toString(), identityNamespace }, null, 2)}\n`,
91
+ ],
92
+ ...[
93
+ "index.ts",
94
+ "types.ts",
95
+ "runtime.ts",
96
+ "controller.ts",
97
+ "device-identity.ts",
98
+ "model/update-controller.ts",
99
+ "model/hooks/useOtaUpdates.ts",
100
+ "ui/ota-updates.tsx",
101
+ "ui/ota-update-gate.tsx",
102
+ "docs/update-lifecycle.md",
103
+ "README.md",
104
+ ].map((name) => [
105
+ `ota-client/${name}`,
106
+ fs.readFileSync(path.join(templateRoot, "ota-client", name), "utf8"),
107
+ ]),
51
108
  ];
109
+ const obsolete = [
110
+ "index.js",
111
+ "index.d.ts",
112
+ "runtime.js",
113
+ "controller.js",
114
+ "device-identity.js",
115
+ "model/update-controller.js",
116
+ "model/hooks/useOtaUpdates.js",
117
+ "ui/ota-update-gate.js",
118
+ ]
119
+ .map((name) => path.join(appRoot, "ota-client", name))
120
+ .filter((file) => fs.existsSync(file));
121
+ if (obsolete.length && !force)
122
+ throw new Error(
123
+ "Refusing to replace the existing JavaScript OTA client. Review your customizations and rerun with --force to migrate to TypeScript.",
124
+ );
52
125
  for (const [name, content] of files) {
53
126
  const destination = path.join(appRoot, name);
54
- if (fs.existsSync(destination) && fs.readFileSync(destination, 'utf8') !== content && !force) {
55
- throw new Error(`Refusing to overwrite ${destination}. Re-run with --force.`);
127
+ if (
128
+ fs.existsSync(destination) &&
129
+ fs.readFileSync(destination, "utf8") !== content &&
130
+ !force
131
+ ) {
132
+ throw new Error(
133
+ `Refusing to overwrite ${destination}. Re-run with --force.`,
134
+ );
56
135
  }
57
136
  }
58
137
  return {
59
138
  warnings: rootHookPlan.warnings,
60
139
  apply() {
140
+ for (const file of obsolete) fs.rmSync(file);
61
141
  for (const [name, content] of [...files, ...rootHookPlan.files]) {
62
142
  const destination = path.join(appRoot, name);
63
143
  fs.mkdirSync(path.dirname(destination), { recursive: true });
64
144
  fs.writeFileSync(destination, content);
65
145
  }
66
146
  },
67
- patchPackage(packageJson) { return { ...packageJson, main: ENTRY }; },
147
+ patchPackage(packageJson) {
148
+ return { ...packageJson, main: ENTRY };
149
+ },
68
150
  };
69
151
  }
@@ -1,88 +1,237 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import os from 'node:os';
4
- import { afterEach, describe, expect, it } from 'vitest';
5
- import { planOtaClient } from './ota-client-configurator.mjs';
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { planOtaClient } from "./ota-client-configurator.mjs";
6
6
  const roots: string[] = [];
7
- afterEach(() => { for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true }); });
7
+ afterEach(() => {
8
+ for (const root of roots.splice(0))
9
+ fs.rmSync(root, { recursive: true, force: true });
10
+ });
8
11
  function setup(main?: string) {
9
- const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ota-entry-')); roots.push(appRoot);
10
- const options = { appRoot, templateRoot: path.resolve('templates/expo-app'), packageJson: main ? { main } : {}, manifestUrl: 'https://example.org/prefix/api/manifest', channel: 'test', force: false };
11
- return { options, entry: () => fs.readFileSync(path.join(appRoot, 'ota-entry.js'), 'utf8') };
12
+ const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), "ota-entry-"));
13
+ roots.push(appRoot);
14
+ const options = {
15
+ appRoot,
16
+ templateRoot: path.resolve("templates/expo-app"),
17
+ packageJson: main ? { main } : {},
18
+ manifestUrl: "https://example.org/prefix/api/manifest",
19
+ channel: "test",
20
+ force: false,
21
+ };
22
+ return {
23
+ options,
24
+ entry: () => fs.readFileSync(path.join(appRoot, "ota-entry.js"), "utf8"),
25
+ };
12
26
  }
13
- describe('configure-only bootstrap', () => {
14
- it('preserves Router entry across repeated configurations and keeps URL prefix', () => {
15
- const f = setup('expo-router/entry'); const plan = planOtaClient(f.options); plan.apply();
27
+ describe("configure-only bootstrap", () => {
28
+ it("migrates legacy JavaScript modules without leaving files that shadow TypeScript", () => {
29
+ const f = setup("expo-router/entry");
30
+ const legacy = [
31
+ "index.js",
32
+ "index.d.ts",
33
+ "runtime.js",
34
+ "controller.js",
35
+ "device-identity.js",
36
+ "model/update-controller.js",
37
+ "model/hooks/useOtaUpdates.js",
38
+ "ui/ota-update-gate.js",
39
+ ];
40
+ for (const name of legacy) {
41
+ const file = path.join(f.options.appRoot, "ota-client", name);
42
+ fs.mkdirSync(path.dirname(file), { recursive: true });
43
+ fs.writeFileSync(file, "// old customized client");
44
+ }
45
+ const layout = path.join(f.options.appRoot, "app/_layout.tsx");
46
+ fs.mkdirSync(path.dirname(layout), { recursive: true });
47
+ fs.writeFileSync(
48
+ layout,
49
+ `import { useOtaUpdates, OtaUpdateGate } from '../ota-client';
50
+ import { createElement } from 'react';
51
+ export default function Layout() {
52
+ const ota = useOtaUpdates({ autoCheck: true, autoUpdate: true });
53
+ return createElement(OtaUpdateGate, { controller: ota }, <AppTabs />);
54
+ }`,
55
+ );
56
+ expect(() => planOtaClient(f.options)).toThrow("Refusing");
57
+ expect(
58
+ fs.existsSync(path.join(f.options.appRoot, "ota-client/index.js")),
59
+ ).toBe(true);
60
+ planOtaClient({ ...f.options, force: true }).apply();
61
+ for (const name of legacy)
62
+ expect(
63
+ fs.existsSync(path.join(f.options.appRoot, "ota-client", name)),
64
+ ).toBe(false);
65
+ expect(
66
+ fs.existsSync(path.join(f.options.appRoot, "ota-client/index.ts")),
67
+ ).toBe(true);
68
+ const migrated = fs.readFileSync(layout, "utf8");
69
+ expect(migrated).toContain("<OtaUpdates");
70
+ expect(migrated).toContain("autoUpdate: true");
71
+ expect(migrated).not.toContain("createElement");
72
+ planOtaClient({
73
+ ...f.options,
74
+ packageJson: { main: "ota-entry.js" },
75
+ }).apply();
76
+ expect(fs.readFileSync(layout, "utf8")).toBe(migrated);
77
+ });
78
+ it("preserves Router entry across repeated configurations and keeps URL prefix", () => {
79
+ const f = setup("expo-router/entry");
80
+ const plan = planOtaClient(f.options);
81
+ plan.apply();
16
82
  expect(f.entry()).toContain('require("expo-router/entry")');
17
- planOtaClient({ ...f.options, packageJson: plan.patchPackage(f.options.packageJson) }).apply();
83
+ planOtaClient({
84
+ ...f.options,
85
+ packageJson: plan.patchPackage(f.options.packageJson),
86
+ }).apply();
18
87
  expect(f.entry()).toContain('require("expo-router/entry")');
19
- expect(JSON.parse(fs.readFileSync(path.join(f.options.appRoot, 'ota-client/config.json'), 'utf8')).heartbeatUrl).toBe('https://example.org/prefix/api/device-heartbeat');
88
+ expect(
89
+ JSON.parse(
90
+ fs.readFileSync(
91
+ path.join(f.options.appRoot, "ota-client/config.json"),
92
+ "utf8",
93
+ ),
94
+ ).heartbeatUrl,
95
+ ).toBe("https://example.org/prefix/api/device-heartbeat");
20
96
  });
21
- it('uses platform-aware root index when main is missing', () => {
22
- const f = setup(); fs.writeFileSync(path.join(f.options.appRoot, 'index.android.ts'), '');
23
- planOtaClient(f.options).apply(); expect(fs.readFileSync(path.join(f.options.appRoot, 'ota-original-entry.android.js'), 'utf8')).toContain('require("./index")');
24
- expect(fs.readFileSync(path.join(f.options.appRoot, 'ota-original-entry.ios.js'), 'utf8')).toContain("require('./App')");
97
+ it("uses platform-aware root index when main is missing", () => {
98
+ const f = setup();
99
+ fs.writeFileSync(path.join(f.options.appRoot, "index.android.ts"), "");
100
+ planOtaClient(f.options).apply();
101
+ expect(
102
+ fs.readFileSync(
103
+ path.join(f.options.appRoot, "ota-original-entry.android.js"),
104
+ "utf8",
105
+ ),
106
+ ).toContain('require("./index")');
107
+ expect(
108
+ fs.readFileSync(
109
+ path.join(f.options.appRoot, "ota-original-entry.ios.js"),
110
+ "utf8",
111
+ ),
112
+ ).toContain("require('./App')");
25
113
  });
26
- it('registers root App fallback without depending on hoisted expo/AppEntry', () => {
27
- const f = setup(); planOtaClient(f.options).apply(); expect(fs.readFileSync(path.join(f.options.appRoot, 'ota-original-entry.ios.js'), 'utf8')).toContain("registerRootComponent(require('./App').default)");
28
- planOtaClient({ ...f.options, packageJson: { main: 'ota-entry.js' } }).apply();
114
+ it("registers root App fallback without depending on hoisted expo/AppEntry", () => {
115
+ const f = setup();
116
+ planOtaClient(f.options).apply();
117
+ expect(
118
+ fs.readFileSync(
119
+ path.join(f.options.appRoot, "ota-original-entry.ios.js"),
120
+ "utf8",
121
+ ),
122
+ ).toContain("registerRootComponent(require('./App').default)");
123
+ planOtaClient({
124
+ ...f.options,
125
+ packageJson: { main: "ota-entry.js" },
126
+ }).apply();
29
127
  });
30
- it('resolves extensionless local main', () => {
31
- const f = setup('bootstrap'); fs.writeFileSync(path.join(f.options.appRoot, 'bootstrap.tsx'), '');
32
- planOtaClient(f.options).apply(); expect(f.entry()).toContain('require("./bootstrap")');
128
+ it("resolves extensionless local main", () => {
129
+ const f = setup("bootstrap");
130
+ fs.writeFileSync(path.join(f.options.appRoot, "bootstrap.tsx"), "");
131
+ planOtaClient(f.options).apply();
132
+ expect(f.entry()).toContain('require("./bootstrap")');
33
133
  });
34
- it('normalizes an existing local custom main and refuses edits without force', () => {
35
- const f = setup('entry.js'); fs.writeFileSync(path.join(f.options.appRoot, 'entry.js'), '');
36
- planOtaClient(f.options).apply(); expect(f.entry()).toContain('require("./entry.js")');
37
- fs.writeFileSync(path.join(f.options.appRoot, 'ota-client/index.js'), 'user changes');
38
- expect(() => planOtaClient({ ...f.options, packageJson: { main: 'ota-entry.js' } })).toThrow('Refusing');
134
+ it("normalizes an existing local custom main and refuses edits without force", () => {
135
+ const f = setup("entry.js");
136
+ fs.writeFileSync(path.join(f.options.appRoot, "entry.js"), "");
137
+ planOtaClient(f.options).apply();
138
+ expect(f.entry()).toContain('require("./entry.js")');
139
+ fs.writeFileSync(
140
+ path.join(f.options.appRoot, "ota-client/index.ts"),
141
+ "user changes",
142
+ );
143
+ expect(() =>
144
+ planOtaClient({ ...f.options, packageJson: { main: "ota-entry.js" } }),
145
+ ).toThrow("Refusing");
39
146
  });
40
- it('automatically starts the client, preserves namespace when URL/channel changes, and copies identity model', () => {
41
- const f = setup('expo-router/entry'); planOtaClient(f.options).apply();
42
- expect(f.entry().indexOf("require('./ota-client').start()")).toBeLessThan(f.entry().indexOf('require("expo-router/entry")'));
43
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-client/device-identity.js'))).toBe(true);
44
- planOtaClient({ ...f.options, packageJson: { main: 'ota-entry.js' }, manifestUrl: 'https://new-tunnel.example/api/manifest', channel: 'another', force: true }).apply();
45
- expect(JSON.parse(fs.readFileSync(path.join(f.options.appRoot, 'ota-client/config.json'), 'utf8')).identityNamespace).toBe('https://example.org');
147
+ it("automatically starts the client, preserves namespace when URL/channel changes, and copies identity model", () => {
148
+ const f = setup("expo-router/entry");
149
+ planOtaClient(f.options).apply();
150
+ expect(
151
+ f.entry().indexOf("require('./ota-client/runtime').start()"),
152
+ ).toBeLessThan(f.entry().indexOf('require("expo-router/entry")'));
153
+ expect(
154
+ fs.existsSync(
155
+ path.join(f.options.appRoot, "ota-client/device-identity.ts"),
156
+ ),
157
+ ).toBe(true);
158
+ planOtaClient({
159
+ ...f.options,
160
+ packageJson: { main: "ota-entry.js" },
161
+ manifestUrl: "https://new-tunnel.example/api/manifest",
162
+ channel: "another",
163
+ force: true,
164
+ }).apply();
165
+ expect(
166
+ JSON.parse(
167
+ fs.readFileSync(
168
+ path.join(f.options.appRoot, "ota-client/config.json"),
169
+ "utf8",
170
+ ),
171
+ ).identityNamespace,
172
+ ).toBe("https://example.org");
46
173
  });
47
174
 
48
- it('patches the Router layout without force and preserves custom hook modes on rerun', () => {
49
- const f = setup('expo-router/entry');
50
- const layout = path.join(f.options.appRoot, 'src/app/_layout.tsx');
175
+ it("patches the Router layout without force and preserves custom hook modes on rerun", () => {
176
+ const f = setup("expo-router/entry");
177
+ const layout = path.join(f.options.appRoot, "src/app/_layout.tsx");
51
178
  fs.mkdirSync(path.dirname(layout), { recursive: true });
52
- fs.writeFileSync(layout, 'export default function Root() { return null; }\n');
179
+ fs.writeFileSync(
180
+ layout,
181
+ "export default function Root() { return null; }\n",
182
+ );
53
183
  const plan = planOtaClient(f.options);
54
184
  expect(plan.warnings).toEqual([]);
55
185
  plan.apply();
56
- expect(fs.readFileSync(layout, 'utf8')).toContain('useOtaUpdates({ autoCheck: true');
57
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-client/model/hooks/useOtaUpdates.js'))).toBe(true);
58
- const customized = fs.readFileSync(layout, 'utf8').replace('autoCheck: true', 'autoCheck: false');
186
+ expect(fs.readFileSync(layout, "utf8")).toContain("<OtaUpdates autoCheck");
187
+ expect(
188
+ fs.existsSync(
189
+ path.join(f.options.appRoot, "ota-client/model/hooks/useOtaUpdates.ts"),
190
+ ),
191
+ ).toBe(true);
192
+ const customized = fs
193
+ .readFileSync(layout, "utf8")
194
+ .replace("autoUpdate={false}", "autoUpdate={true}");
59
195
  fs.writeFileSync(layout, customized);
60
- planOtaClient({ ...f.options, packageJson: plan.patchPackage(f.options.packageJson) }).apply();
61
- expect(fs.readFileSync(layout, 'utf8')).toBe(customized);
196
+ planOtaClient({
197
+ ...f.options,
198
+ packageJson: plan.patchPackage(f.options.packageJson),
199
+ }).apply();
200
+ expect(fs.readFileSync(layout, "utf8")).toBe(customized);
62
201
  });
63
202
 
64
- it('preflights an unsupported root without mutating application or generated files', () => {
65
- const f = setup('expo-router/entry');
66
- const layout = path.join(f.options.appRoot, 'app/_layout.tsx');
67
- const original = 'export default memo(() => null);\n';
203
+ it("preflights an unsupported root without mutating application or generated files", () => {
204
+ const f = setup("expo-router/entry");
205
+ const layout = path.join(f.options.appRoot, "app/_layout.tsx");
206
+ const original = "export default memo(() => null);\n";
68
207
  fs.mkdirSync(path.dirname(layout), { recursive: true });
69
208
  fs.writeFileSync(layout, original);
70
- expect(() => planOtaClient(f.options)).toThrow('unsupported default root');
71
- expect(fs.readFileSync(layout, 'utf8')).toBe(original);
72
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-entry.js'))).toBe(false);
73
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-client'))).toBe(false);
209
+ expect(() => planOtaClient(f.options)).toThrow("unsupported default root");
210
+ expect(fs.readFileSync(layout, "utf8")).toBe(original);
211
+ expect(fs.existsSync(path.join(f.options.appRoot, "ota-entry.js"))).toBe(
212
+ false,
213
+ );
214
+ expect(fs.existsSync(path.join(f.options.appRoot, "ota-client"))).toBe(
215
+ false,
216
+ );
74
217
  });
75
218
 
76
- it('preserves all files if an aliased existing OTA hook cannot be safely resolved', () => {
77
- const f = setup('expo-router/entry');
78
- const layout = path.join(f.options.appRoot, 'app/_layout.tsx');
79
- const original = "import { useOtaUpdates } from '@/ota-client'; export default function Root() { const ota = useOtaUpdates({ autoCheck: false }); return null; }\n";
219
+ it("preserves all files if an aliased existing OTA hook cannot be safely resolved", () => {
220
+ const f = setup("expo-router/entry");
221
+ const layout = path.join(f.options.appRoot, "app/_layout.tsx");
222
+ const original =
223
+ "import { useOtaUpdates } from '@/ota-client'; export default function Root() { const ota = useOtaUpdates({ autoCheck: false }); return null; }\n";
80
224
  fs.mkdirSync(path.dirname(layout), { recursive: true });
81
225
  fs.writeFileSync(layout, original);
82
- expect(() => planOtaClient(f.options)).toThrow('use a relative import to ota-client');
83
- expect(fs.readFileSync(layout, 'utf8')).toBe(original);
84
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-entry.js'))).toBe(false);
85
- expect(fs.existsSync(path.join(f.options.appRoot, 'ota-client'))).toBe(false);
226
+ expect(() => planOtaClient(f.options)).toThrow(
227
+ "use a relative import to ota-client",
228
+ );
229
+ expect(fs.readFileSync(layout, "utf8")).toBe(original);
230
+ expect(fs.existsSync(path.join(f.options.appRoot, "ota-entry.js"))).toBe(
231
+ false,
232
+ );
233
+ expect(fs.existsSync(path.join(f.options.appRoot, "ota-client"))).toBe(
234
+ false,
235
+ );
86
236
  });
87
-
88
237
  });
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
- import { createInstallationClient } from '../../templates/expo-app/ota-client/controller.js';
2
+ import { createInstallationClient } from '../../templates/expo-app/ota-client/controller';
3
3
  function fixture() {
4
4
  let stored: string | null = null;
5
5
  let counter = 0;