create-expo-updates-server 0.2.0 → 0.3.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 (45) hide show
  1. package/dist/template/Dockerfile +5 -0
  2. package/dist/template/docker/minio.Dockerfile +11 -0
  3. package/dist/template/docker-compose.yml +7 -9
  4. package/dist/template/docs/expo-app-setup.md +8 -12
  5. package/dist/template/docs/getting-started.md +9 -5
  6. package/dist/template/docs/getting-started.ru.md +9 -7
  7. package/dist/template/docs/ota-client-lifecycle.md +46 -42
  8. package/dist/template/package-lock.json +589 -0
  9. package/dist/template/package.json +1 -0
  10. package/dist/template/scripts/ensure-storage-bucket.mjs +25 -0
  11. package/dist/template/scripts/lib/device-identity.test.ts +2 -2
  12. package/dist/template/scripts/lib/doctor.mjs +3 -3
  13. package/dist/template/scripts/lib/doctor.test.mjs +1 -1
  14. package/dist/template/scripts/lib/ota-client-configurator.mjs +116 -34
  15. package/dist/template/scripts/lib/ota-client-configurator.test.ts +210 -61
  16. package/dist/template/scripts/lib/ota-client.test.ts +1 -1
  17. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +435 -118
  18. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +243 -86
  19. package/dist/template/scripts/lib/ota-update-controller.test.ts +10 -9
  20. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +154 -0
  21. package/dist/template/scripts/tests/fixtures/react-native-ui.tsx +34 -0
  22. package/dist/template/scripts/tests/ota-client-types.mjs +69 -0
  23. package/dist/template/templates/expo-app/ota-client/README.md +16 -2
  24. package/dist/template/templates/expo-app/ota-client/controller.ts +107 -0
  25. package/dist/template/templates/expo-app/ota-client/device-identity.ts +48 -0
  26. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +18 -9
  27. package/dist/template/templates/expo-app/ota-client/index.ts +16 -0
  28. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +97 -0
  29. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +293 -0
  30. package/dist/template/templates/expo-app/ota-client/runtime.ts +153 -0
  31. package/dist/template/templates/expo-app/ota-client/types.ts +85 -0
  32. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +25 -0
  33. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +196 -0
  34. package/dist/template/tsconfig.json +3 -1
  35. package/dist/template/vitest.config.mts +3 -0
  36. package/dist/template-manifest.json +99 -69
  37. package/package.json +1 -1
  38. package/dist/template/templates/expo-app/ota-client/controller.js +0 -60
  39. package/dist/template/templates/expo-app/ota-client/device-identity.js +0 -26
  40. package/dist/template/templates/expo-app/ota-client/index.d.ts +0 -47
  41. package/dist/template/templates/expo-app/ota-client/index.js +0 -3
  42. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +0 -48
  43. package/dist/template/templates/expo-app/ota-client/model/update-controller.js +0 -182
  44. package/dist/template/templates/expo-app/ota-client/runtime.js +0 -112
  45. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +0 -56
@@ -1,123 +1,280 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import os from 'node:os';
4
- import ts from 'typescript';
5
- import { afterEach, describe, expect, it } from 'vitest';
6
- import { patchOtaRootHook, planOtaRootHook } from './ota-root-hook-patcher.mjs';
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+ import ts from "typescript";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { patchOtaRootHook, planOtaRootHook } from "./ota-root-hook-patcher.mjs";
7
7
 
8
8
  const roots: string[] = [];
9
- afterEach(() => { for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true }); });
10
- const root = '/example';
11
- const filename = '/example/src/app/_layout.tsx';
12
- function patch(source: string, file = filename) { return patchOtaRootHook(source, file, root); }
9
+ afterEach(() => {
10
+ for (const root of roots.splice(0))
11
+ fs.rmSync(root, { recursive: true, force: true });
12
+ });
13
+ const root = "/example";
14
+ const filename = "/example/src/app/_layout.tsx";
15
+ function patch(source: string, file = filename) {
16
+ return patchOtaRootHook(source, file, root);
17
+ }
13
18
  function assertValid(source: string, file = filename) {
14
- const result = ts.transpileModule(source, { fileName: file, reportDiagnostics: true, compilerOptions: { jsx: ts.JsxEmit.ReactJSX, target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext } });
19
+ const result = ts.transpileModule(source, {
20
+ fileName: file,
21
+ reportDiagnostics: true,
22
+ compilerOptions: {
23
+ jsx: ts.JsxEmit.ReactJSX,
24
+ target: ts.ScriptTarget.ES2022,
25
+ module: ts.ModuleKind.ESNext,
26
+ },
27
+ });
15
28
  expect(result.diagnostics).toEqual([]);
16
29
  }
