easc 0.0.28 → 0.0.30
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/README.md +2 -2
- package/bin/easc.js +1 -1
- package/index.ts +2 -2
- package/package.json +34 -34
- package/src/commands/build.ts +4 -14
- package/src/commands/submit.ts +6 -9
- package/src/commands/update.ts +18 -6
- package/src/utils/cli.ts +5 -10
- package/src/utils/files.test.ts +175 -47
- package/src/utils/files.ts +96 -53
- package/src/utils/git.test.ts +2 -2
- package/src/utils/git.ts +2 -6
- package/src/utils/runtime.test.ts +5 -9
- package/src/utils/runtime.ts +5 -9
- package/src/utils/runx.ts +2 -5
- package/src/utils/schema.test.ts +2 -8
- package/src/utils/schema.ts +3 -7
- package/src/utils/upload.ts +23 -11
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ To test easc locally, link the package:
|
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
71
|
# From this directory
|
|
72
|
-
|
|
72
|
+
bun link
|
|
73
73
|
|
|
74
74
|
# Now you can use 'easc' command globally
|
|
75
75
|
easc --help
|
|
@@ -84,5 +84,5 @@ tsx index.ts --help
|
|
|
84
84
|
### Publishing
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
|
|
87
|
+
bun version patch && bun publish
|
|
88
88
|
```
|
package/bin/easc.js
CHANGED
|
@@ -17,7 +17,7 @@ const envArgs = existsSync(envPath) ? ["--env-file", envPath] : [];
|
|
|
17
17
|
const scriptArgs = [indexPath, ...process.argv.slice(2)];
|
|
18
18
|
|
|
19
19
|
function getRuntime() {
|
|
20
|
-
const runtime =
|
|
20
|
+
const runtime = process.versions["bun"] ? Runtime.BUN : Runtime.NODE;
|
|
21
21
|
|
|
22
22
|
switch (runtime) {
|
|
23
23
|
case Runtime.BUN:
|
package/index.ts
CHANGED
|
@@ -5,12 +5,12 @@ import { build } from "./src/commands/build";
|
|
|
5
5
|
import { submit } from "./src/commands/submit";
|
|
6
6
|
import { update } from "./src/commands/update";
|
|
7
7
|
|
|
8
|
-
cli(hideBin(process.argv))
|
|
8
|
+
void cli(hideBin(process.argv))
|
|
9
9
|
.scriptName("easc")
|
|
10
10
|
.usage("$0 <command> [options]")
|
|
11
11
|
.command(update)
|
|
12
|
-
.command(build)
|
|
13
12
|
.command(submit)
|
|
13
|
+
.command(build)
|
|
14
14
|
.demandCommand(1, "")
|
|
15
15
|
.help()
|
|
16
16
|
.alias("help", "h")
|
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "Expo App Services for Cloudflare - Deploy tool for Expo OTA updates to Cloudflare Workers",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"deploy",
|
|
8
|
+
"expo",
|
|
9
|
+
"ota",
|
|
10
|
+
"updates",
|
|
11
|
+
"workers"
|
|
12
|
+
],
|
|
6
13
|
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/Daniel-Griffiths/cloudflare-expo-ota-updates.git",
|
|
17
|
+
"directory": "apps/easc"
|
|
18
|
+
},
|
|
7
19
|
"bin": {
|
|
8
20
|
"easc": "./bin/easc.js"
|
|
9
21
|
},
|
|
@@ -12,45 +24,33 @@
|
|
|
12
24
|
"index.ts",
|
|
13
25
|
"src"
|
|
14
26
|
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
15
31
|
"scripts": {
|
|
16
|
-
"test": "
|
|
17
|
-
"test:watch": "
|
|
18
|
-
"test:ui": "
|
|
19
|
-
"test:coverage": "
|
|
20
|
-
"typecheck": "tsgo --noEmit"
|
|
32
|
+
"test": "vp test",
|
|
33
|
+
"test:watch": "vp test --watch",
|
|
34
|
+
"test:ui": "vp test --ui",
|
|
35
|
+
"test:coverage": "vp test --coverage"
|
|
21
36
|
},
|
|
22
37
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
38
|
+
"@expo/fingerprint": "^0.11.0",
|
|
39
|
+
"@inquirer/prompts": "^8.3.2",
|
|
40
|
+
"chalk": "5.6.2",
|
|
41
|
+
"ora": "^9.3.0",
|
|
42
|
+
"tsx": "^4.21.0",
|
|
27
43
|
"yargs": "^18.0.0",
|
|
28
|
-
"zod": "^4.
|
|
44
|
+
"zod": "^4.3.6"
|
|
29
45
|
},
|
|
30
46
|
"devDependencies": {
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@types/yargs": "^17.0.
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"vitest": "
|
|
47
|
+
"@types/node": "^25.5.0",
|
|
48
|
+
"@types/yargs": "^17.0.35",
|
|
49
|
+
"@vitest/ui": "^4.1.0",
|
|
50
|
+
"vite-plus": "latest",
|
|
51
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
36
52
|
},
|
|
37
53
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
39
|
-
},
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/Daniel-Griffiths/cloudflare-expo-ota-updates.git",
|
|
43
|
-
"directory": "apps/easc"
|
|
44
|
-
},
|
|
45
|
-
"keywords": [
|
|
46
|
-
"expo",
|
|
47
|
-
"ota",
|
|
48
|
-
"cloudflare",
|
|
49
|
-
"workers",
|
|
50
|
-
"deploy",
|
|
51
|
-
"updates"
|
|
52
|
-
],
|
|
53
|
-
"publishConfig": {
|
|
54
|
-
"access": "public"
|
|
54
|
+
"node": ">=20.12.0"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/commands/build.ts
CHANGED
|
@@ -61,26 +61,16 @@ export const build: CommandModule = {
|
|
|
61
61
|
})
|
|
62
62
|
.option("path", {
|
|
63
63
|
type: "string",
|
|
64
|
-
description:
|
|
65
|
-
"Path to the simulator/emulator build archive or app (skips build)",
|
|
64
|
+
description: "Path to the simulator/emulator build archive or app (skips build)",
|
|
66
65
|
})
|
|
67
66
|
.option("non-interactive", {
|
|
68
67
|
type: "boolean",
|
|
69
68
|
description: "Never prompt for user input",
|
|
70
69
|
default: false,
|
|
71
70
|
})
|
|
72
|
-
.example(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
.example(
|
|
77
|
-
"$0 build -p android",
|
|
78
|
-
"Build with default profile and run on Android Emulator",
|
|
79
|
-
)
|
|
80
|
-
.example(
|
|
81
|
-
"$0 build -p ios --path ./build.tar.gz",
|
|
82
|
-
"Run existing build artifact",
|
|
83
|
-
),
|
|
71
|
+
.example("$0 build -p ios -e preview", "Build with preview profile and run on iOS Simulator")
|
|
72
|
+
.example("$0 build -p android", "Build with default profile and run on Android Emulator")
|
|
73
|
+
.example("$0 build -p ios --path ./build.tar.gz", "Run existing build artifact"),
|
|
84
74
|
async handler(argv) {
|
|
85
75
|
const args = argv as unknown as IArgs;
|
|
86
76
|
const logger = new Logger();
|
package/src/commands/submit.ts
CHANGED
|
@@ -84,9 +84,7 @@ export const submit: CommandModule = {
|
|
|
84
84
|
|
|
85
85
|
try {
|
|
86
86
|
const platforms: PlatformType[] =
|
|
87
|
-
args.platform === "all"
|
|
88
|
-
? [Platform.iOS, Platform.Android]
|
|
89
|
-
: [args.platform];
|
|
87
|
+
args.platform === "all" ? [Platform.iOS, Platform.Android] : [args.platform];
|
|
90
88
|
|
|
91
89
|
for (const platform of platforms) {
|
|
92
90
|
const platformName = platform === Platform.iOS ? "iOS" : "Android";
|
|
@@ -129,8 +127,7 @@ export const submit: CommandModule = {
|
|
|
129
127
|
const artifactPath =
|
|
130
128
|
platform === Platform.iOS
|
|
131
129
|
? findBuildArtifact("build-*.ipa")
|
|
132
|
-
: findBuildArtifact("build-*.aab") ||
|
|
133
|
-
findBuildArtifact("build-*.apk");
|
|
130
|
+
: findBuildArtifact("build-*.aab") || findBuildArtifact("build-*.apk");
|
|
134
131
|
|
|
135
132
|
if (!artifactPath) {
|
|
136
133
|
logger.error(`No ${platformName} build artifact found`);
|
|
@@ -139,10 +136,10 @@ export const submit: CommandModule = {
|
|
|
139
136
|
|
|
140
137
|
logger.info(`Found artifact: ${artifactPath}`);
|
|
141
138
|
|
|
142
|
-
runx(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
139
|
+
runx(`eas submit --platform ${platform} --path "${artifactPath}" --non-interactive`, {
|
|
140
|
+
cwd: process.cwd(),
|
|
141
|
+
stdio: "inherit",
|
|
142
|
+
});
|
|
146
143
|
|
|
147
144
|
logger.success(`${platformName} submitted`);
|
|
148
145
|
|
package/src/commands/update.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
checkExportDirectory,
|
|
12
12
|
} from "../utils/files";
|
|
13
13
|
import { uploadBundle, createDryRunSummary } from "../utils/upload";
|
|
14
|
+
import { createFingerprintAsync } from "@expo/fingerprint";
|
|
14
15
|
import { Logger } from "../utils/logger";
|
|
15
16
|
import { PlatformType } from "../enums/platform";
|
|
16
17
|
import { runx } from "../utils/runx";
|
|
@@ -21,6 +22,7 @@ interface IArgs {
|
|
|
21
22
|
dryRun: boolean;
|
|
22
23
|
exportDir: string;
|
|
23
24
|
nonInteractive: boolean;
|
|
25
|
+
dangerouslyIgnoreFingerprintCheck: boolean;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export const update: CommandModule = {
|
|
@@ -54,6 +56,11 @@ export const update: CommandModule = {
|
|
|
54
56
|
description: "Never prompt for user input",
|
|
55
57
|
default: false,
|
|
56
58
|
})
|
|
59
|
+
.option("dangerously-ignore-fingerprint-check", {
|
|
60
|
+
type: "boolean",
|
|
61
|
+
description: "Skip fingerprint validation when native dependencies have changed",
|
|
62
|
+
default: false,
|
|
63
|
+
})
|
|
57
64
|
.example("$0 update --channel production", "Deploy to production")
|
|
58
65
|
.example("$0 update -c staging --skip-build", "Deploy existing build"),
|
|
59
66
|
async handler(argv) {
|
|
@@ -79,16 +86,14 @@ export const update: CommandModule = {
|
|
|
79
86
|
|
|
80
87
|
runx(
|
|
81
88
|
args.exportDir !== "dist"
|
|
82
|
-
? `expo export --output-dir ${args.exportDir}`
|
|
83
|
-
: `expo export`,
|
|
89
|
+
? `expo export --dump-sourcemap --output-dir ${args.exportDir}`
|
|
90
|
+
: `expo export --dump-sourcemap`,
|
|
84
91
|
{ cwd: process.cwd(), stdio: "inherit" },
|
|
85
92
|
);
|
|
86
93
|
|
|
87
94
|
logger.success("Build completed");
|
|
88
95
|
} else {
|
|
89
|
-
logger.info(
|
|
90
|
-
`Skipping build (using existing export from ${args.exportDir})`,
|
|
91
|
-
);
|
|
96
|
+
logger.info(`Skipping build (using existing export from ${args.exportDir})`);
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
const exportDir = checkExportDirectory(args.exportDir);
|
|
@@ -99,11 +104,16 @@ export const update: CommandModule = {
|
|
|
99
104
|
const commitHash = getCommitHash();
|
|
100
105
|
const shortCommit = getShortCommitHash();
|
|
101
106
|
|
|
107
|
+
logger.info("Generating native fingerprint...");
|
|
108
|
+
const { hash: fingerprint } = await createFingerprintAsync(process.cwd());
|
|
109
|
+
logger.success(`Fingerprint: ${fingerprint}`);
|
|
110
|
+
|
|
102
111
|
logger.section("📤 Deployment Info");
|
|
103
112
|
logger.table([
|
|
104
113
|
["Server", config.otaServer],
|
|
105
114
|
["Runtime", runtimeVersion],
|
|
106
115
|
["Commit", shortCommit || ""],
|
|
116
|
+
["Fingerprint", fingerprint || ""],
|
|
107
117
|
["Export Dir", args.exportDir],
|
|
108
118
|
["Channel", channel],
|
|
109
119
|
]);
|
|
@@ -120,7 +130,7 @@ export const update: CommandModule = {
|
|
|
120
130
|
logger.section(platform.toUpperCase());
|
|
121
131
|
|
|
122
132
|
try {
|
|
123
|
-
const bundlePath = findBundleFile(exportDir, platform);
|
|
133
|
+
const bundlePath = findBundleFile(exportDir, metadata, platform);
|
|
124
134
|
const assetPaths = getAssetFiles(exportDir, metadata, platform);
|
|
125
135
|
|
|
126
136
|
if (args.dryRun) {
|
|
@@ -155,6 +165,8 @@ export const update: CommandModule = {
|
|
|
155
165
|
expoConfig: appJson.expo,
|
|
156
166
|
metadata,
|
|
157
167
|
config,
|
|
168
|
+
fingerprint,
|
|
169
|
+
ignoreFingerprintCheck: args.dangerouslyIgnoreFingerprintCheck,
|
|
158
170
|
});
|
|
159
171
|
|
|
160
172
|
logger.succeedSpinner(`${platform} uploaded`);
|
package/src/utils/cli.ts
CHANGED
|
@@ -37,8 +37,7 @@ class InteractiveCLI {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
command(cmd: CommandModule): this {
|
|
40
|
-
const commandStr =
|
|
41
|
-
typeof cmd.command === "string" ? cmd.command : (cmd.command?.[0] ?? "");
|
|
40
|
+
const commandStr = typeof cmd.command === "string" ? cmd.command : (cmd.command?.[0] ?? "");
|
|
42
41
|
const commandName = commandStr.split(" ")[0] || "";
|
|
43
42
|
|
|
44
43
|
let options: Record<string, Options> = {};
|
|
@@ -104,11 +103,10 @@ class InteractiveCLI {
|
|
|
104
103
|
|
|
105
104
|
async parse(): Promise<void> {
|
|
106
105
|
const needsCommandPrompt =
|
|
107
|
-
this.args.length === 0 ||
|
|
108
|
-
(this.args.length === 1 && this.args[0]?.startsWith("-"));
|
|
106
|
+
this.args.length === 0 || (this.args.length === 1 && this.args[0]?.startsWith("-"));
|
|
109
107
|
|
|
110
108
|
if (!needsCommandPrompt) {
|
|
111
|
-
this.yargsInstance.demandCommand(1, "").parse();
|
|
109
|
+
void this.yargsInstance.demandCommand(1, "").parse();
|
|
112
110
|
return;
|
|
113
111
|
}
|
|
114
112
|
|
|
@@ -158,7 +156,7 @@ class InteractiveCLI {
|
|
|
158
156
|
});
|
|
159
157
|
}
|
|
160
158
|
|
|
161
|
-
this.yargsInstance.demandCommand(1, "").parse();
|
|
159
|
+
void this.yargsInstance.demandCommand(1, "").parse();
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
private _showWelcome() {
|
|
@@ -174,10 +172,7 @@ class InteractiveCLI {
|
|
|
174
172
|
console.log();
|
|
175
173
|
}
|
|
176
174
|
|
|
177
|
-
private async _promptForMissingArgs(
|
|
178
|
-
argv: any,
|
|
179
|
-
options: Record<string, Options>,
|
|
180
|
-
) {
|
|
175
|
+
private async _promptForMissingArgs(argv: any, options: Record<string, Options>) {
|
|
181
176
|
if (argv.nonInteractive || argv["non-interactive"]) return;
|
|
182
177
|
|
|
183
178
|
for (const [key, opt] of Object.entries(options)) {
|
package/src/utils/files.test.ts
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vite-plus/test";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
4
|
+
import { Platform } from "../enums/platform";
|
|
5
|
+
import { readAppJson, readMetadata, findBundleFile } from "./files";
|
|
6
|
+
|
|
7
|
+
const { requireImpl } = vi.hoisted(() => ({
|
|
8
|
+
requireImpl: vi.fn().mockImplementation(() => ({
|
|
9
|
+
expo: { name: "FromConfigJs", version: "1.0.0" },
|
|
10
|
+
})),
|
|
11
|
+
}));
|
|
11
12
|
|
|
12
13
|
vi.mock("fs");
|
|
13
14
|
vi.mock("path");
|
|
15
|
+
vi.mock("module", () => ({ createRequire: () => requireImpl }));
|
|
14
16
|
|
|
15
17
|
describe("File utilities", () => {
|
|
16
18
|
beforeEach(() => {
|
|
17
19
|
vi.clearAllMocks();
|
|
18
20
|
vi.mocked(path.join).mockImplementation((...args) => args.join("/"));
|
|
21
|
+
vi.mocked(path.resolve).mockImplementation((...args) => args[0] ?? "");
|
|
22
|
+
requireImpl.mockImplementation(() => ({
|
|
23
|
+
expo: { name: "FromConfigJs", version: "1.0.0" },
|
|
24
|
+
}));
|
|
19
25
|
});
|
|
20
26
|
|
|
21
27
|
describe("readAppJson", () => {
|
|
22
|
-
it("should read
|
|
28
|
+
it("should read app.json when only app.json exists", () => {
|
|
23
29
|
const mockAppJson = {
|
|
24
30
|
expo: {
|
|
25
31
|
name: "TestApp",
|
|
@@ -27,27 +33,101 @@ describe("File utilities", () => {
|
|
|
27
33
|
},
|
|
28
34
|
};
|
|
29
35
|
|
|
30
|
-
vi.mocked(fs.existsSync).
|
|
36
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
37
|
+
(p: fs.PathLike) => typeof p === "string" && p.endsWith("app.json"),
|
|
38
|
+
);
|
|
31
39
|
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockAppJson));
|
|
32
40
|
|
|
33
41
|
const result = readAppJson("/test/dir");
|
|
34
42
|
|
|
35
|
-
expect(fs.existsSync).toHaveBeenCalledWith("/test/dir/app.json");
|
|
36
43
|
expect(fs.readFileSync).toHaveBeenCalledWith("/test/dir/app.json", "utf-8");
|
|
37
44
|
expect(result).toEqual(mockAppJson);
|
|
38
45
|
});
|
|
39
46
|
|
|
40
|
-
it("should
|
|
47
|
+
it("should use app.config.js when it exists and not read app.json", () => {
|
|
48
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
49
|
+
(p: fs.PathLike) => typeof p === "string" && p.endsWith("app.config.js"),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const result = readAppJson("/test/dir");
|
|
53
|
+
|
|
54
|
+
expect(result.expo.name).toBe("FromConfigJs");
|
|
55
|
+
expect(result.expo.version).toBe("1.0.0");
|
|
56
|
+
expect(fs.readFileSync).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should use app.config.ts when it exists and .js does not", () => {
|
|
60
|
+
requireImpl.mockReturnValueOnce({
|
|
61
|
+
expo: { name: "FromConfigTs", version: "1.0.0" },
|
|
62
|
+
});
|
|
63
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
64
|
+
(p: fs.PathLike) => typeof p === "string" && p.endsWith("app.config.ts"),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const result = readAppJson("/test/dir");
|
|
68
|
+
|
|
69
|
+
expect(result.expo.name).toBe("FromConfigTs");
|
|
70
|
+
expect(fs.readFileSync).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should use app.config.ts over app.config.js when both exist", () => {
|
|
74
|
+
requireImpl.mockReturnValueOnce({
|
|
75
|
+
expo: { name: "FromConfigTs", version: "1.0.0" },
|
|
76
|
+
});
|
|
77
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
78
|
+
(p: fs.PathLike) =>
|
|
79
|
+
typeof p === "string" && (p.endsWith("app.config.js") || p.endsWith("app.config.ts")),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const result = readAppJson("/test/dir");
|
|
83
|
+
|
|
84
|
+
expect(result.expo.name).toBe("FromConfigTs");
|
|
85
|
+
expect(requireImpl).toHaveBeenCalledWith("/test/dir/app.config.ts");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should throw if no app config found", () => {
|
|
41
89
|
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
42
90
|
|
|
43
|
-
expect(() => readAppJson("/test/dir")).toThrow("app
|
|
91
|
+
expect(() => readAppJson("/test/dir")).toThrow("No app config found");
|
|
44
92
|
});
|
|
45
93
|
|
|
46
|
-
it("should throw
|
|
47
|
-
|
|
94
|
+
it("should throw with cause when app.config.js fails to load", () => {
|
|
95
|
+
requireImpl.mockImplementationOnce(() => {
|
|
96
|
+
throw new Error("SyntaxError");
|
|
97
|
+
});
|
|
98
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
99
|
+
(p: fs.PathLike) => typeof p === "string" && p.endsWith("app.config.js"),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
readAppJson("/test/dir");
|
|
104
|
+
expect.fail("should have thrown");
|
|
105
|
+
} catch (error) {
|
|
106
|
+
expect(error).toBeInstanceOf(Error);
|
|
107
|
+
if (!(error instanceof Error)) throw error;
|
|
108
|
+
expect(error.message).toMatch(/Failed to load app.config.js/);
|
|
109
|
+
expect(error.cause).toBeDefined();
|
|
110
|
+
expect(error.cause).toBeInstanceOf(Error);
|
|
111
|
+
if (!(error.cause instanceof Error)) throw error;
|
|
112
|
+
expect(error.cause.message).toBe("SyntaxError");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should throw with cause when app.json is invalid JSON", () => {
|
|
117
|
+
vi.mocked(fs.existsSync).mockImplementation(
|
|
118
|
+
(p: fs.PathLike) => typeof p === "string" && p.endsWith("app.json"),
|
|
119
|
+
);
|
|
48
120
|
vi.mocked(fs.readFileSync).mockReturnValue("invalid json");
|
|
49
121
|
|
|
50
|
-
|
|
122
|
+
try {
|
|
123
|
+
readAppJson("/test/dir");
|
|
124
|
+
expect.fail("should have thrown");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
expect(error).toBeInstanceOf(Error);
|
|
127
|
+
if (!(error instanceof Error)) throw error;
|
|
128
|
+
expect(error.message).toMatch(/Failed to load app.json/);
|
|
129
|
+
expect(error.cause).toBeDefined();
|
|
130
|
+
}
|
|
51
131
|
});
|
|
52
132
|
});
|
|
53
133
|
|
|
@@ -72,59 +152,107 @@ describe("File utilities", () => {
|
|
|
72
152
|
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
73
153
|
|
|
74
154
|
expect(() => readMetadata("/test/dist")).toThrow(
|
|
75
|
-
"metadata.json not found in /test/dist. Did you run 'expo export'?"
|
|
155
|
+
"metadata.json not found in /test/dist. Did you run 'expo export'?",
|
|
76
156
|
);
|
|
77
157
|
});
|
|
158
|
+
|
|
159
|
+
it("should throw with cause when metadata.json is invalid JSON", () => {
|
|
160
|
+
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
161
|
+
vi.mocked(fs.readFileSync).mockReturnValue("invalid");
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
readMetadata("/test/dist");
|
|
165
|
+
expect.fail("should have thrown");
|
|
166
|
+
} catch (error) {
|
|
167
|
+
expect(error).toBeInstanceOf(Error);
|
|
168
|
+
if (!(error instanceof Error)) throw error;
|
|
169
|
+
expect(error.message).toMatch(/Failed to parse metadata.json/);
|
|
170
|
+
expect(error.cause).toBeDefined();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
78
173
|
});
|
|
79
174
|
|
|
80
175
|
describe("findBundleFile", () => {
|
|
81
|
-
it("should
|
|
176
|
+
it("should return correct path from metadata bundle field", () => {
|
|
82
177
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
83
|
-
vi.mocked(fs.readdirSync).mockReturnValue([
|
|
84
|
-
"entry-abc123.hbc",
|
|
85
|
-
"other-file.js",
|
|
86
|
-
] as any);
|
|
87
178
|
|
|
88
|
-
const
|
|
179
|
+
const metadata = {
|
|
180
|
+
version: 0,
|
|
181
|
+
bundler: "metro",
|
|
182
|
+
fileMetadata: {
|
|
183
|
+
[Platform.iOS]: {
|
|
184
|
+
bundle: "_expo/static/js/ios/entry-abc123.hbc",
|
|
185
|
+
assets: [],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const result = findBundleFile("/dist", metadata, Platform.iOS);
|
|
89
191
|
|
|
90
192
|
expect(result).toBe("/dist/_expo/static/js/ios/entry-abc123.hbc");
|
|
91
193
|
});
|
|
92
194
|
|
|
93
|
-
it("should
|
|
94
|
-
vi.mocked(fs.existsSync).mockReturnValue(
|
|
195
|
+
it("should work for android platform", () => {
|
|
196
|
+
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
95
197
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
198
|
+
const metadata = {
|
|
199
|
+
version: 0,
|
|
200
|
+
bundler: "metro",
|
|
201
|
+
fileMetadata: {
|
|
202
|
+
[Platform.Android]: {
|
|
203
|
+
bundle: "_expo/static/js/android/index-xyz789.js",
|
|
204
|
+
assets: [],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const result = findBundleFile("/dist", metadata, Platform.Android);
|
|
210
|
+
|
|
211
|
+
expect(result).toBe("/dist/_expo/static/js/android/index-xyz789.js");
|
|
99
212
|
});
|
|
100
213
|
|
|
101
|
-
it("should throw if
|
|
102
|
-
|
|
103
|
-
|
|
214
|
+
it("should throw if platform not in metadata", () => {
|
|
215
|
+
const metadata = {
|
|
216
|
+
version: 0,
|
|
217
|
+
bundler: "metro",
|
|
218
|
+
fileMetadata: {
|
|
219
|
+
[Platform.iOS]: {
|
|
220
|
+
bundle: "_expo/static/js/ios/entry-abc123.hbc",
|
|
221
|
+
assets: [],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
};
|
|
104
225
|
|
|
105
|
-
expect(() => findBundleFile("/dist",
|
|
106
|
-
"No bundle found for
|
|
226
|
+
expect(() => findBundleFile("/dist", metadata, Platform.Android)).toThrow(
|
|
227
|
+
"No bundle path found for android in metadata.json",
|
|
107
228
|
);
|
|
108
229
|
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("checkDistDirectory", () => {
|
|
112
|
-
it("should return dist dir when valid", () => {
|
|
113
|
-
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
114
230
|
|
|
115
|
-
|
|
231
|
+
it("should throw if fileMetadata is missing", () => {
|
|
232
|
+
const metadata = { version: 0, bundler: "metro" };
|
|
116
233
|
|
|
117
|
-
expect(
|
|
234
|
+
expect(() => findBundleFile("/dist", metadata, Platform.iOS)).toThrow(
|
|
235
|
+
"No bundle path found for ios in metadata.json",
|
|
236
|
+
);
|
|
118
237
|
});
|
|
119
238
|
|
|
120
|
-
it("should throw if
|
|
121
|
-
vi.mocked(fs.existsSync).
|
|
122
|
-
|
|
123
|
-
|
|
239
|
+
it("should throw if bundle file doesn't exist on disk", () => {
|
|
240
|
+
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
241
|
+
|
|
242
|
+
const metadata = {
|
|
243
|
+
version: 0,
|
|
244
|
+
bundler: "metro",
|
|
245
|
+
fileMetadata: {
|
|
246
|
+
[Platform.iOS]: {
|
|
247
|
+
bundle: "_expo/static/js/ios/entry-abc123.hbc",
|
|
248
|
+
assets: [],
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
124
252
|
|
|
125
|
-
expect(() =>
|
|
126
|
-
"
|
|
253
|
+
expect(() => findBundleFile("/dist", metadata, Platform.iOS)).toThrow(
|
|
254
|
+
"Bundle file not found",
|
|
127
255
|
);
|
|
128
256
|
});
|
|
129
257
|
});
|
|
130
|
-
});
|
|
258
|
+
});
|
package/src/utils/files.ts
CHANGED
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { createRequire } from "module";
|
|
3
4
|
import { IAppJson } from "./runtime";
|
|
4
5
|
import { Platform, PlatformType } from "../enums/platform";
|
|
5
6
|
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
interface IPlatformMetadata {
|
|
10
|
+
bundle: string;
|
|
11
|
+
assets: Array<{ path: string; ext: string }>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const APP_CONFIGS = [
|
|
15
|
+
{ filename: "app.config.ts", loader: _loadJsConfig },
|
|
16
|
+
{ filename: "app.config.js", loader: _loadJsConfig },
|
|
17
|
+
{ filename: "app.json", loader: _loadJsonConfig },
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
6
20
|
export interface IMetadata {
|
|
21
|
+
version: number;
|
|
22
|
+
bundler: string;
|
|
7
23
|
fileMetadata?: {
|
|
8
|
-
[Platform.iOS]?:
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
[Platform.Android]?: {
|
|
12
|
-
assets: Array<{ path: string }>;
|
|
13
|
-
};
|
|
24
|
+
[Platform.iOS]?: IPlatformMetadata;
|
|
25
|
+
[Platform.Android]?: IPlatformMetadata;
|
|
14
26
|
};
|
|
15
27
|
}
|
|
16
28
|
|
|
17
29
|
/**
|
|
18
|
-
* Read
|
|
30
|
+
* Read app config from the app directory.
|
|
31
|
+
* Tries in order: app.config.js, app.config.ts, app.json.
|
|
32
|
+
* Returns the first found; throws if none exist.
|
|
19
33
|
*/
|
|
20
34
|
export function readAppJson(appDir: string = process.cwd()): IAppJson {
|
|
21
|
-
const
|
|
35
|
+
const resolvedDir = path.resolve(appDir);
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
for (const { filename, loader } of APP_CONFIGS) {
|
|
38
|
+
const filePath = path.join(resolvedDir, filename);
|
|
39
|
+
if (fs.existsSync(filePath)) {
|
|
40
|
+
return _parseAppConfig(filePath, filename, loader);
|
|
41
|
+
}
|
|
25
42
|
}
|
|
26
43
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return JSON.parse(content);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw new Error(`Failed to parse app.json: ${error}`);
|
|
32
|
-
}
|
|
44
|
+
const names = APP_CONFIGS.map((config) => config.filename).join(", ");
|
|
45
|
+
throw new Error(`No app config found in ${appDir}. Create ${names}`);
|
|
33
46
|
}
|
|
34
47
|
|
|
35
48
|
/**
|
|
@@ -39,46 +52,41 @@ export function readMetadata(exportDir: string): IMetadata {
|
|
|
39
52
|
const metadataPath = path.join(exportDir, "metadata.json");
|
|
40
53
|
|
|
41
54
|
if (!fs.existsSync(metadataPath)) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`metadata.json not found in ${exportDir}. Did you run 'expo export'?`
|
|
44
|
-
);
|
|
55
|
+
throw new Error(`metadata.json not found in ${exportDir}. Did you run 'expo export'?`);
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
try {
|
|
48
59
|
const content = fs.readFileSync(metadataPath, "utf-8");
|
|
49
60
|
return JSON.parse(content);
|
|
50
61
|
} catch (error) {
|
|
51
|
-
|
|
62
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
63
|
+
throw new Error(`Failed to parse metadata.json: ${msg}`, { cause: error });
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
/**
|
|
56
|
-
* Find the bundle file for a platform
|
|
68
|
+
* Find the bundle file for a platform using metadata.json
|
|
57
69
|
*/
|
|
58
70
|
export function findBundleFile(
|
|
59
71
|
exportDir: string,
|
|
60
|
-
|
|
72
|
+
metadata: IMetadata,
|
|
73
|
+
platform: PlatformType,
|
|
61
74
|
): string {
|
|
62
|
-
const
|
|
75
|
+
const platformMetadata = metadata.fileMetadata?.[platform];
|
|
63
76
|
|
|
64
|
-
if (!
|
|
65
|
-
throw new Error(
|
|
77
|
+
if (!platformMetadata?.bundle) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`No bundle path found for ${platform} in metadata.json. Run 'npx expo export' first.`,
|
|
80
|
+
);
|
|
66
81
|
}
|
|
67
82
|
|
|
68
|
-
const
|
|
69
|
-
.readdirSync(bundlePath)
|
|
70
|
-
.filter((f) => f.startsWith("entry-") && f.endsWith(".hbc"));
|
|
83
|
+
const bundlePath = path.join(exportDir, platformMetadata.bundle);
|
|
71
84
|
|
|
72
|
-
if (
|
|
73
|
-
throw new Error(`
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const [firstBundle] = bundleFiles;
|
|
77
|
-
if (!firstBundle) {
|
|
78
|
-
throw new Error(`No bundle found for ${platform}`);
|
|
85
|
+
if (!fs.existsSync(bundlePath)) {
|
|
86
|
+
throw new Error(`Bundle file not found: ${bundlePath}. Run 'npx expo export' first.`);
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
return
|
|
89
|
+
return bundlePath;
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
/**
|
|
@@ -87,7 +95,7 @@ export function findBundleFile(
|
|
|
87
95
|
export function getAssetFiles(
|
|
88
96
|
exportDir: string,
|
|
89
97
|
metadata: IMetadata,
|
|
90
|
-
platform: PlatformType
|
|
98
|
+
platform: PlatformType,
|
|
91
99
|
): string[] {
|
|
92
100
|
const assetsPath = path.join(exportDir, "assets");
|
|
93
101
|
|
|
@@ -105,9 +113,7 @@ export function getAssetFiles(
|
|
|
105
113
|
return [];
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
const platformAssetFiles = new Set(
|
|
109
|
-
platformAssets.map((asset) => path.basename(asset.path))
|
|
110
|
-
);
|
|
116
|
+
const platformAssetFiles = new Set(platformAssets.map((asset) => path.basename(asset.path)));
|
|
111
117
|
|
|
112
118
|
const assetFiles = fs.readdirSync(assetsPath);
|
|
113
119
|
const validAssets: string[] = [];
|
|
@@ -126,19 +132,14 @@ export function getAssetFiles(
|
|
|
126
132
|
* Check if the export directory exists and has been built
|
|
127
133
|
* Supports custom export directories (EAS-compatible)
|
|
128
134
|
*/
|
|
129
|
-
export function checkExportDirectory(
|
|
130
|
-
exportDir: string,
|
|
131
|
-
appDir: string = process.cwd()
|
|
132
|
-
): string {
|
|
135
|
+
export function checkExportDirectory(exportDir: string, appDir: string = process.cwd()): string {
|
|
133
136
|
// If exportDir is relative, resolve it from appDir
|
|
134
|
-
const resolvedExportDir = path.isAbsolute(exportDir)
|
|
135
|
-
? exportDir
|
|
136
|
-
: path.join(appDir, exportDir);
|
|
137
|
+
const resolvedExportDir = path.isAbsolute(exportDir) ? exportDir : path.join(appDir, exportDir);
|
|
137
138
|
|
|
138
139
|
if (!fs.existsSync(resolvedExportDir)) {
|
|
139
140
|
throw new Error(
|
|
140
141
|
`Export directory not found: ${resolvedExportDir}\n` +
|
|
141
|
-
`Run 'npx expo export' or use --export-dir to specify a different directory
|
|
142
|
+
`Run 'npx expo export' or use --export-dir to specify a different directory.`,
|
|
142
143
|
);
|
|
143
144
|
}
|
|
144
145
|
|
|
@@ -152,7 +153,7 @@ export function checkExportDirectory(
|
|
|
152
153
|
if (!fs.existsSync(expectedPath)) {
|
|
153
154
|
throw new Error(
|
|
154
155
|
`Invalid export directory structure in: ${resolvedExportDir}\n` +
|
|
155
|
-
`Run 'npx expo export' to generate a valid export
|
|
156
|
+
`Run 'npx expo export' to generate a valid export.`,
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
@@ -161,9 +162,51 @@ export function checkExportDirectory(
|
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
/**
|
|
164
|
-
*
|
|
165
|
-
|
|
165
|
+
* Type guard that checks whether a value conforms to the IAppJson shape
|
|
166
|
+
*/
|
|
167
|
+
function _isAppJson(value: unknown): value is IAppJson {
|
|
168
|
+
if (typeof value !== "object" || value === null || !("expo" in value)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
const record = value as Record<string, unknown>;
|
|
172
|
+
return typeof record["expo"] === "object" && record["expo"] !== null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Load a JS/TS config file via require, resolving default exports
|
|
177
|
+
*/
|
|
178
|
+
function _loadJsConfig(filePath: string): unknown {
|
|
179
|
+
const config = require(filePath);
|
|
180
|
+
return config?.default ?? config;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Load and parse a JSON config file from disk
|
|
166
185
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
186
|
+
function _loadJsonConfig(filePath: string): unknown {
|
|
187
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
188
|
+
return JSON.parse(content);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Load a config file using the given loader and validate it as IAppJson
|
|
193
|
+
*/
|
|
194
|
+
function _parseAppConfig(
|
|
195
|
+
filePath: string,
|
|
196
|
+
label: string,
|
|
197
|
+
loader: (filePath: string) => unknown,
|
|
198
|
+
): IAppJson {
|
|
199
|
+
try {
|
|
200
|
+
const result = loader(filePath);
|
|
201
|
+
if (!_isAppJson(result)) {
|
|
202
|
+
throw new Error(`${label} must contain an object with an "expo" key`);
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (error instanceof Error && error.message.endsWith('"expo" key')) {
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
210
|
+
throw new Error(`Failed to load ${label}: ${msg}`, { cause: error });
|
|
211
|
+
}
|
|
169
212
|
}
|
package/src/utils/git.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vite-plus/test";
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
3
|
import { getCommitHash, getShortCommitHash, isGitClean, getCurrentBranch } from "./git";
|
|
4
4
|
|
|
@@ -109,4 +109,4 @@ describe("Git utilities", () => {
|
|
|
109
109
|
expect(getCurrentBranch()).toBeUndefined();
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
-
});
|
|
112
|
+
});
|
package/src/utils/git.ts
CHANGED
|
@@ -25,9 +25,7 @@ export function getCommitHash(cwd: string = process.cwd()): string | undefined {
|
|
|
25
25
|
* @param cwd - Working directory (defaults to process.cwd())
|
|
26
26
|
* @returns The short commit hash or undefined if not in a git repo
|
|
27
27
|
*/
|
|
28
|
-
export function getShortCommitHash(
|
|
29
|
-
cwd: string = process.cwd()
|
|
30
|
-
): string | undefined {
|
|
28
|
+
export function getShortCommitHash(cwd: string = process.cwd()): string | undefined {
|
|
31
29
|
const hash = getCommitHash(cwd);
|
|
32
30
|
return hash ? hash.substring(0, 7) : undefined;
|
|
33
31
|
}
|
|
@@ -57,9 +55,7 @@ export function isGitClean(cwd: string = process.cwd()): boolean {
|
|
|
57
55
|
* @param cwd - Working directory (defaults to process.cwd())
|
|
58
56
|
* @returns The branch name or undefined if not in a git repo
|
|
59
57
|
*/
|
|
60
|
-
export function getCurrentBranch(
|
|
61
|
-
cwd: string = process.cwd()
|
|
62
|
-
): string | undefined {
|
|
58
|
+
export function getCurrentBranch(cwd: string = process.cwd()): string | undefined {
|
|
63
59
|
try {
|
|
64
60
|
const branch = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
65
61
|
cwd,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect } from "
|
|
1
|
+
import { describe, it, expect } from "vite-plus/test";
|
|
2
2
|
import { resolveRuntimeVersion, getPlatforms, type IAppJson } from "./runtime";
|
|
3
3
|
|
|
4
4
|
describe("resolveRuntimeVersion", () => {
|
|
@@ -28,7 +28,7 @@ describe("resolveRuntimeVersion", () => {
|
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
expect(() => resolveRuntimeVersion(appJson)).toThrow(
|
|
31
|
-
'runtimeVersion policy is "appVersion" but no version field found in app.json'
|
|
31
|
+
'runtimeVersion policy is "appVersion" but no version field found in app.json',
|
|
32
32
|
);
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -36,9 +36,7 @@ describe("resolveRuntimeVersion", () => {
|
|
|
36
36
|
const appJson: IAppJson = {
|
|
37
37
|
expo: {},
|
|
38
38
|
};
|
|
39
|
-
expect(() => resolveRuntimeVersion(appJson)).toThrow(
|
|
40
|
-
"Invalid runtimeVersion configuration"
|
|
41
|
-
);
|
|
39
|
+
expect(() => resolveRuntimeVersion(appJson)).toThrow("Invalid runtimeVersion configuration");
|
|
42
40
|
});
|
|
43
41
|
|
|
44
42
|
it("should throw error for unsupported policy", () => {
|
|
@@ -47,9 +45,7 @@ describe("resolveRuntimeVersion", () => {
|
|
|
47
45
|
runtimeVersion: { policy: "unsupported" } as any,
|
|
48
46
|
},
|
|
49
47
|
};
|
|
50
|
-
expect(() => resolveRuntimeVersion(appJson)).toThrow(
|
|
51
|
-
"Invalid runtimeVersion configuration"
|
|
52
|
-
);
|
|
48
|
+
expect(() => resolveRuntimeVersion(appJson)).toThrow("Invalid runtimeVersion configuration");
|
|
53
49
|
});
|
|
54
50
|
});
|
|
55
51
|
|
|
@@ -96,4 +92,4 @@ describe("getPlatforms", () => {
|
|
|
96
92
|
};
|
|
97
93
|
expect(getPlatforms(appJson)).toEqual(["android"]);
|
|
98
94
|
});
|
|
99
|
-
});
|
|
95
|
+
});
|
package/src/utils/runtime.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { PlatformType } from "../enums/platform";
|
|
|
6
6
|
|
|
7
7
|
export interface IAppJson {
|
|
8
8
|
expo: {
|
|
9
|
+
name?: string;
|
|
9
10
|
runtimeVersion?: string | { policy: string };
|
|
10
11
|
version?: string;
|
|
11
12
|
platforms?: string[];
|
|
@@ -26,14 +27,11 @@ export function resolveRuntimeVersion(appJson: IAppJson): string {
|
|
|
26
27
|
return runtimeVersionConfig;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
if (
|
|
30
|
-
typeof runtimeVersionConfig === "object" &&
|
|
31
|
-
runtimeVersionConfig?.policy === "appVersion"
|
|
32
|
-
) {
|
|
30
|
+
if (typeof runtimeVersionConfig === "object" && runtimeVersionConfig?.policy === "appVersion") {
|
|
33
31
|
const version = appJson.expo.version;
|
|
34
32
|
if (!version) {
|
|
35
33
|
throw new Error(
|
|
36
|
-
'runtimeVersion policy is "appVersion" but no version field found in app.json'
|
|
34
|
+
'runtimeVersion policy is "appVersion" but no version field found in app.json',
|
|
37
35
|
);
|
|
38
36
|
}
|
|
39
37
|
return version;
|
|
@@ -42,7 +40,7 @@ export function resolveRuntimeVersion(appJson: IAppJson): string {
|
|
|
42
40
|
throw new Error(
|
|
43
41
|
"Invalid runtimeVersion configuration in app.json. Must be either:\n" +
|
|
44
42
|
' - A string: "runtimeVersion": "1.0.0"\n' +
|
|
45
|
-
' - Policy object: "runtimeVersion": { "policy": "appVersion" }'
|
|
43
|
+
' - Policy object: "runtimeVersion": { "policy": "appVersion" }',
|
|
46
44
|
);
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -51,7 +49,5 @@ export function resolveRuntimeVersion(appJson: IAppJson): string {
|
|
|
51
49
|
*/
|
|
52
50
|
export function getPlatforms(appJson: IAppJson): PlatformType[] {
|
|
53
51
|
const platforms = appJson.expo.platforms || ["ios", "android"];
|
|
54
|
-
return platforms.filter(
|
|
55
|
-
(p) => p === "ios" || p === "android"
|
|
56
|
-
) as PlatformType[];
|
|
52
|
+
return platforms.filter((p) => p === "ios" || p === "android") as PlatformType[];
|
|
57
53
|
}
|
package/src/utils/runx.ts
CHANGED
|
@@ -4,11 +4,8 @@ import { execSync, ExecSyncOptions } from "child_process";
|
|
|
4
4
|
* Execute a command using the appropriate package runner (bunx or npx)
|
|
5
5
|
* based on the current runtime environment.
|
|
6
6
|
*/
|
|
7
|
-
export function runx(
|
|
8
|
-
|
|
9
|
-
options?: ExecSyncOptions
|
|
10
|
-
): Buffer | string {
|
|
11
|
-
const packageRunner = !!process.versions["bun"] ? "bunx" : "npx";
|
|
7
|
+
export function runx(command: string, options?: ExecSyncOptions): Buffer | string {
|
|
8
|
+
const packageRunner = process.versions["bun"] ? "bunx" : "npx";
|
|
12
9
|
|
|
13
10
|
return execSync(`${packageRunner} ${command}`, options);
|
|
14
11
|
}
|
package/src/utils/schema.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vite-plus/test";
|
|
2
2
|
import {
|
|
3
3
|
validateEnvironment,
|
|
4
4
|
validateChannel,
|
|
@@ -70,13 +70,7 @@ describe("Schema utilities", () => {
|
|
|
70
70
|
|
|
71
71
|
describe("validateChannel", () => {
|
|
72
72
|
it("should pass for valid channel names", () => {
|
|
73
|
-
const validChannels = [
|
|
74
|
-
"production",
|
|
75
|
-
"staging",
|
|
76
|
-
"dev",
|
|
77
|
-
"test-123",
|
|
78
|
-
"feature_branch",
|
|
79
|
-
];
|
|
73
|
+
const validChannels = ["production", "staging", "dev", "test-123", "feature_branch"];
|
|
80
74
|
|
|
81
75
|
for (const channel of validChannels) {
|
|
82
76
|
const result = validateChannel(channel);
|
package/src/utils/schema.ts
CHANGED
|
@@ -11,7 +11,7 @@ const channelSchema = z
|
|
|
11
11
|
.min(1, "Channel name is required")
|
|
12
12
|
.regex(
|
|
13
13
|
/^[a-zA-Z0-9-_]+$/,
|
|
14
|
-
"Channel names can only contain letters, numbers, hyphens, and underscores"
|
|
14
|
+
"Channel names can only contain letters, numbers, hyphens, and underscores",
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
const configSchema = z.object({
|
|
@@ -38,9 +38,7 @@ function formatZodError(error: z.ZodError, context?: string): string[] {
|
|
|
38
38
|
if (context === "environment") {
|
|
39
39
|
if (path === "OTA_SERVER") {
|
|
40
40
|
return (
|
|
41
|
-
`${chalk.red(
|
|
42
|
-
"OTA_SERVER"
|
|
43
|
-
)} environment variable is required or invalid\n` +
|
|
41
|
+
`${chalk.red("OTA_SERVER")} environment variable is required or invalid\n` +
|
|
44
42
|
` Set it in your .env file or export it:\n` +
|
|
45
43
|
` export OTA_SERVER="https://your-ota-server.com"`
|
|
46
44
|
);
|
|
@@ -89,9 +87,7 @@ export function validateEnvironment(): IValidationResult {
|
|
|
89
87
|
/**
|
|
90
88
|
* Validate a channel name using zod
|
|
91
89
|
*/
|
|
92
|
-
export function validateChannel(
|
|
93
|
-
channel: string | undefined
|
|
94
|
-
): IValidationResult {
|
|
90
|
+
export function validateChannel(channel: string | undefined): IValidationResult {
|
|
95
91
|
if (!channel) {
|
|
96
92
|
return {
|
|
97
93
|
valid: false,
|
package/src/utils/upload.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface IUploadOptions {
|
|
|
14
14
|
platform: PlatformType;
|
|
15
15
|
runtimeVersion: string;
|
|
16
16
|
expoConfig: IAppJson["expo"];
|
|
17
|
+
fingerprint?: string | undefined;
|
|
18
|
+
ignoreFingerprintCheck?: boolean | undefined;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -30,6 +32,8 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
30
32
|
assetPaths,
|
|
31
33
|
expoConfig,
|
|
32
34
|
runtimeVersion,
|
|
35
|
+
fingerprint,
|
|
36
|
+
ignoreFingerprintCheck,
|
|
33
37
|
} = options;
|
|
34
38
|
|
|
35
39
|
const form = new FormData();
|
|
@@ -43,6 +47,14 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
43
47
|
form.append("commitHash", commitHash);
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
if (fingerprint) {
|
|
51
|
+
form.append("fingerprint", fingerprint);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (ignoreFingerprintCheck) {
|
|
55
|
+
form.append("ignoreFingerprintCheck", "true");
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
// Add bundle
|
|
47
59
|
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
48
60
|
const bundleBlob = new Blob([bundleBuffer]);
|
|
@@ -63,7 +75,6 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
63
75
|
form.append(`asset-${index}`, assetBlob, assetFileName);
|
|
64
76
|
});
|
|
65
77
|
|
|
66
|
-
// Upload
|
|
67
78
|
const url = new URL("/upload", config.otaServer);
|
|
68
79
|
|
|
69
80
|
const response = await fetch(url.toString(), {
|
|
@@ -75,10 +86,18 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
75
86
|
});
|
|
76
87
|
|
|
77
88
|
if (!response.ok) {
|
|
89
|
+
if (response.status === 409) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"Fingerprint mismatch: the native fingerprint of this update does not match the latest deployed update. " +
|
|
92
|
+
"This usually means native dependencies have changed and a new native build is required. " +
|
|
93
|
+
"Use --dangerously-ignore-fingerprint-check to bypass this check.",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
78
97
|
let errorText = "";
|
|
79
98
|
try {
|
|
80
99
|
errorText = await response.text();
|
|
81
|
-
} catch
|
|
100
|
+
} catch {
|
|
82
101
|
errorText = "Unable to read error response";
|
|
83
102
|
}
|
|
84
103
|
throw new Error(`Upload failed: ${response.status} ${errorText}`);
|
|
@@ -96,14 +115,7 @@ export function createDryRunSummary(options: {
|
|
|
96
115
|
platform: PlatformType;
|
|
97
116
|
runtimeVersion: string;
|
|
98
117
|
}): string {
|
|
99
|
-
const {
|
|
100
|
-
channel,
|
|
101
|
-
platform,
|
|
102
|
-
bundlePath,
|
|
103
|
-
assetPaths,
|
|
104
|
-
commitHash,
|
|
105
|
-
runtimeVersion,
|
|
106
|
-
} = options;
|
|
118
|
+
const { channel, platform, bundlePath, assetPaths, commitHash, runtimeVersion } = options;
|
|
107
119
|
|
|
108
120
|
const bundleSize = fs.statSync(bundlePath).size;
|
|
109
121
|
const totalAssetSize = assetPaths.reduce((sum, path) => {
|
|
@@ -122,7 +134,7 @@ export function createDryRunSummary(options: {
|
|
|
122
134
|
|
|
123
135
|
lines.push(
|
|
124
136
|
`Bundle: ${formatBytes(bundleSize)}`,
|
|
125
|
-
`Assets: ${assetPaths.length} files (${formatBytes(totalAssetSize)})
|
|
137
|
+
`Assets: ${assetPaths.length} files (${formatBytes(totalAssetSize)})`,
|
|
126
138
|
);
|
|
127
139
|
|
|
128
140
|
return lines.join("\n");
|