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.
- package/dist/template/Dockerfile +5 -0
- package/dist/template/docker/minio.Dockerfile +11 -0
- package/dist/template/docker-compose.yml +7 -9
- package/dist/template/docs/expo-app-setup.md +8 -12
- package/dist/template/docs/getting-started.md +9 -5
- package/dist/template/docs/getting-started.ru.md +9 -7
- package/dist/template/docs/ota-client-lifecycle.md +46 -42
- package/dist/template/package-lock.json +589 -0
- package/dist/template/package.json +1 -0
- package/dist/template/scripts/ensure-storage-bucket.mjs +25 -0
- package/dist/template/scripts/lib/device-identity.test.ts +2 -2
- package/dist/template/scripts/lib/doctor.mjs +3 -3
- package/dist/template/scripts/lib/doctor.test.mjs +1 -1
- package/dist/template/scripts/lib/ota-client-configurator.mjs +116 -34
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +210 -61
- package/dist/template/scripts/lib/ota-client.test.ts +1 -1
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +435 -118
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +243 -86
- package/dist/template/scripts/lib/ota-update-controller.test.ts +10 -9
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +154 -0
- package/dist/template/scripts/tests/fixtures/react-native-ui.tsx +34 -0
- package/dist/template/scripts/tests/ota-client-types.mjs +69 -0
- package/dist/template/templates/expo-app/ota-client/README.md +16 -2
- package/dist/template/templates/expo-app/ota-client/controller.ts +107 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +48 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +18 -9
- package/dist/template/templates/expo-app/ota-client/index.ts +16 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +97 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +293 -0
- package/dist/template/templates/expo-app/ota-client/runtime.ts +153 -0
- package/dist/template/templates/expo-app/ota-client/types.ts +85 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +25 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +196 -0
- package/dist/template/tsconfig.json +3 -1
- package/dist/template/vitest.config.mts +3 -0
- package/dist/template-manifest.json +99 -69
- package/package.json +1 -1
- package/dist/template/templates/expo-app/ota-client/controller.js +0 -60
- package/dist/template/templates/expo-app/ota-client/device-identity.js +0 -26
- package/dist/template/templates/expo-app/ota-client/index.d.ts +0 -47
- package/dist/template/templates/expo-app/ota-client/index.js +0 -3
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +0 -48
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +0 -182
- package/dist/template/templates/expo-app/ota-client/runtime.js +0 -112
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +0 -56
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CreateBucketCommand, HeadBucketCommand, S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
|
|
3
|
+
const client = new S3Client({
|
|
4
|
+
endpoint: "http://minio:9000",
|
|
5
|
+
region: "us-east-1",
|
|
6
|
+
forcePathStyle: true,
|
|
7
|
+
credentials: {
|
|
8
|
+
accessKeyId: process.env.MINIO_ROOT_USER,
|
|
9
|
+
secretAccessKey: process.env.MINIO_ROOT_PASSWORD,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const Bucket = process.env.OTA_STORAGE_BUCKET;
|
|
13
|
+
if (!Bucket) throw new Error("OTA_STORAGE_BUCKET is required.");
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
try {
|
|
17
|
+
await client.send(new CreateBucketCommand({ Bucket }));
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (error.name !== "BucketAlreadyOwnedByYou") throw error;
|
|
20
|
+
}
|
|
21
|
+
await client.send(new HeadBucketCommand({ Bucket }));
|
|
22
|
+
console.log("Storage bucket ready.");
|
|
23
|
+
} finally {
|
|
24
|
+
client.destroy();
|
|
25
|
+
}
|
|
@@ -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
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
2
|
-
import path from
|
|
3
|
-
import { planOtaRootHook } from
|
|
4
|
-
const ENTRY =
|
|
5
|
-
const META =
|
|
6
|
-
const extensions = [
|
|
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 ===
|
|
9
|
-
return suffixes.some((suffix) =>
|
|
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({
|
|
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(
|
|
29
|
+
const metadata = JSON.parse(
|
|
30
|
+
fs.readFileSync(path.join(appRoot, META), "utf8"),
|
|
31
|
+
);
|
|
17
32
|
entry = metadata.originalEntry;
|
|
18
|
-
if (typeof entry !==
|
|
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 =
|
|
21
|
-
} else if (typeof entry !==
|
|
22
|
-
throw new Error(
|
|
23
|
-
} else if (
|
|
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(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 =
|
|
60
|
+
const identityNamespace =
|
|
61
|
+
existingConfig.identityNamespace || new URL(manifestUrl).origin;
|
|
34
62
|
const defaultEntries = [];
|
|
35
|
-
if (entry ===
|
|
36
|
-
for (const platform of [
|
|
37
|
-
const source = hasEntry(appRoot,
|
|
38
|
-
|
|
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 =
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
[
|
|
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
|
-
[
|
|
50
|
-
|
|
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 (
|
|
55
|
-
|
|
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) {
|
|
147
|
+
patchPackage(packageJson) {
|
|
148
|
+
return { ...packageJson, main: ENTRY };
|
|
149
|
+
},
|
|
68
150
|
};
|
|
69
151
|
}
|
|
@@ -1,88 +1,237 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import os from
|
|
4
|
-
import { afterEach, describe, expect, it } from
|
|
5
|
-
import { planOtaClient } from
|
|
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(() => {
|
|
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(),
|
|
10
|
-
|
|
11
|
-
|
|
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(
|
|
14
|
-
it(
|
|
15
|
-
const f = setup(
|
|
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({
|
|
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(
|
|
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(
|
|
22
|
-
const f = setup();
|
|
23
|
-
|
|
24
|
-
|
|
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(
|
|
27
|
-
const f = setup();
|
|
28
|
-
planOtaClient(
|
|
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(
|
|
31
|
-
const f = setup(
|
|
32
|
-
|
|
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(
|
|
35
|
-
const f = setup(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(()
|
|
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(
|
|
41
|
-
const f = setup(
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
|
|
45
|
-
|
|
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(
|
|
49
|
-
const f = setup(
|
|
50
|
-
const layout = path.join(f.options.appRoot,
|
|
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(
|
|
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,
|
|
57
|
-
expect(
|
|
58
|
-
|
|
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({
|
|
61
|
-
|
|
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(
|
|
65
|
-
const f = setup(
|
|
66
|
-
const layout = path.join(f.options.appRoot,
|
|
67
|
-
const original =
|
|
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(
|
|
71
|
-
expect(fs.readFileSync(layout,
|
|
72
|
-
expect(fs.existsSync(path.join(f.options.appRoot,
|
|
73
|
-
|
|
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(
|
|
77
|
-
const f = setup(
|
|
78
|
-
const layout = path.join(f.options.appRoot,
|
|
79
|
-
const original =
|
|
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(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(fs.
|
|
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
|
|
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;
|