@akanjs/devkit 3.3.1-rc.0 → 3.4.0-rc.1
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/codeAgent/skills/akan-runtime/SKILL.md +1 -1
- package/executors/executors.test.ts +51 -44
- package/executors/pkgExecutor.ts +13 -10
- package/mobile/nativeApi.test.ts +2 -2
- package/mobile/nativeApi.ts +4 -3
- package/mobile/nativeApp.test.ts +105 -0
- package/mobile/nativeApp.ts +120 -3
- package/mobile/updatePackFolder.test.ts +5 -0
- package/mobile/updatePackFolder.ts +40 -4
- package/mobile/updateUploader.test.ts +41 -3
- package/mobile/updateUploader.ts +12 -4
- package/package.json +3 -4
- package/pipeline/PipelineCompiler.test.ts +270 -0
- package/pipeline/PipelineCompiler.ts +61 -20
- package/pipeline/PipelineDefinition.test.ts +25 -0
- package/pipeline/PipelineDefinition.ts +2 -1
- package/pipeline/PipelineDryRun.test.ts +54 -0
- package/pipeline/PipelineDryRun.ts +11 -4
- package/pipeline/PipelineInputReader.ts +42 -2
- package/pipeline/PipelineRules.ts +5 -1
- package/quality/runtimeImports.test.ts +1 -1
- package/workspace/dependencyScanner.test.ts +10 -0
- package/workspace/dependencyScanner.ts +1 -1
|
@@ -56,7 +56,7 @@ A `start-*` command loads its pages from a running `akan start`; a desktop app c
|
|
|
56
56
|
akan start-desktop <app> # Run the desktop app on this computer
|
|
57
57
|
akan start-ios <app> # Run it in a simulator or on an iPhone (start-android alike)
|
|
58
58
|
akan build-desktop <app> # Build it for this computer into dist/native/<app>/<target>/build
|
|
59
|
-
akan build-desktop <app> --installer true #
|
|
59
|
+
akan build-desktop <app> --installer true # Add its installer: a setup program, a dmg, an AppImage and tar.gz
|
|
60
60
|
akan update-keygen <app> # Make the update signing key once; print its public key
|
|
61
61
|
akan publish-update <app> # Build a key-signed release for updates.url; --sign true also code-signs it
|
|
62
62
|
```
|
|
@@ -1319,10 +1319,10 @@ describe("Workspace and app executor environment contracts", () => {
|
|
|
1319
1319
|
});
|
|
1320
1320
|
|
|
1321
1321
|
describe("PkgExecutor package generation", () => {
|
|
1322
|
-
test("generates dist package metadata from root dependency versions", async () => {
|
|
1322
|
+
test("generates dist package metadata from root dependency versions, leaving the source manifest alone", async () => {
|
|
1323
1323
|
const root = await makeTempRoot();
|
|
1324
1324
|
await writeJson(path.join(root, "package.json"), rootPackageJson());
|
|
1325
|
-
|
|
1325
|
+
const sourcePackageJson = {
|
|
1326
1326
|
name: "@sample/tool",
|
|
1327
1327
|
version: "0.1.0",
|
|
1328
1328
|
description: "tool",
|
|
@@ -1330,7 +1330,8 @@ describe("PkgExecutor package generation", () => {
|
|
|
1330
1330
|
peerDependencies: { react: "19.0.0" },
|
|
1331
1331
|
peerDependenciesMeta: { react: { optional: true } },
|
|
1332
1332
|
optionalDependencies: { "@sample/native": "1.0.0" },
|
|
1333
|
-
}
|
|
1333
|
+
};
|
|
1334
|
+
await writeJson(path.join(root, "pkgs/@sample/tool/package.json"), sourcePackageJson);
|
|
1334
1335
|
|
|
1335
1336
|
const workspace = new WorkspaceExecutor({ workspaceRoot: root, repoName: "repo" });
|
|
1336
1337
|
const pkg = PkgExecutor.from(workspace, "@sample/tool");
|
|
@@ -1352,7 +1353,7 @@ describe("PkgExecutor package generation", () => {
|
|
|
1352
1353
|
default: "./index.ts",
|
|
1353
1354
|
});
|
|
1354
1355
|
expect(await Bun.file(path.join(root, "dist/pkgs/@sample/tool/package.json")).json()).toEqual(distPackageJson);
|
|
1355
|
-
expect(await Bun.file(path.join(root, "pkgs/@sample/tool/package.json")).json()).toEqual(
|
|
1356
|
+
expect(await Bun.file(path.join(root, "pkgs/@sample/tool/package.json")).json()).toEqual(sourcePackageJson);
|
|
1356
1357
|
});
|
|
1357
1358
|
|
|
1358
1359
|
test("names a sibling the root links as workspace:* at the sibling's own version", async () => {
|
|
@@ -1623,48 +1624,54 @@ describe("SysExecutor scan", () => {
|
|
|
1623
1624
|
expect(fullSrv).toContain('import * as cnst from "./cnst";\nimport * as db from "./db";');
|
|
1624
1625
|
});
|
|
1625
1626
|
|
|
1626
|
-
test.skipIf(!hasBiome)(
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1627
|
+
test.skipIf(!hasBiome)(
|
|
1628
|
+
"writes barrels, module indexes and akan.lib.json the way Biome prints them",
|
|
1629
|
+
async () => {
|
|
1630
|
+
const component = "export const C = () => null;\n";
|
|
1631
|
+
const uiFiles = ["QRCode", "Qa", "SSOButton", "Select", "Icon10", "Icon2"].map((name) => [
|
|
1632
|
+
`ui/${name}.tsx`,
|
|
1633
|
+
component,
|
|
1634
|
+
]);
|
|
1635
|
+
const srvkitFiles = ["aB", "aa", "a10", "a9"].map((name) => [`srvkit/${name}.ts`, "export const x = 1;\n"]);
|
|
1636
|
+
const moduleFiles = ["Template", "Unit", "View"].map((role) => [`lib/post/Post.${role}.tsx`, component]);
|
|
1637
|
+
const { root, lib, libDir } = await createScannableLib("biomestable", {
|
|
1638
|
+
files: Object.fromEntries([
|
|
1639
|
+
...uiFiles,
|
|
1640
|
+
...srvkitFiles,
|
|
1641
|
+
...moduleFiles,
|
|
1642
|
+
["lib/post/post.constant.ts", "export class Post {}\n"],
|
|
1643
|
+
]),
|
|
1644
|
+
});
|
|
1645
|
+
expect(await formatWithBiome('export * from "./b";\nexport * from "./a";\n', "libs/x/srvkit/index.ts")).toBe(
|
|
1646
|
+
'export * from "./a";\nexport * from "./b";\n',
|
|
1647
|
+
);
|
|
1645
1648
|
|
|
1646
|
-
|
|
1649
|
+
await lib.scan();
|
|
1647
1650
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1651
|
+
expect(await lib.readFile("ui/index.ts")).toBe(
|
|
1652
|
+
["Icon2", "Icon10", "Qa", "QRCode", "Select", "SSOButton"]
|
|
1653
|
+
.map((name) => `export * from "./${name}";\n`)
|
|
1654
|
+
.join(""),
|
|
1655
|
+
);
|
|
1656
|
+
expect(await lib.readFile("srvkit/index.ts")).toBe(
|
|
1657
|
+
["a9", "a10", "aa", "aB"].map((name) => `export * from "./${name}";\n`).join(""),
|
|
1658
|
+
);
|
|
1659
|
+
for (const file of [
|
|
1660
|
+
"ui/index.ts",
|
|
1661
|
+
"srvkit/index.ts",
|
|
1662
|
+
"lib/post/index.ts",
|
|
1663
|
+
"akan.lib.json",
|
|
1664
|
+
"env/env.server.type.ts",
|
|
1665
|
+
]) {
|
|
1666
|
+
const generated = await lib.readFile(file);
|
|
1667
|
+
expect(await formatWithBiome(generated, `libs/biomestable/${file}`)).toBe(generated);
|
|
1668
|
+
}
|
|
1669
|
+
const devSync = new DevGeneratedIndexSync({ workspaceRoot: root });
|
|
1670
|
+
const events = ["ui/QRCode.tsx", "srvkit/a9.ts", "lib/post"].map((file) => path.join(libDir, file));
|
|
1671
|
+
expect(await devSync.syncForBatch(events)).toEqual({ changedFiles: [], errors: [] });
|
|
1672
|
+
},
|
|
1673
|
+
30_000,
|
|
1674
|
+
);
|
|
1668
1675
|
|
|
1669
1676
|
test.skipIf(!hasBiome)(
|
|
1670
1677
|
"writes env.server.type.ts the way Biome prints it, spreading libs in dependency order",
|
package/executors/pkgExecutor.ts
CHANGED
|
@@ -71,18 +71,21 @@ export class PkgExecutor extends Executor {
|
|
|
71
71
|
Object.fromEntries(names.map((dep) => [dep, dependencyVersions.get(dep) as string]));
|
|
72
72
|
return { dependencies: toDependencyMap(dependencyNames), devDependencies: toDependencyMap(devDependencyNames) };
|
|
73
73
|
}
|
|
74
|
-
async
|
|
74
|
+
async updateDistPackageJsonDependencies(
|
|
75
75
|
dependencies: string[] = [],
|
|
76
76
|
devDependencies: string[] = [],
|
|
77
|
-
): Promise<PackageJson> {
|
|
78
|
-
|
|
77
|
+
): Promise<PackageJson | null> {
|
|
78
|
+
if (!(await this.dist.exists("package.json"))) return null;
|
|
79
|
+
const [rootPackageJson, distPkgJson] = await Promise.all([
|
|
80
|
+
this.workspace.getPackageJson(),
|
|
81
|
+
this.dist.readJson("package.json") as Promise<PackageJson>,
|
|
82
|
+
]);
|
|
79
83
|
const dependencyMaps = await this.#toDependencyMap(rootPackageJson, dependencies, devDependencies);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return newPkgJson;
|
|
84
|
+
//? A build script that drops a dependency field from its manifest has bundled those packages into its output.
|
|
85
|
+
const keptMaps = Object.fromEntries(Object.entries(dependencyMaps).filter(([field]) => field in distPkgJson));
|
|
86
|
+
const newDistPkgJson: PackageJson = { ...distPkgJson, ...keptMaps };
|
|
87
|
+
await this.dist.writeJson("package.json", newDistPkgJson);
|
|
88
|
+
return newDistPkgJson;
|
|
86
89
|
}
|
|
87
90
|
async generateDistPackageJson(dependencies: string[] = [], devDependencies: string[] = []): Promise<PackageJson> {
|
|
88
91
|
const [rootPackageJson, pkgJson] = await Promise.all([this.workspace.getPackageJson(), this.getPackageJson()]);
|
|
@@ -101,7 +104,7 @@ export class PkgExecutor extends Executor {
|
|
|
101
104
|
engines: { bun: ">=1.4.4" },
|
|
102
105
|
...dependencyMaps,
|
|
103
106
|
};
|
|
104
|
-
await
|
|
107
|
+
await this.dist.writeJson("package.json", distPkgJson);
|
|
105
108
|
return distPkgJson;
|
|
106
109
|
}
|
|
107
110
|
async build(): Promise<void> {
|
package/mobile/nativeApi.test.ts
CHANGED
|
@@ -42,7 +42,7 @@ describe("NativeApi", () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
test("refuses an API older than the one the build calls into, and another major, before anything builds", async () => {
|
|
45
|
-
await expect(NativeApi.load(await installVendoredApi("0.
|
|
45
|
+
await expect(NativeApi.load(await installVendoredApi("0.13.4"))).rejects.toThrow(
|
|
46
46
|
"install matching versions of akanjs and @akanjs/cli",
|
|
47
47
|
);
|
|
48
48
|
await expect(NativeApi.load(await installVendoredApi("0.10.0"))).rejects.toThrow(
|
|
@@ -54,6 +54,6 @@ describe("NativeApi", () => {
|
|
|
54
54
|
expect((await NativeApi.load(await installVendoredApi(NativeApi.minimumVersion))).API_VERSION).toBe(
|
|
55
55
|
NativeApi.minimumVersion,
|
|
56
56
|
);
|
|
57
|
-
expect((await NativeApi.load(await installVendoredApi("0.
|
|
57
|
+
expect((await NativeApi.load(await installVendoredApi("0.14.4"))).API_VERSION).toBe("0.14.4");
|
|
58
58
|
});
|
|
59
59
|
});
|
package/mobile/nativeApi.ts
CHANGED
|
@@ -6,9 +6,10 @@ export type NativeBuildApiModule = typeof NativeBuildApi;
|
|
|
6
6
|
export class NativeApi {
|
|
7
7
|
//* The build API versions itself; a major this devkit was not written against is refused before anything builds.
|
|
8
8
|
static readonly supportedMajor = 0;
|
|
9
|
-
//? A desktop
|
|
10
|
-
//?
|
|
11
|
-
|
|
9
|
+
//? A desktop app's unsigned pack and `republishUpdate` arrived in 0.14.0; a desktop release's envelope and
|
|
10
|
+
//? `updates.target` in 0.13.0, and an older API refuses the key; an update release's `revoke` and `resetSequence` in
|
|
11
|
+
//? 0.12.0; `requestedDistribution` in 0.11.0; akanjs 3.0.x vendors 0.10.0.
|
|
12
|
+
static readonly minimumVersion = "0.14.0";
|
|
12
13
|
|
|
13
14
|
/** The API of the akanjs the app installed: the workspace package inside this repo, akanjs's vendored copy elsewhere. */
|
|
14
15
|
static entryOf(appDir: string): string {
|
package/mobile/nativeApp.test.ts
CHANGED
|
@@ -223,6 +223,111 @@ describe("NativeApp", () => {
|
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
+
describe("a desktop app's unsigned pack", () => {
|
|
227
|
+
const updates = { url: "https://releases.example.com/portal", publicKey: `${"a".repeat(43)}=` };
|
|
228
|
+
const sha = (char: string) => char.repeat(64);
|
|
229
|
+
const packing = async (config: Partial<AkanNativeTarget>) => {
|
|
230
|
+
const root = await makeTempRoot();
|
|
231
|
+
const app = {
|
|
232
|
+
...fakeApp(),
|
|
233
|
+
workspace: { workspaceRoot: root },
|
|
234
|
+
logger: { info: () => undefined, warn: () => undefined },
|
|
235
|
+
} as unknown as App;
|
|
236
|
+
const nativeApp = new NativeApp(app, target(config), "main");
|
|
237
|
+
const asked: Record<string, unknown>[] = [];
|
|
238
|
+
nativeApp.assembleWeb = async () => undefined as never;
|
|
239
|
+
nativeApp.prepare = async () =>
|
|
240
|
+
({
|
|
241
|
+
config: { updates: { channel: "pilot" } },
|
|
242
|
+
api: {
|
|
243
|
+
requestedDistribution: () => ({ macos: { sign: true }, unused: [] }),
|
|
244
|
+
packAppUpdate: async (options: Record<string, unknown> & { out: string; previous?: string }) => {
|
|
245
|
+
asked.push(options);
|
|
246
|
+
return {
|
|
247
|
+
build: { artifacts: [], warnings: [] },
|
|
248
|
+
out: options.out,
|
|
249
|
+
signer: { teamId: "TEAM123456" },
|
|
250
|
+
manifest: {
|
|
251
|
+
schema: 2,
|
|
252
|
+
kind: "app",
|
|
253
|
+
app: "com.portal.app",
|
|
254
|
+
platform: "macos",
|
|
255
|
+
arch: "arm64",
|
|
256
|
+
version: "1.0.0",
|
|
257
|
+
build: 1700000000,
|
|
258
|
+
server: true,
|
|
259
|
+
files: [{ path: "app.tar", sha256: sha("b"), size: 4096 }],
|
|
260
|
+
archive: { url: `app/${sha("b")}.tar.gz`, sha256: sha("b"), gzSha256: sha("c"), size: 1024 },
|
|
261
|
+
patches: options.previous
|
|
262
|
+
? [{ from: sha("a"), url: `app/${sha("a")}-${sha("b")}.delta.gz`, sha256: sha("d"), size: 64 }]
|
|
263
|
+
: [],
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
}) as never;
|
|
269
|
+
return { root, nativeApp, asked };
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
test("is recorded in pack.json: the archive, the app's signer and build, and the delta --previous asked for", async () => {
|
|
273
|
+
const { root, nativeApp, asked } = await packing({ updates });
|
|
274
|
+
const out = nativeApp.appPackDir("macos", "arm64");
|
|
275
|
+
expect(out).toBe(path.join(root, "dist/native/portal/default/updates/macos-arm64"));
|
|
276
|
+
|
|
277
|
+
const { pack } = await nativeApp.packAppUpdate("macos", { arch: "arm64", sign: true });
|
|
278
|
+
expect(asked[0]).toMatchObject({ platform: "macos", out, arch: "arm64", macos: { sign: true } });
|
|
279
|
+
expect(asked[0]).not.toHaveProperty("previous");
|
|
280
|
+
const record = await Bun.file(path.join(out, "pack.json")).json();
|
|
281
|
+
expect(record).toEqual({ ...pack, out: undefined });
|
|
282
|
+
expect(record).toMatchObject({
|
|
283
|
+
schema: 2,
|
|
284
|
+
kind: "app",
|
|
285
|
+
app: "portal",
|
|
286
|
+
target: "default",
|
|
287
|
+
platform: "macos",
|
|
288
|
+
arch: "arm64",
|
|
289
|
+
env: "main",
|
|
290
|
+
channel: "pilot",
|
|
291
|
+
appId: "com.portal.app",
|
|
292
|
+
appVersion: "1.0.0",
|
|
293
|
+
build: 1700000000,
|
|
294
|
+
server: true,
|
|
295
|
+
signer: { teamId: "TEAM123456" },
|
|
296
|
+
archive: {
|
|
297
|
+
url: `app/${sha("b")}.tar.gz`,
|
|
298
|
+
tarSha256: sha("b"),
|
|
299
|
+
tarSize: 4096,
|
|
300
|
+
gzSha256: sha("c"),
|
|
301
|
+
gzSize: 1024,
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
expect(record).not.toHaveProperty("patch");
|
|
305
|
+
expect(typeof record.cli).toBe("string");
|
|
306
|
+
expect(Number.isNaN(Date.parse(record.builtAt))).toBe(false);
|
|
307
|
+
|
|
308
|
+
const elsewhere = path.join(root, "elsewhere");
|
|
309
|
+
const previous = `https://releases.example.com/portal/macos-arm64/app/${sha("a")}.tar.gz`;
|
|
310
|
+
const delta = await nativeApp.packAppUpdate("macos", { out: elsewhere, previous });
|
|
311
|
+
expect(asked[1]).toMatchObject({ out: elsewhere, previous });
|
|
312
|
+
expect(delta.pack.patch).toEqual({
|
|
313
|
+
from: sha("a"),
|
|
314
|
+
url: `app/${sha("a")}-${sha("b")}.delta.gz`,
|
|
315
|
+
sha256: sha("d"),
|
|
316
|
+
size: 64,
|
|
317
|
+
});
|
|
318
|
+
expect((await Bun.file(path.join(elsewhere, "pack.json")).json()).patch).toEqual(delta.pack.patch);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test("is refused, like a republish, for a target with no updates before anything builds", async () => {
|
|
322
|
+
const { nativeApp, asked } = await packing({});
|
|
323
|
+
await expect(nativeApp.packAppUpdate("macos")).rejects.toThrow("Native target 'default' has no updates");
|
|
324
|
+
await expect(nativeApp.republishUpdate("macos", { bundle: "1.0.0-1" })).rejects.toThrow(
|
|
325
|
+
"Native target 'default' has no updates",
|
|
326
|
+
);
|
|
327
|
+
expect(asked).toEqual([]);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
226
331
|
test("a dev build bundles no page a release build left, and builds apart from the release it would empty", async () => {
|
|
227
332
|
const root = await makeTempRoot();
|
|
228
333
|
const app = {
|
package/mobile/nativeApp.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { NativePluginFolders } from "./nativePluginFolders";
|
|
|
21
21
|
import { NativePublicEnv, type PublicEnv } from "./nativePublicEnv";
|
|
22
22
|
import { NativeWebDir } from "./nativeWebDir";
|
|
23
23
|
import { ServerBundleSecrets } from "./serverBundleSecrets";
|
|
24
|
-
import { type NativeUpdatePack, UpdatePackFolder } from "./updatePackFolder";
|
|
24
|
+
import { type DesktopUpdatePack, type NativeUpdatePack, UpdatePackFolder } from "./updatePackFolder";
|
|
25
25
|
|
|
26
26
|
type TaskOptions = Parameters<NativeBuildApiModule["build"]>[0];
|
|
27
27
|
type DeviceSelector = NonNullable<Parameters<NativeBuildApiModule["run"]>[0]["device"]>;
|
|
@@ -44,7 +44,7 @@ export interface NativeBuildOptions {
|
|
|
44
44
|
profile?: "debug" | "release";
|
|
45
45
|
/** The server a desktop app carries (the target's `desktop.server`), staged by DesktopServerStage. */
|
|
46
46
|
server?: DesktopServerBundle;
|
|
47
|
-
/** What a person downloads beside the app: a Windows NSIS setup program, a macOS dmg, a Linux AppImage. */
|
|
47
|
+
/** What a person downloads beside the app: a Windows NSIS setup program, a macOS dmg, a Linux AppImage and tar.gz. */
|
|
48
48
|
installer?: boolean;
|
|
49
49
|
/** The CPU the desktop app runs on, of the same OS; a macOS app is arm64 only. Default this computer's. */
|
|
50
50
|
arch?: DesktopArch;
|
|
@@ -376,6 +376,122 @@ export class NativeApp {
|
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
+
//? Beside the releases publishUpdate signs for the same OS and CPU: both name an archive by its hash, so one a pack
|
|
380
|
+
//? wrote is the one a later publish or --previous finds.
|
|
381
|
+
appPackDir(platform: DesktopPlatform, arch: DesktopArch = process.arch as DesktopArch) {
|
|
382
|
+
return path.join(this.updatesDir, `${platform}-${arch}`);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* A desktop release this target's updates folder published, signed again as its channel's newest: the same archive
|
|
387
|
+
* under a new sequence, so installs on a later build go back to it. Nothing is built.
|
|
388
|
+
*/
|
|
389
|
+
async republishUpdate(
|
|
390
|
+
platform: DesktopPlatform,
|
|
391
|
+
{
|
|
392
|
+
bundle,
|
|
393
|
+
channel,
|
|
394
|
+
arch,
|
|
395
|
+
revoke,
|
|
396
|
+
resetSequence,
|
|
397
|
+
}: { bundle: string; channel?: string; arch?: DesktopArch } & ReleaseRevocation,
|
|
398
|
+
) {
|
|
399
|
+
this.#assertUpdates();
|
|
400
|
+
const [api, { config }] = await Promise.all([
|
|
401
|
+
NativeApi.load(this.app.cwdPath),
|
|
402
|
+
this.config({ platform, stageBin: false }),
|
|
403
|
+
]);
|
|
404
|
+
this.#assertValid(api, config);
|
|
405
|
+
const { log } = this.#task(platform, config);
|
|
406
|
+
return await api.republishUpdate({
|
|
407
|
+
appDir: this.app.cwdPath,
|
|
408
|
+
config,
|
|
409
|
+
platform,
|
|
410
|
+
bundle,
|
|
411
|
+
out: this.updatesDir,
|
|
412
|
+
log,
|
|
413
|
+
...(channel ? { channel } : {}),
|
|
414
|
+
...(arch ? { arch } : {}),
|
|
415
|
+
...(revoke?.length ? { revoke } : {}),
|
|
416
|
+
...(resetSequence ? { resetSequence } : {}),
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* An unsigned update of this target's desktop app: a release build as publishUpdate makes it, its archive and the
|
|
422
|
+
* manifest template whoever holds the update key fills and signs, and the record `pack.json` keeps of it.
|
|
423
|
+
*/
|
|
424
|
+
async packAppUpdate(
|
|
425
|
+
platform: DesktopPlatform,
|
|
426
|
+
{
|
|
427
|
+
out,
|
|
428
|
+
server,
|
|
429
|
+
arch,
|
|
430
|
+
sign = false,
|
|
431
|
+
notarize = false,
|
|
432
|
+
previous,
|
|
433
|
+
}: {
|
|
434
|
+
out?: string;
|
|
435
|
+
server?: DesktopServerBundle;
|
|
436
|
+
arch?: DesktopArch;
|
|
437
|
+
sign?: boolean;
|
|
438
|
+
notarize?: boolean;
|
|
439
|
+
/** The archive of the release the channel has now, a path or a URL: the pack carries the delta from it. */
|
|
440
|
+
previous?: string;
|
|
441
|
+
} = {},
|
|
442
|
+
) {
|
|
443
|
+
this.#assertUpdates();
|
|
444
|
+
await this.assembleWeb(platform);
|
|
445
|
+
const { api, config } = await this.prepare(platform, server, arch);
|
|
446
|
+
const distribution = await this.#distribution(api, platform, "release", { sign, notarize }, server);
|
|
447
|
+
const packed = await api.packAppUpdate({
|
|
448
|
+
...this.#task(platform, config, { env: await this.#runtimeEnv(server) }),
|
|
449
|
+
platform,
|
|
450
|
+
out: path.resolve(out ?? this.appPackDir(platform, arch)),
|
|
451
|
+
...(arch ? { arch } : {}),
|
|
452
|
+
...(distribution.macos ? { macos: distribution.macos } : {}),
|
|
453
|
+
...(distribution.windows ? { windows: distribution.windows } : {}),
|
|
454
|
+
...(previous ? { previous } : {}),
|
|
455
|
+
});
|
|
456
|
+
const { manifest } = packed;
|
|
457
|
+
const { archive } = manifest;
|
|
458
|
+
const [file] = manifest.files;
|
|
459
|
+
if (!archive || !file || !manifest.arch || manifest.build === undefined)
|
|
460
|
+
throw new Error(`The native build API packed no app archive for '${this.target.name}'.`);
|
|
461
|
+
const [patch] = manifest.patches ?? [];
|
|
462
|
+
const tool = (await Bun.file(path.join(import.meta.dir, "..", "package.json"))
|
|
463
|
+
.json()
|
|
464
|
+
.catch(() => null)) as { version?: string } | null;
|
|
465
|
+
const pack: DesktopUpdatePack = {
|
|
466
|
+
schema: 2,
|
|
467
|
+
kind: "app",
|
|
468
|
+
...(tool?.version ? { cli: tool.version } : {}),
|
|
469
|
+
builtAt: new Date().toISOString(),
|
|
470
|
+
app: this.app.name,
|
|
471
|
+
target: this.target.name,
|
|
472
|
+
platform,
|
|
473
|
+
arch: manifest.arch,
|
|
474
|
+
env: this.env ?? "main",
|
|
475
|
+
channel: config.updates?.channel ?? "production",
|
|
476
|
+
appId: manifest.app,
|
|
477
|
+
appVersion: manifest.version,
|
|
478
|
+
build: manifest.build,
|
|
479
|
+
server: manifest.server === true,
|
|
480
|
+
signer: packed.signer,
|
|
481
|
+
archive: {
|
|
482
|
+
url: archive.url,
|
|
483
|
+
tarSha256: archive.sha256,
|
|
484
|
+
tarSize: file.size,
|
|
485
|
+
gzSha256: archive.gzSha256,
|
|
486
|
+
gzSize: archive.size,
|
|
487
|
+
},
|
|
488
|
+
...(patch ? { patch } : {}),
|
|
489
|
+
out: packed.out,
|
|
490
|
+
};
|
|
491
|
+
await UpdatePackFolder.write(pack);
|
|
492
|
+
return { ...packed, pack };
|
|
493
|
+
}
|
|
494
|
+
|
|
379
495
|
//* Only what the command asked for is signed or uploaded. A release's server is searched for the workspace's secret
|
|
380
496
|
//* values first, signed or not: an unsigned app is handed out too, and an update is published to every install. The
|
|
381
497
|
//* one line naming the identity and the service comes right before the build.
|
|
@@ -582,7 +698,8 @@ export class NativeApp {
|
|
|
582
698
|
return `/${home.join("/")}?${params}${hash ? `#${hash}` : ""}`;
|
|
583
699
|
}
|
|
584
700
|
|
|
585
|
-
//* `installer` is
|
|
701
|
+
//* `installer` is what a person downloads: a setup program on Windows, a disk image on macOS, and on Linux an
|
|
702
|
+
//* AppImage and a tar.gz whose install.sh installs the folder that updates itself.
|
|
586
703
|
static assertInstaller(platform: NativePlatform, installer: boolean) {
|
|
587
704
|
if (installer && (platform === "ios" || platform === "android"))
|
|
588
705
|
throw new Error(`An installer is built for a desktop app (Windows, macOS, Linux), not for ${platform}.`);
|
|
@@ -31,6 +31,11 @@ describe("a pack read back from its folder", () => {
|
|
|
31
31
|
const later = path.join(root, "later");
|
|
32
32
|
await writeText(path.join(later, "pack.json"), JSON.stringify({ ...pack, schema: 2 }));
|
|
33
33
|
await expect(UpdatePackFolder.read(later)).rejects.toThrow("schema 2");
|
|
34
|
+
const desktop = path.join(root, "desktop");
|
|
35
|
+
await writeText(path.join(desktop, "pack.json"), JSON.stringify({ schema: 2, kind: "app", platform: "macos" }));
|
|
36
|
+
await expect(UpdatePackFolder.read(desktop)).rejects.toThrow(
|
|
37
|
+
`${desktop} holds a desktop app's pack, which whoever holds the update key signs`,
|
|
38
|
+
);
|
|
34
39
|
const refused = path.join(root, "refused");
|
|
35
40
|
const compat = { against: "store/bundle.json", compatible: false, problems: ["deepLinks differ"] };
|
|
36
41
|
await writeText(path.join(refused, "pack.json"), JSON.stringify({ ...pack, compat }));
|
|
@@ -2,9 +2,10 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import type { NativeEnv } from "akanjs";
|
|
5
|
-
import type { BundleInfo, UpdateManifest } from "akanjs/native/api";
|
|
5
|
+
import type { AppSigner, BundleInfo, UpdateManifest } from "akanjs/native/api";
|
|
6
6
|
import { ExitCodeError } from "../commandDecorators/exitCodeError";
|
|
7
|
-
import type {
|
|
7
|
+
import type { DesktopArch } from "./desktopBin";
|
|
8
|
+
import type { DesktopPlatform, MobilePlatform } from "./mobileTarget";
|
|
8
9
|
|
|
9
10
|
export interface NativeUpdatePackCompat {
|
|
10
11
|
/** The store build's bundle.json the pack was compared with. */
|
|
@@ -35,6 +36,37 @@ export interface NativeUpdatePack {
|
|
|
35
36
|
compat?: NativeUpdatePackCompat;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/**
|
|
40
|
+
* `<out>/pack.json` of a desktop pack: what whoever signs it needs to know of the app in `app/`. Schema 2, so a reader
|
|
41
|
+
* of a phone's pack refuses it by its number.
|
|
42
|
+
*/
|
|
43
|
+
export interface DesktopUpdatePack {
|
|
44
|
+
schema: 2;
|
|
45
|
+
kind: "app";
|
|
46
|
+
/** The @akanjs/cli version that packed it. */
|
|
47
|
+
cli?: string;
|
|
48
|
+
builtAt: string;
|
|
49
|
+
app: string;
|
|
50
|
+
target: string;
|
|
51
|
+
platform: DesktopPlatform;
|
|
52
|
+
arch: DesktopArch;
|
|
53
|
+
env: NativeEnv;
|
|
54
|
+
/** The target's `updates.channel`; the signer decides the release's. */
|
|
55
|
+
channel: string;
|
|
56
|
+
appId: string;
|
|
57
|
+
appVersion: string;
|
|
58
|
+
/** The manifest's `build`: the packed app's own sequence, by which an installed copy knows a release is itself. */
|
|
59
|
+
build: number;
|
|
60
|
+
server: boolean;
|
|
61
|
+
/** Who signed the app's files (not the update key); null for an app signed ad hoc or not at all. */
|
|
62
|
+
signer: AppSigner | null;
|
|
63
|
+
archive: { url: string; tarSha256: string; tarSize: number; gzSha256: string; gzSize: number };
|
|
64
|
+
/** With --previous: the delta the manifest template names in `patches`. */
|
|
65
|
+
patch?: { from: string; url: string; sha256: string; size: number };
|
|
66
|
+
/** The folder it was packed to; pack.json leaves it out. */
|
|
67
|
+
out: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
38
70
|
//* The folder `akan pack-update` writes for a signer or Akan Cloud: the native build API writes `files/<sha256>`,
|
|
39
71
|
//* bundle.json and manifest.template.json, and akan writes pack.json and compat.json beside them.
|
|
40
72
|
export class UpdatePackFolder {
|
|
@@ -63,14 +95,18 @@ export class UpdatePackFolder {
|
|
|
63
95
|
const file = Bun.file(path.join(dir, UpdatePackFolder.packFile));
|
|
64
96
|
if (!(await file.exists()))
|
|
65
97
|
throw new Error(`${dir} holds no ${UpdatePackFolder.packFile}: give the folder \`akan pack-update\` wrote.`);
|
|
66
|
-
const pack = (await file.json()) as NativeUpdatePack;
|
|
98
|
+
const pack = (await file.json()) as NativeUpdatePack | DesktopUpdatePack;
|
|
99
|
+
if (pack.schema === 2 && pack.kind === "app")
|
|
100
|
+
throw new Error(
|
|
101
|
+
`${dir} holds a desktop app's pack, which whoever holds the update key signs (fillManifest, manifestBytes and updateEnvelope of akanjs/native/api); a phone's pack is read here.`,
|
|
102
|
+
);
|
|
67
103
|
if (pack.schema !== 1)
|
|
68
104
|
throw new Error(`${dir}/${UpdatePackFolder.packFile} is schema ${pack.schema}, and this akan reads schema 1.`);
|
|
69
105
|
return { ...pack, out: path.resolve(dir) };
|
|
70
106
|
}
|
|
71
107
|
|
|
72
108
|
//? Without `out`: the record travels in the pack's archive, and the folder is wherever it is read from.
|
|
73
|
-
static async write({ out, ...record }: NativeUpdatePack) {
|
|
109
|
+
static async write({ out, ...record }: NativeUpdatePack | DesktopUpdatePack) {
|
|
74
110
|
await Bun.write(path.join(out, UpdatePackFolder.packFile), `${JSON.stringify(record, null, 2)}\n`);
|
|
75
111
|
}
|
|
76
112
|
|
|
@@ -83,12 +83,14 @@ describe("UpdateUploader", () => {
|
|
|
83
83
|
);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
test("uploads a desktop release's envelope, with the v1 pair only when the pair is that release", async () => {
|
|
86
|
+
test("uploads a desktop release's envelope and the copy kept of it, with the v1 pair only when the pair is that release", async () => {
|
|
87
87
|
const manifest = { kind: "app", bundle: "1.3.0-3000", archive: { url: `app/${sha("c")}.tar.gz` }, patches: [] };
|
|
88
88
|
await inUpdatesDir(
|
|
89
89
|
{
|
|
90
90
|
[`macos-arm64/app/${sha("c")}.tar.gz`]: "tar",
|
|
91
91
|
"macos-arm64/main/app.json": envelope(manifest),
|
|
92
|
+
"macos-arm64/main/releases/1.3.0-3000.json": envelope(manifest),
|
|
93
|
+
"macos-arm64/main/releases/1.2.0-2000.json": envelope({ ...manifest, bundle: "1.2.0-2000" }),
|
|
92
94
|
"macos-arm64/main.json": JSON.stringify({ ...manifest, bundle: "1.2.0-2000" }),
|
|
93
95
|
"macos-arm64/main.json.sig": "sig",
|
|
94
96
|
"macos-arm64/beta/app.json": envelope({ ...manifest, bundle: "1.4.0-4000" }),
|
|
@@ -97,13 +99,18 @@ describe("UpdateUploader", () => {
|
|
|
97
99
|
},
|
|
98
100
|
async (updatesDir) => {
|
|
99
101
|
const dir = path.join(updatesDir, "macos-arm64");
|
|
100
|
-
const upload = async (channel: string, bundle: string) => {
|
|
101
|
-
const { bucket, writes } = fakeBucket();
|
|
102
|
+
const upload = async (channel: string, bundle: string, held: string[] = []) => {
|
|
103
|
+
const { bucket, writes } = fakeBucket(held);
|
|
102
104
|
await new UpdateUploader(bucket, "").upload(updatesDir, { dir, channel, bundle });
|
|
103
105
|
return writes.map(({ key }) => key);
|
|
104
106
|
};
|
|
105
107
|
|
|
106
108
|
expect(await upload("main", "1.3.0-3000")).toEqual([
|
|
109
|
+
`macos-arm64/app/${sha("c")}.tar.gz`,
|
|
110
|
+
"macos-arm64/main/releases/1.3.0-3000.json",
|
|
111
|
+
"macos-arm64/main/app.json",
|
|
112
|
+
]);
|
|
113
|
+
expect(await upload("main", "1.3.0-3000", ["macos-arm64/main/releases/1.3.0-3000.json"])).toEqual([
|
|
107
114
|
`macos-arm64/app/${sha("c")}.tar.gz`,
|
|
108
115
|
"macos-arm64/main/app.json",
|
|
109
116
|
]);
|
|
@@ -148,6 +155,37 @@ describe("UpdateUploader", () => {
|
|
|
148
155
|
);
|
|
149
156
|
});
|
|
150
157
|
|
|
158
|
+
test("writes the live envelope of a channel named releases every time, on a phone and a desktop alike", async () => {
|
|
159
|
+
const app = { kind: "app", bundle: "1.3.0-3000", archive: { url: `app/${sha("c")}.tar.gz` }, patches: [] };
|
|
160
|
+
await inUpdatesDir(
|
|
161
|
+
{
|
|
162
|
+
[`ios/files/${sha("a")}`]: "index.html",
|
|
163
|
+
"ios/releases/api2.json": envelope({ bundle: "3000-aaaaaaaa", files: [{ sha256: sha("a") }] }),
|
|
164
|
+
[`macos-arm64/app/${sha("c")}.tar.gz`]: "tar",
|
|
165
|
+
"macos-arm64/releases/app.json": envelope(app),
|
|
166
|
+
"macos-arm64/releases/releases/1.3.0-3000.json": envelope(app),
|
|
167
|
+
},
|
|
168
|
+
async (updatesDir) => {
|
|
169
|
+
const upload = async (platform: string, bundle: string, held: string[]) => {
|
|
170
|
+
const { bucket, writes } = fakeBucket(held);
|
|
171
|
+
const release = { dir: path.join(updatesDir, platform), channel: "releases", bundle };
|
|
172
|
+
await new UpdateUploader(bucket, "").upload(updatesDir, release);
|
|
173
|
+
return writes.map(({ key }) => key);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
expect(await upload("ios", "3000-aaaaaaaa", [`ios/files/${sha("a")}`, "ios/releases/api2.json"])).toEqual([
|
|
177
|
+
"ios/releases/api2.json",
|
|
178
|
+
]);
|
|
179
|
+
const desktopHeld = [
|
|
180
|
+
`macos-arm64/app/${sha("c")}.tar.gz`,
|
|
181
|
+
"macos-arm64/releases/app.json",
|
|
182
|
+
"macos-arm64/releases/releases/1.3.0-3000.json",
|
|
183
|
+
];
|
|
184
|
+
expect(await upload("macos-arm64", "1.3.0-3000", desktopHeld)).toEqual(["macos-arm64/releases/app.json"]);
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
151
189
|
test("uploads nothing when the release is not there or names a file outside its folder", async () => {
|
|
152
190
|
await inUpdatesDir(
|
|
153
191
|
{
|