17
- describe('root update hook patch', () => {
18
- it('preserves directives, comments, custom options and conditional returns on rerun', () => {
19
- const source = `'use client';\n// Header\nimport { Stack } from 'expo-router';\n// Component\nexport default function Layout() {\n // Keep this check.\n if (loading) return null;\n return <Stack />;\n}\n`;
30
+ describe("root OTA component patch", () => {
31
+ it.each([
32
+ "undefined",
33
+ "{ autoCheck: undefined }",
34
+ "{ autoCheck: false }",
35
+ "{ autoCheck: true }",
36
+ ])("preserves legacy defaults with type-safe options: %s", (options) => {
37
+ const source = `import { useOtaUpdates } from '../../ota-client';
38
+ export default function Layout() { useOtaUpdates(${options}); return null; }`;
20
39
  const result = patch(source);
21
- expect(result.startsWith("'use client';\n// Header\n")).toBe(true);
22
- expect(result).toContain('// Component\nexport default function Layout()');
40
+ expect(result).toContain("autoCheck={otaAutoCheck}");
41
+ expect(patch(result)).toBe(result);
42
+ const directory = fs.mkdtempSync(
43
+ path.join(os.tmpdir(), "ota-migration-types-"),
44
+ );
45
+ roots.push(directory);
46
+ const layout = path.join(directory, "src/app/_layout.tsx");
47
+ fs.mkdirSync(path.dirname(layout), { recursive: true });
48
+ fs.mkdirSync(path.join(directory, "ota-client"));
49
+ fs.writeFileSync(layout, result);
50
+ fs.writeFileSync(
51
+ path.join(directory, "ota-client/index.ts"),
52
+ "export function OtaUpdates(props: { autoCheck?: boolean; autoUpdate?: boolean; autoReload?: boolean }) { return null; }",
53
+ );
54
+ const program = ts.createProgram([layout], {
55
+ noEmit: true,
56
+ strict: true,
57
+ skipLibCheck: true,
58
+ jsx: ts.JsxEmit.Preserve,
59
+ target: ts.ScriptTarget.ES2022,
60
+ module: ts.ModuleKind.ESNext,
61
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
62
+ types: [],
63
+ });
64
+ expect(
65
+ ts
66
+ .getPreEmitDiagnostics(program)
67
+ .map((diagnostic) =>
68
+ ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
69
+ ),
70
+ ).toEqual([]);
71
+ });
72
+ it("evaluates dynamic legacy options only once and preserves undefined autoCheck", () => {
73
+ const result = patch(`import { useOtaUpdates } from '../../ota-client';
74
+ export default function Layout() { useOtaUpdates(getOptions()); return null; }`);
75
+ expect(result.match(/getOptions\(\)/g)).toHaveLength(1);
76
+ expect(result).toContain("autoCheck: otaAutoCheck = false, ...otaOptions");
77
+ expect(result).toContain("autoCheck={otaAutoCheck}");
78
+ expect(patch(result)).toBe(result);
79
+ });
80
+ it.each([
81
+ "ready && <OtaUpdates autoCheck={false} />",
82
+ "ready ? <OtaUpdates /> : null",
83
+ "items.map(() => <OtaUpdates />)",
84
+ ])(
85
+ "refuses to duplicate an existing conditional component: %s",
86
+ (expression) => {
87
+ expect(() =>
88
+ patch(`import { OtaUpdates } from '../../ota-client';
89
+ export default () => <>{${expression}}</>;`),
90
+ ).toThrow("conditional or nested");
91
+ },
92
+ );
93
+ it("normalizes a retained legacy JS entry import before the JS file is removed", () => {
94
+ const result =
95
+ patch(`import { useOtaUpdates, OtaUpdateGate, getInstallationId } from '../../ota-client/index.js';
96
+ import { createElement } from 'react';
97
+ export default function Layout() {
98
+ const ota = useOtaUpdates({ autoCheck: true });
99
+ void getInstallationId();
100
+ return createElement(OtaUpdateGate, { controller: ota }, null);
101
+ }`);
102
+ expect(result).not.toContain("index.js");
103
+ expect(result).toContain(
104
+ "import { getInstallationId } from '../../ota-client';",
105
+ );
106
+ expect(patch(result)).toBe(result);
107
+ });
108
+ it("renders JSX siblings, preserves comments and is idempotent with custom props", () => {
109
+ const source = `'use client';\n// Header\nimport { Stack } from 'expo-router';\nexport default function Layout() {\n // Keep this check.\n if (loading) return null;\n return <Stack />;\n}\n`;
110
+ const result = patch(source);
111
+ expect(result).toContain("'use client';");
112
+ expect(result).toContain("// Keep this check.");
23
113
  expect(result).toContain("from '../../ota-client'");
24
- expect(result).toContain('const otaUpdates = useOtaUpdates({ autoCheck: true, autoUpdate: false, autoReload: false });');
25
- expect(result).toContain('if (loading) return createElement(OtaUpdateGate, { controller: otaUpdates }, null)');
26
- expect(result).toContain('return createElement(OtaUpdateGate, { controller: otaUpdates }, <Stack />)');
27
- expect(result).toContain('// Keep this check.');
28
- const customized = result.replace('autoCheck: true', 'autoCheck: false');
29
- expect(patch(customized)).toBe(customized);
114
+ expect(result.match(/<OtaUpdates /g)).toHaveLength(2);
115
+ expect(result).toContain("autoCheck autoUpdate={false} autoReload={false}");
116
+ expect(result).not.toContain("createElement");
117
+ expect(result).not.toContain("useOtaUpdates");
118
+ expect(result).toContain(" <Stack />");
119
+ const custom = result.replaceAll("autoUpdate={false}", "autoUpdate={true}");
120
+ expect(patch(custom)).toBe(custom);
30
121
  assertValid(result);
31
122
  });
32
123
  it.each([
33
- 'const Layout = () => (<Stack />); export default Layout;',
34
- 'export default () => <Stack />;',
35
- 'export default function () { return <Stack />; }',
36
- 'function Layout() { return <Stack />; } export default Layout;',
37
- 'const Layout = function() { return <Stack />; }; export default Layout;',
38
- 'const Layout = (() => <Stack />) satisfies ComponentType; export default Layout;',
39
- ])('supports a synchronous root shape: %s', (source) => {
124
+ "const Layout = () => (<Stack />); export default Layout;",
125
+ "export default () => <Stack />;",
126
+ "export default function () { return <Stack />; }",
127
+ "function Layout() { return <Stack />; } export default Layout;",
128
+ "const Layout = function() { return <Stack />; }; export default Layout;",
129
+ "const Layout = (() => <Stack />) satisfies ComponentType; export default Layout;",
130
+ ])("supports synchronous root: %s", (source) => {
40
131
  const result = patch(source);
41
- expect(result).toContain('useOtaUpdates({');
42
- expect(result).toContain('createElement(OtaUpdateGate,');
132
+ expect(result).toContain("<OtaUpdates ");
43
133
  expect(patch(result)).toBe(result);
44
134
  assertValid(result);
45
135
  });
46
- it('leaves nested render callbacks alone and preserves all root early returns', () => {
47
- const result = patch('export default function Layout() { const render = () => { return <Text />; }; if (ready) return <Stack render={render} />; return null; }');
48
- expect(result).toContain('const render = () => { return <Text />; }');
49
- expect(result.match(/createElement\(OtaUpdateGate/g)).toHaveLength(2);
136
+ it("does not inject into nested render callbacks and handles bare returns", () => {
137
+ const result = patch(
138
+ "export default function Root() { const render = () => { return <Text />; }; if (loading) return; return <Stack render={render} />; }",
139
+ );
140
+ expect(result.match(/<OtaUpdates /g)).toHaveLength(2);
50
141
  assertValid(result);
51
142
  });
52
- it('uses alias imports and keeps the existing hook configuration', () => {
53
- const result = patch("import { useOtaUpdates as useUpdates, OtaUpdateGate as Gate } from '../../ota-client';\nimport { createElement as el } from 'react';\nexport default function Root() { const updates = useUpdates({ autoCheck: false, autoReload: true }); return <Stack/>; }");
54
- expect(result.match(/useUpdates\(/g)).toHaveLength(1);
55
- expect(result).toContain('const updates = useUpdates({ autoCheck: false, autoReload: true });');
56
- expect(result).toContain('return el(Gate, { controller: updates }, <Stack/>)');
143
+ it("migrates the released createElement gate and preserves hook options", () => {
144
+ const source = `import { useOtaUpdates as useUpdates, OtaUpdateGate as Gate } from '../../ota-client';
145
+ import { createElement as el } from 'react';
146
+ export default function Root() {
147
+ const ota = useUpdates({ autoCheck: false, autoUpdate: true, autoReload: true, guardHandlers });
148
+ if (loading) return el(Gate, { controller: ota }, null);
149
+ return el(Gate, { controller: ota }, <Stack />);
150
+ }`;
151
+ const result = patch(source);
152
+ expect(result).not.toContain("useUpdates");
153
+ expect(result).not.toContain("createElement");
154
+ expect(result).not.toContain("OtaUpdateGate");
155
+ expect(result).toContain("autoUpdate: true");
156
+ expect(result).toContain("guardHandlers");
157
+ expect(result.match(/<OtaUpdates /g)).toHaveLength(2);
57
158
  expect(patch(result)).toBe(result);
58
159
  assertValid(result);
59
160
  });
60
- it('upgrades an existing unassigned top-level hook to provide the gate controller', () => {
61
- const result = patch("import { useOtaUpdates } from '../../ota-client';\nexport default function Root() { useOtaUpdates({ autoCheck: false }); return null; }");
62
- expect(result).toContain('const otaUpdates = useOtaUpdates({ autoCheck: false });');
63
- expect(result).toContain('controller: otaUpdates');
161
+ it("migrates a JSX gate without dropping its original children", () => {
162
+ const result =
163
+ patch(`import { useOtaUpdates, OtaUpdateGate } from '../../ota-client';
164
+ export default function Root() {
165
+ const ota = useOtaUpdates({ autoCheck: false });
166
+ return <OtaUpdateGate controller={ota}><Stack /><StatusBar /></OtaUpdateGate>;
167
+ }`);
168
+ expect(result).toContain("<Stack");
169
+ expect(result).toContain("<StatusBar");
170
+ expect(result).not.toContain("OtaUpdateGate");
64
171
  expect(patch(result)).toBe(result);
172
+ assertValid(result);
173
+ });
174
+ it("preserves React createElement when unrelated application code still uses it", () => {
175
+ const result = patch(`import { createElement } from 'react';
176
+ export default function Root() { return createElement(AppTabs); }`);
177
+ expect(result).toContain("import { createElement } from 'react'");
178
+ expect(result).toContain("{createElement(AppTabs)}");
179
+ assertValid(result);
65
180
  });
66
- it('rejects an unresolved import alias instead of installing a competing default hook', () => {
67
- const source = "import { useOtaUpdates as useUpdates } from '@/ota-client';\nexport default function Root() { const updates = useUpdates({ autoCheck: false }); return null; }";
68
- expect(() => patch(source)).toThrow('use a relative import to ota-client');
181
+ it("supports an aliased existing component without adding a second instance", () => {
182
+ const source = `import { OtaUpdates as Updates } from '../../ota-client';
183
+ export default () => <><Updates autoUpdate /><Stack /></>;`;
184
+ expect(patch(source)).toBe(source);
69
185
  });
70
- it('avoids collisions with local names and supports non-JSX TS App roots', () => {
71
- const result = patch('const useOtaUpdates = 1; const OtaUpdateGate = 2; const createElement = 3; const otaUpdates = 4; export default function App() { return null; }', '/example/App.ts');
72
- expect(result).toContain("import { useOtaUpdates as useOtaUpdates2, OtaUpdateGate as OtaUpdateGate2 } from './ota-client';");
73
- expect(result).toContain('const otaUpdates2 = useOtaUpdates2(');
74
- expect(result).toContain('return createElement2(OtaUpdateGate2,');
75
- assertValid(result, '/example/App.ts');
186
+ it("avoids collisions with local component names", () => {
187
+ const result = patch(
188
+ "const OtaUpdates = 1; export default () => <Stack/>;",
189
+ );
190
+ expect(result).toContain("OtaUpdates as OtaUpdates2");
191
+ expect(result).toContain("<OtaUpdates2 ");
192
+ assertValid(result);
76
193
  });
77
194
  it.each([
78
- 'export default memo(() => <Stack/>);',
79
- 'export default class Root { render() { return null; } }',
80
- 'export default async function Root() { return null; }',
81
- 'export default function* Root() { return null; }',
195
+ "export default memo(() => <Stack/>);",
196
+ "export default class Root { render() { return null; } }",
197
+ "export default async function Root() { return null; }",
198
+ "export default function* Root() { return null; }",
82
199
  "export { default } from './Root';",
83
- 'export default function Root( { return null;',
200
+ "export default function Root( { return null;",
84
201
  "import { useOtaUpdates } from '../../ota-client'; export default function Root() { if (ready) useOtaUpdates(); return null; }",
85
202
  "import { useOtaUpdates } from '../../ota-client'; export default function Root() { if (loading) return null; const updates = useOtaUpdates(); return null; }",
86
- "import { useOtaUpdates } from '../../ota-client'; export default function Root(useOtaUpdates) { return null; }",
87
- "import { OtaUpdateGate } from '../../ota-client'; export default function Root() { const OtaUpdateGate = CustomGate; return null; }",
88
- ])('rejects an unsafe root before patching: %s', (source) => {
89
- expect(() => patch(source)).toThrow('Cannot automatically connect');
203
+ "import { OtaUpdates } from '../../ota-client'; export default function Root(OtaUpdates) { return null; }",
204
+ "import { useOtaUpdates } from '@/ota-client'; export default function Root() { useOtaUpdates(); return null; }",
205
+ "import { useOtaUpdates } from '../../ota-client'; export default function Root() { useOtaUpdates(...options); return null; }",
206
+ "import { useOtaUpdates, OtaUpdateGate } from '../../ota-client'; export default function Root() { const ota = useOtaUpdates(); return <OtaUpdateGate controller={ota}><Text>{ota.status}</Text></OtaUpdateGate>; }",
207
+ ])("rejects an unsafe root before changing it: %s", (source) => {
208
+ expect(() => patch(source)).toThrow("Cannot automatically connect");
209
+ });
210
+ it("requires a TSX extension instead of emitting JSX into a .ts file", () => {
211
+ expect(() =>
212
+ patch("export default () => null;", "/example/App.ts"),
213
+ ).toThrow("rename the root to .tsx");
90
214
  });
91
- it('preserves CRLF and function directives', () => {
92
- const result = patch('export default function Root() {\r\n "use strict";\r\n return null;\r\n}\r\n');
93
- expect(result).toContain('"use strict";\r\n const otaUpdates');
94
- expect(result.replaceAll('\r\n', '')).not.toContain('\n');
215
+ it("preserves CRLF and directives", () => {
216
+ const result = patch(
217
+ 'export default function Root() {\r\n "use strict";\r\n return null;\r\n}\r\n',
218
+ );
219
+ expect(result).toContain('"use strict";');
220
+ expect(result.replaceAll("\r\n", "")).not.toContain("\n");
221
+ expect(patch(result)).toBe(result);
95
222
  });
96
223
  });
97
224
 
98
- describe('root selection', () => {
225
+ describe("root selection", () => {
99
226
  function fixture(files: Record<string, string>) {
100
- const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ota-root-hook-')); roots.push(appRoot);
101
- for (const [name, source] of Object.entries(files)) { fs.mkdirSync(path.dirname(path.join(appRoot, name)), { recursive: true }); fs.writeFileSync(path.join(appRoot, name), source); }
227
+ const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), "ota-root-hook-"));
228
+ roots.push(appRoot);
229
+ for (const [name, source] of Object.entries(files)) {
230
+ fs.mkdirSync(path.dirname(path.join(appRoot, name)), { recursive: true });
231
+ fs.writeFileSync(path.join(appRoot, name), source);
232
+ }
102
233
  return appRoot;
103
234
  }
104
- const component = 'export default function Root() { return null; }';
105
- it('prefers src/app and patches all its platform roots only', () => {
106
- const appRoot = fixture({ 'src/app/_layout.tsx': component, 'src/app/_layout.ios.tsx': component, 'app/_layout.tsx': 'unsupported' });
107
- const result = planOtaRootHook({ appRoot, originalEntry: 'expo-router/entry' });
108
- expect(result.files.map((file: string[]) => file[0])).toEqual(['src/app/_layout.tsx', 'src/app/_layout.ios.tsx']);
235
+ const component = "export default function Root() { return null; }";
236
+ it("prefers src/app and patches all its platform roots only", () => {
237
+ const appRoot = fixture({
238
+ "src/app/_layout.tsx": component,
239
+ "src/app/_layout.ios.tsx": component,
240
+ "app/_layout.tsx": "unsupported",
241
+ });
242
+ const result = planOtaRootHook({
243
+ appRoot,
244
+ originalEntry: "expo-router/entry",
245
+ });
246
+ expect(result.files.map((file: string[]) => file[0])).toEqual([
247
+ "src/app/_layout.tsx",
248
+ "src/app/_layout.ios.tsx",
249
+ ]);
109
250
  expect(result.warnings).toEqual([]);
110
- expect(fs.readFileSync(path.join(appRoot, 'src/app/_layout.tsx'), 'utf8')).toBe(component);
111
- });
112
- it('supports standard App fallback and warns for unknown custom entry', () => {
113
- const appRoot = fixture({ 'App.tsx': component });
114
- expect(planOtaRootHook({ appRoot, originalEntry: '__platform_default__' }).files).toHaveLength(1);
115
- expect(planOtaRootHook({ appRoot, originalEntry: './entry.js' }).warnings).toHaveLength(1);
116
- fs.writeFileSync(path.join(appRoot, 'index.android.js'), 'custom registration');
117
- expect(planOtaRootHook({ appRoot, originalEntry: '__platform_default__' }).files).toHaveLength(0);
118
- });
119
- it('does not patch ignored app root when src/app exists without a layout', () => {
120
- const appRoot = fixture({ 'src/app/index.tsx': component, 'app/_layout.tsx': component });
121
- expect(planOtaRootHook({ appRoot, originalEntry: 'expo-router/entry' }).warnings).toHaveLength(1);
251
+ expect(
252
+ fs.readFileSync(path.join(appRoot, "src/app/_layout.tsx"), "utf8"),
253
+ ).toBe(component);
254
+ });
255
+ it("supports standard App fallback and warns for unknown custom entry", () => {
256
+ const appRoot = fixture({ "App.tsx": component });
257
+ expect(
258
+ planOtaRootHook({ appRoot, originalEntry: "__platform_default__" }).files,
259
+ ).toHaveLength(1);
260
+ expect(
261
+ planOtaRootHook({ appRoot, originalEntry: "./entry.js" }).warnings,
262
+ ).toHaveLength(1);
263
+ fs.writeFileSync(
264
+ path.join(appRoot, "index.android.js"),
265
+ "custom registration",
266
+ );
267
+ expect(
268
+ planOtaRootHook({ appRoot, originalEntry: "__platform_default__" }).files,
269
+ ).toHaveLength(0);
270
+ });
271
+ it("does not patch ignored app root when src/app exists without a layout", () => {
272
+ const appRoot = fixture({
273
+ "src/app/index.tsx": component,
274
+ "app/_layout.tsx": component,
275
+ });
276
+ expect(
277
+ planOtaRootHook({ appRoot, originalEntry: "expo-router/entry" }).warnings,
278
+ ).toHaveLength(1);
122
279
  });
123
280
  });
@@ -1,5 +1,6 @@
1
+ import type { OtaCheckResult, OtaFetchResult, OtaOptions } from '../../templates/expo-app/ota-client/types';
1
2
  import { describe, expect, it, vi } from 'vitest';
2
- import { createUpdateController } from '../../templates/expo-app/ota-client/model/update-controller.js';
3
+ import { createUpdateController } from '../../templates/expo-app/ota-client/model/update-controller';
3
4
 
4
5
  function manifest(id = 'update-a', delivery = 'manual', action?: string) {
5
6
  return { id, extra: { updatePolicy: { schemaVersion: 1, policyVersion: 1, delivery,
@@ -10,14 +11,14 @@ function fixture() {
10
11
  const deps = {
11
12
  enabled: true, start: vi.fn(),
12
13
  identity: vi.fn(async () => ({ installationId: 'installation', deviceId: 'device' })),
13
- check: vi.fn(async (): Promise<unknown> => ({ isAvailable: true, manifest: manifest() })),
14
- fetch: vi.fn(async (): Promise<unknown> => ({ isNew: true, manifest: manifest() })),
14
+ check: vi.fn(async (): Promise<OtaCheckResult> => ({ isAvailable: true, manifest: manifest() })),
15
+ fetch: vi.fn(async (): Promise<OtaFetchResult> => ({ isNew: true, manifest: manifest() })),
15
16
  reload: vi.fn(async () => undefined), openStore: vi.fn(async () => undefined),
16
17
  isActive: vi.fn(() => true), now: () => clock,
17
18
  };
18
19
  const client = createUpdateController(deps);
19
20
  const owner = Symbol('root');
20
- const configure = (value: Record<string, unknown> = {}) => client.configure(owner, value);
21
+ const configure = (value: OtaOptions = {}) => client.configure(owner, value);
21
22
  return { deps, client, configure, owner, advance: () => { clock += 60000; } };
22
23
  }
23
24
  function deferred<T>() {
@@ -108,7 +109,7 @@ describe('OTA lifecycle policy and operations', () => {
108
109
  f.deps.check.mockResolvedValue({ isAvailable: true, manifest: manifest('custom', 'manual', 'login') });
109
110
  await f.client.check();
110
111
  expect(f.client.getSnapshot()).toMatchObject({ blocked: true }); expect(f.deps.fetch).not.toHaveBeenCalled();
111
- const decision = deferred<string>();
112
+ const decision = deferred<"allow" | "block">();
112
113
  f.configure({ guardHandlers: { login: () => decision.promise } });
113
114
  const checking = f.client.retry();
114
115
  await vi.waitFor(() => expect(f.deps.check).toHaveBeenCalledTimes(2));
@@ -139,7 +140,7 @@ describe('OTA lifecycle policy and operations', () => {
139
140
  await f.client.retry(); expect(f.deps.identity).toHaveBeenCalledTimes(2); expect(f.deps.check).toHaveBeenCalledOnce();
140
141
  });
141
142
  it('single-flights identical operations and rejects conflicting operations', async () => {
142
- const f = fixture(); const response = deferred<unknown>(); f.deps.check.mockReturnValue(response.promise);
143
+ const f = fixture(); const response = deferred<OtaCheckResult>(); f.deps.check.mockReturnValue(response.promise);
143
144
  const first = f.client.check(); const second = f.client.check();
144
145
  expect(first).toBe(second);
145
146
  await expect(f.client.download()).rejects.toThrow('in progress');
@@ -180,13 +181,13 @@ describe('OTA lifecycle policy and operations', () => {
180
181
  it('re-evaluates a pending guard on retry after application conditions change', async () => {
181
182
  const f = fixture();
182
183
  await f.client.syncPending({ type: 'new', manifest: manifest('cached', 'manual', 'login') });
183
- f.configure({ guardHandlers: { login: async () => 'allow' } });
184
+ f.configure({ guardHandlers: { login: async () => 'allow' as const } });
184
185
  await f.client.retry();
185
186
  expect(f.client.getSnapshot()).toMatchObject({ candidate: { manifest: { id: 'cached' } }, pending: true, blocked: false });
186
187
  });
187
188
  it('ignores an old native pending snapshot queued while a newer download completes', async () => {
188
189
  const f = fixture(); await f.client.check();
189
- const fetched = deferred<unknown>(); f.deps.fetch.mockReturnValue(fetched.promise);
190
+ const fetched = deferred<OtaFetchResult>(); f.deps.fetch.mockReturnValue(fetched.promise);
190
191
  const downloading = f.client.download();
191
192
  await vi.waitFor(() => expect(f.deps.fetch).toHaveBeenCalledOnce());
192
193
  const syncing = f.client.syncPending({ type: 'new', manifest: manifest('old') });
@@ -222,7 +223,7 @@ describe('OTA lifecycle policy and operations', () => {
222
223
  const f = fixture(); f.deps.check.mockResolvedValue({ isAvailable: false });
223
224
  const client = createUpdateController({ ...f.deps, runningCandidate: () => ({ type: 'new', manifest: manifest('running', 'manual', 'login') }) });
224
225
  await client.initialize(); expect(client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'login' });
225
- const handler = vi.fn(async () => 'allow');
226
+ const handler = vi.fn(async () => 'allow' as const);
226
227
  client.configure(f.owner, { guardHandlers: { login: handler } });
227
228
  await client.check();
228
229
  expect(handler).toHaveBeenCalledWith(expect.objectContaining({ action: 'login', manifest: expect.objectContaining({ id: 'running' }) }));
@@ -0,0 +1,154 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
+ import type { OtaController } from "../../templates/expo-app/ota-client/types";
6
+ import { OtaUpdates } from "../../templates/expo-app/ota-client/ui/ota-updates";
7
+
8
+ const mocked = vi.hoisted(() => ({ hook: vi.fn() }));
9
+ vi.mock(
10
+ "../../templates/expo-app/ota-client/model/hooks/useOtaUpdates",
11
+ () => ({ useOtaUpdates: mocked.hook }),
12
+ );
13
+
14
+ let root: Root;
15
+ let container: HTMLDivElement;
16
+ let controller: OtaController;
17
+ beforeEach(() => {
18
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
19
+ container = document.createElement("div");
20
+ document.body.append(container);
21
+ root = createRoot(container);
22
+ controller = {
23
+ enabled: true,
24
+ status: "idle",
25
+ installationId: "installation",
26
+ deviceId: "device",
27
+ available: true,
28
+ pending: false,
29
+ candidate: { type: "new", manifest: { id: "a" } },
30
+ policy: { schemaVersion: 1, delivery: "manual" },
31
+ blocked: false,
32
+ blockReason: null,
33
+ error: null,
34
+ isBusy: false,
35
+ check: vi.fn(async () => ({ isAvailable: true })),
36
+ download: vi.fn(async () => ({ isNew: true })),
37
+ reload: vi.fn(async () => {}),
38
+ retry: vi.fn(async () => ({ isAvailable: true })),
39
+ openStore: vi.fn(async () => {}),
40
+ };
41
+ mocked.hook.mockImplementation(() => controller);
42
+ });
43
+ afterEach(async () => {
44
+ await act(async () => root.unmount());
45
+ container.remove();
46
+ vi.clearAllMocks();
47
+ });
48
+ async function render() {
49
+ await act(async () =>
50
+ root.render(
51
+ <>
52
+ <div>Application tabs</div>
53
+ <OtaUpdates />
54
+ </>,
55
+ ),
56
+ );
57
+ }
58
+ async function click(label: string) {
59
+ const button = [...container.querySelectorAll("button")].find(
60
+ (element) => element.textContent === label,
61
+ );
62
+ expect(button).toBeDefined();
63
+ await act(async () => button!.click());
64
+ }
65
+ describe("standalone OTA updates UI", () => {
66
+ it("offers manual download with autoUpdate false, then restart, without wrapping navigation", async () => {
67
+ await render();
68
+ expect(mocked.hook).toHaveBeenCalledWith(
69
+ expect.objectContaining({
70
+ autoCheck: true,
71
+ autoUpdate: false,
72
+ autoReload: false,
73
+ }),
74
+ );
75
+ expect(container.textContent).toContain("Update available");
76
+ expect(container.querySelector("[role=dialog]")?.textContent).not.toContain(
77
+ "Application tabs",
78
+ );
79
+ await click("Download");
80
+ expect(controller.download).toHaveBeenCalledOnce();
81
+ controller = { ...controller, pending: true };
82
+ await render();
83
+ await click("Restart");
84
+ expect(controller.reload).toHaveBeenCalledOnce();
85
+ });
86
+ it("dismisses an optional candidate until another candidate arrives", async () => {
87
+ await render();
88
+ await click("Later");
89
+ expect(container.querySelector("[role=dialog]")).toBeNull();
90
+ await render();
91
+ expect(container.querySelector("[role=dialog]")).toBeNull();
92
+ controller = {
93
+ ...controller,
94
+ candidate: { type: "new", manifest: { id: "b" } },
95
+ };
96
+ await render();
97
+ expect(container.querySelector("[role=dialog]")).not.toBeNull();
98
+ });
99
+ it("keeps background updates silent, even after download", async () => {
100
+ controller = {
101
+ ...controller,
102
+ pending: true,
103
+ policy: { schemaVersion: 1, delivery: "background" },
104
+ };
105
+ await render();
106
+ expect(container.querySelector("[role=dialog]")).toBeNull();
107
+ });
108
+ it("does not allow dismissing required updates, even for a previously dismissed candidate", async () => {
109
+ await render();
110
+ await click("Later");
111
+ controller = {
112
+ ...controller,
113
+ blocked: true,
114
+ blockReason: "ota-force-update",
115
+ pending: true,
116
+ };
117
+ await render();
118
+ expect(container.textContent).toContain("Update required");
119
+ expect(container.textContent).not.toContain("Later");
120
+ await act(async () =>
121
+ container
122
+ .querySelector("[role=dialog]")!
123
+ .dispatchEvent(
124
+ new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
125
+ ),
126
+ );
127
+ expect(container.querySelector("[role=dialog]")).not.toBeNull();
128
+ await click("Restart");
129
+ expect(controller.reload).toHaveBeenCalledOnce();
130
+ });
131
+ it("routes store guards to the store instead of download", async () => {
132
+ controller = {
133
+ ...controller,
134
+ blocked: true,
135
+ blockReason: "ota-force-store-update",
136
+ };
137
+ await render();
138
+ await click("Open store");
139
+ expect(controller.openStore).toHaveBeenCalledOnce();
140
+ expect(controller.download).not.toHaveBeenCalled();
141
+ });
142
+ it("leaves unknown guards blocked and disables operations while busy", async () => {
143
+ controller = {
144
+ ...controller,
145
+ blocked: true,
146
+ blockReason: "custom",
147
+ isBusy: true,
148
+ };
149
+ await render();
150
+ expect(container.textContent).toContain("Update needs attention");
151
+ expect(container.querySelector("button")?.disabled).toBe(true);
152
+ expect(container.textContent).not.toContain("Later");
153
+ });
154
+ });
@@ -0,0 +1,34 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface Props {
4
+ children?: ReactNode;
5
+ disabled?: boolean;
6
+ visible?: boolean;
7
+ onPress?: () => void;
8
+ onRequestClose?: () => void;
9
+ accessibilityLabel?: string;
10
+ }
11
+ export const View = ({ children }: Props) => <div>{children}</div>;
12
+ export const Text = ({ children }: Props) => <span>{children}</span>;
13
+ export const Pressable = ({ children, disabled, onPress }: Props) => (
14
+ <button disabled={disabled} onClick={onPress}>
15
+ {children}
16
+ </button>
17
+ );
18
+ export const ActivityIndicator = ({ accessibilityLabel }: Props) => (
19
+ <span role="progressbar" aria-label={accessibilityLabel} />
20
+ );
21
+ export const Modal = ({ children, visible, onRequestClose }: Props) => {
22
+ if (!visible) return null;
23
+ return (
24
+ <div
25
+ role="dialog"
26
+ onKeyDown={(event) => {
27
+ if (event.key === "Escape") onRequestClose?.();
28
+ }}
29
+ >
30
+ {children}
31
+ </div>
32
+ );
33
+ };
34
+ export const StyleSheet = { create: <T,>(styles: T): T => styles };