@akanjs/cli 3.1.1-rc.1 → 3.1.1-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-4pnxwptq.js → CodeAgent-5t8m16w8.js} +2 -2
  3. package/{CodeTui-hhndze8h.js → CodeTui-drgacyvs.js} +1 -1
  4. package/TunnelShare-26ty9skr.js +14 -0
  5. package/{agent.command-p02330r6.js → agent.command-h82gepwn.js} +5 -5
  6. package/akanCode.js +2 -2
  7. package/{application.command-1117fgq9.js → application.command-j1reb9p1.js} +11 -11
  8. package/{applicationBuildRunner-9cnnsdm5.js → applicationBuildRunner-w20x63mz.js} +74 -26
  9. package/buildBatch.proc.js +5 -5
  10. package/{cloud.command-ttb2s2x6.js → cloud.command-zd2mfkm0.js} +22 -17
  11. package/cloud.script-vdj8ymch.js +24 -0
  12. package/{code.command-16pm1p2v.js → code.command-w1rt357h.js} +6 -6
  13. package/{context.command-6ys86sqf.js → context.command-d35ppstw.js} +16 -16
  14. package/context.runner-azvkkzdr.js +25 -0
  15. package/{guideline.command-3zay3d8g.js → guideline.command-xwkskvky.js} +2 -2
  16. package/guidelines/agentRule/agentRule.instruction.md +21 -4
  17. package/guidelines/conventions/conventions.instruction.md +10 -7
  18. package/guidelines/pageRule/pageRule.instruction.md +9 -0
  19. package/guidelines/queryRule/queryRule.instruction.md +13 -1
  20. package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -0
  21. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +2 -1
  22. package/incrementalBuilder.proc.js +3 -3
  23. package/{index-rr7jk14m.js → index-1e2955yd.js} +23 -10
  24. package/{index-z9xepn8t.js → index-2qzzp0c9.js} +557 -142
  25. package/{index-e9e9cebg.js → index-4rwfh2de.js} +3 -3
  26. package/{index-fmder14z.js → index-553xyb55.js} +1 -1
  27. package/{index-9hbhm6cs.js → index-657908e5.js} +1 -1
  28. package/{index-1mfyyxh5.js → index-6pzt55w3.js} +3 -3
  29. package/{index-4w3skd33.js → index-6y1991s6.js} +3 -3
  30. package/{index-zn6bn1s2.js → index-7abjzny1.js} +4 -4
  31. package/{index-2ar6tffh.js → index-7ktk2hnz.js} +67 -19
  32. package/{index-bb4hj03s.js → index-7yzcaymm.js} +10 -10
  33. package/{index-ngpn9hzy.js → index-8jb5ep2e.js} +2 -2
  34. package/{index-ekpp5tax.js → index-8rvwgd1r.js} +4 -97
  35. package/{index-sww1x1mv.js → index-brpk7gd8.js} +56 -9
  36. package/{index-7f0edwsj.js → index-ch1sv7ke.js} +57 -12
  37. package/{index-jgs8z8xb.js → index-cz9g85xh.js} +1 -1
  38. package/{index-tk3jg2bm.js → index-hdzjaq7s.js} +4 -3
  39. package/{index-sng3vt0p.js → index-kbbyzs6j.js} +2 -2
  40. package/{index-z6v7k9sb.js → index-kr62ph5a.js} +24 -2
  41. package/{index-b5vptvnt.js → index-nmy1rana.js} +4 -4
  42. package/{index-ynqxpwx6.js → index-pqdz7rat.js} +1 -1
  43. package/{index-p4dnj2wc.js → index-qmeh0s05.js} +63 -8
  44. package/{index-qkcwsg6r.js → index-rshwdv9w.js} +2 -2
  45. package/{index-jaa81e9r.js → index-trvk51ht.js} +4 -4
  46. package/{index-1cq1hq12.js → index-tzzs52h0.js} +26 -15
  47. package/{index-qfzfaq96.js → index-wvvwdzfw.js} +3 -3
  48. package/{index-vcpbrrf2.js → index-xeh7m2j5.js} +1 -1
  49. package/{index-sh9mmp5v.js → index-y5m4j2w6.js} +7 -7
  50. package/{index-g2s33373.js → index-ygy8c12j.js} +1 -1
  51. package/{index-q8age5az.js → index-yknrmkmt.js} +2 -2
  52. package/index.js +22 -22
  53. package/{library.command-a8n9h8j4.js → library.command-td8t85kb.js} +3 -3
  54. package/{localRegistry.command-c2mxqf4h.js → localRegistry.command-jx9zkmxf.js} +12 -12
  55. package/{module.command-b6f1p1xa.js → module.command-j70mqgpp.js} +5 -5
  56. package/{package.command-tc27ftmy.js → package.command-1b1v6k5v.js} +3 -3
  57. package/package.json +2 -2
  58. package/{page.command-m5wyqfkd.js → page.command-m31w2tsz.js} +3 -3
  59. package/{pipeline.command-4qxyafpz.js → pipeline.command-q7b8wy55.js} +2 -2
  60. package/{primitive.command-9yaatk0d.js → primitive.command-4zrbhkb9.js} +6 -6
  61. package/{projectTypecheck-87k6z6ab.js → projectTypecheck-synx6qff.js} +1 -1
  62. package/{quality.command-fxn07zwp.js → quality.command-cy0pgqjz.js} +3 -3
  63. package/{repair.command-evg9g911.js → repair.command-98n6zxg7.js} +5 -5
  64. package/{scalar.command-xsejjeq1.js → scalar.command-rak5pjk3.js} +4 -4
  65. package/{subspace.command-4mjjxgmf.js → subspace.command-ej0rk116.js} +8 -8
  66. package/templates/app/tsconfig.json.template +2 -7
  67. package/templates/env/_env.server.type.ts +10 -5
  68. package/templates/facetIndex/index.ts +2 -2
  69. package/templates/workspaceRoot/bunfig.toml.template +0 -4
  70. package/{tunnel.command-7f41pm7y.js → tunnel.command-kdx3amrc.js} +7 -7
  71. package/{workflow.command-qpyq0ya5.js → workflow.command-gffk9nj9.js} +10 -10
  72. package/{workspace.command-qvwdqmnd.js → workspace.command-j1680trm.js} +33 -32
  73. package/TunnelShare-8qtffcex.js +0 -14
  74. package/cloud.script-fqp3zh02.js +0 -24
  75. package/context.runner-3jrypwe3.js +0 -25
@@ -2,19 +2,20 @@
2
2
  import {
3
3
  binPlatforms,
4
4
  ServerEnvProfile,
5
+ AkanAppConfig,
5
6
  Executor,
6
7
  WorkspaceExecutor
7
- } from "./index-rr7jk14m.js";
8
+ } from "./index-1e2955yd.js";
8
9
  import {
9
10
  resolveAppId,
10
11
  targetHtmlFilename
11
12
  } from "./index-m9jj544v.js";
12
13
  import {
13
14
  CsrArtifactBuilder
14
- } from "./index-q8age5az.js";
15
+ } from "./index-yknrmkmt.js";
15
16
  import {
16
17
  ExitCodeError
17
- } from "./index-p4dnj2wc.js";
18
+ } from "./index-qmeh0s05.js";
18
19
 
19
20
  // pkgs/@akanjs/devkit/mobile/desktopBin.ts
20
21
  import { chmod, mkdir, rename, rm, writeFile } from "fs/promises";
@@ -136,12 +137,486 @@ class DesktopBin {
136
137
  }
137
138
  }
138
139
 
139
- // pkgs/@akanjs/devkit/mobile/nativeApi.ts
140
+ // pkgs/@akanjs/devkit/mobile/desktopRelease.ts
141
+ import { mkdtemp as mkdtemp2, readFile, rm as rm3 } from "fs/promises";
142
+ import os2 from "os";
143
+ import path4 from "path";
144
+ import { isRecord as isRecord2, toError } from "akanjs/common";
145
+
146
+ // pkgs/@akanjs/devkit/mobile/tarWriter.ts
147
+ import { createHash } from "crypto";
148
+ import { open } from "fs/promises";
149
+
150
+ class TarWriter {
151
+ static #block = 512;
152
+ static #nameBytes = 100;
153
+ static #maxSize = 8 ** 11 - 1;
154
+ #handle;
155
+ #mtime;
156
+ constructor(handle, mtime) {
157
+ this.#handle = handle;
158
+ this.#mtime = mtime;
159
+ }
160
+ static async create(file, { mtime = 0 } = {}) {
161
+ return new TarWriter(await open(file, "wx"), mtime);
162
+ }
163
+ async add(name, source) {
164
+ const { size } = source;
165
+ if (size > TarWriter.#maxSize)
166
+ throw new Error(`${name} is ${size} bytes, more than a tar entry holds.`);
167
+ if (Buffer.byteLength(name) > TarWriter.#nameBytes) {
168
+ const pax = Buffer.from(TarWriter.#paxRecord("path", name));
169
+ await this.#write(TarWriter.#header(`./PaxHeaders/${name.split("/").at(-1) ?? ""}`, pax.length, this.#mtime, "x"));
170
+ await this.#write(pax);
171
+ await this.#pad(pax.length);
172
+ }
173
+ await this.#write(TarWriter.#header(name, size, this.#mtime, "0"));
174
+ const hasher = createHash("sha256");
175
+ let written = 0;
176
+ for await (const chunk of source.stream()) {
177
+ hasher.update(chunk);
178
+ await this.#write(chunk);
179
+ written += chunk.length;
180
+ }
181
+ if (written !== size)
182
+ throw new Error(`${name} changed while it was archived: ${written} bytes, not ${size}.`);
183
+ await this.#pad(size);
184
+ return hasher.digest("hex");
185
+ }
186
+ async close() {
187
+ await this.#write(new Uint8Array(TarWriter.#block * 2));
188
+ await this.#handle.close();
189
+ }
190
+ async discard() {
191
+ await this.#handle.close().catch(() => {
192
+ return;
193
+ });
194
+ }
195
+ async#write(bytes) {
196
+ for (let at = 0;at < bytes.length; )
197
+ at += (await this.#handle.write(bytes, at)).bytesWritten;
198
+ }
199
+ async#pad(size) {
200
+ const rest = size % TarWriter.#block;
201
+ if (rest)
202
+ await this.#write(new Uint8Array(TarWriter.#block - rest));
203
+ }
204
+ static #paxRecord(key, value) {
205
+ const body = Buffer.byteLength(` ${key}=${value}
206
+ `);
207
+ let length = body + 1;
208
+ while (body + String(length).length !== length)
209
+ length = body + String(length).length;
210
+ return `${length} ${key}=${value}
211
+ `;
212
+ }
213
+ static #header(name, size, mtime, type) {
214
+ const header = Buffer.alloc(TarWriter.#block);
215
+ header.write(name, 0, TarWriter.#nameBytes, "utf8");
216
+ const octal = (value, at, width) => header.write(`${value.toString(8).padStart(width - 1, "0")}\x00`, at, width, "latin1");
217
+ octal(420, 100, 8);
218
+ octal(0, 108, 8);
219
+ octal(0, 116, 8);
220
+ octal(size, 124, 12);
221
+ octal(mtime, 136, 12);
222
+ header.write(" ", 148, 8, "latin1");
223
+ header.write(type, 156, 1, "latin1");
224
+ header.write("ustar\x00", 257, 6, "latin1");
225
+ header.write("00", 263, 2, "latin1");
226
+ const checksum = header.reduce((sum, byte) => sum + byte, 0);
227
+ header.write(`${checksum.toString(8).padStart(6, "0")}\x00 `, 148, 8, "latin1");
228
+ return header;
229
+ }
230
+ }
231
+
232
+ // pkgs/@akanjs/devkit/mobile/updateUploader.ts
233
+ import { readdir } from "fs/promises";
234
+ import path3 from "path";
235
+ import { isRecord, trimTrailingSlashes } from "akanjs/common";
236
+
237
+ // pkgs/@akanjs/devkit/mobile/updatePackFolder.ts
238
+ import { mkdtemp, rm as rm2 } from "fs/promises";
239
+ import os from "os";
140
240
  import path2 from "path";
241
+ class UpdatePackFolder {
242
+ static packFile = "pack.json";
243
+ static compatFile = "compat.json";
244
+ static bundleFile = "bundle.json";
245
+ static templateFile = "manifest.template.json";
246
+ static filesDir = "files";
247
+ static #records = [
248
+ UpdatePackFolder.templateFile,
249
+ UpdatePackFolder.bundleFile,
250
+ UpdatePackFolder.packFile,
251
+ UpdatePackFolder.compatFile
252
+ ];
253
+ static #sha256 = /^[0-9a-f]{64}$/;
254
+ static async clear(dir) {
255
+ await Promise.all([UpdatePackFolder.packFile, UpdatePackFolder.compatFile].map((name) => rm2(path2.join(dir, name), { force: true })));
256
+ }
257
+ static async read(dir) {
258
+ const file = Bun.file(path2.join(dir, UpdatePackFolder.packFile));
259
+ if (!await file.exists())
260
+ throw new Error(`${dir} holds no ${UpdatePackFolder.packFile}: give the folder \`akan pack-update\` wrote.`);
261
+ const pack = await file.json();
262
+ if (pack.schema !== 1)
263
+ throw new Error(`${dir}/${UpdatePackFolder.packFile} is schema ${pack.schema}, and this akan reads schema 1.`);
264
+ return { ...pack, out: path2.resolve(dir) };
265
+ }
266
+ static async write({ out, ...record }) {
267
+ await Bun.write(path2.join(out, UpdatePackFolder.packFile), `${JSON.stringify(record, null, 2)}
268
+ `);
269
+ }
270
+ static async writeCompat(pack, compat) {
271
+ pack.compat = compat;
272
+ await Bun.write(path2.join(pack.out, UpdatePackFolder.compatFile), `${JSON.stringify(compat, null, 2)}
273
+ `);
274
+ }
275
+ static async readBundle(file) {
276
+ return await Bun.file(file).json();
277
+ }
278
+ static storeBuildVerdict({ out, compat }, then) {
279
+ if (!compat || compat.compatible)
280
+ return null;
281
+ return new ExitCodeError(`The pack in ${out} needs a new store build; it differs from the one ${compat.against} came from:
282
+ - ${compat.problems.join(`
283
+ - `)}${then ? `
284
+ ${then}` : ""}`, 2);
285
+ }
286
+ static async withArchive(pack, use) {
287
+ const { templateFile, filesDir } = UpdatePackFolder;
288
+ const template = Bun.file(path2.join(pack.out, templateFile));
289
+ if (!await template.exists())
290
+ throw new Error(`${pack.out} holds no ${templateFile}: give the folder \`akan pack-update\` wrote.`);
291
+ const { files = [] } = await template.json();
292
+ const hashes = [...new Set(files.map((file) => file.sha256))];
293
+ if (!hashes.every((hash) => typeof hash === "string" && UpdatePackFolder.#sha256.test(hash)))
294
+ throw new Error(`${pack.out}/${templateFile} lists a file whose sha256 is not 64 hex digits.`);
295
+ const present = await Promise.all(UpdatePackFolder.#records.map((name) => Bun.file(path2.join(pack.out, name)).exists()));
296
+ const entries = [
297
+ ...UpdatePackFolder.#records.filter((_, idx) => present[idx]),
298
+ ...hashes.map((hash) => `${filesDir}/${hash}`)
299
+ ];
300
+ const dir = await mkdtemp(path2.join(os.tmpdir(), "akan-pack-"));
301
+ try {
302
+ const tar = Bun.spawn(["tar", "-czf", "pack.tgz", "-C", pack.out, "-T", "-"], {
303
+ cwd: dir,
304
+ stdin: new Blob([entries.map((entry) => `./${entry}
305
+ `).join("")]),
306
+ stdout: "ignore",
307
+ stderr: "pipe"
308
+ });
309
+ const [code, stderr] = await Promise.all([tar.exited, new Response(tar.stderr).text()]);
310
+ if (code !== 0)
311
+ throw new Error(`tar of ${pack.out} failed: ${stderr.trim()}`);
312
+ return await use(path2.join(dir, "pack.tgz"));
313
+ } finally {
314
+ await rm2(dir, { recursive: true, force: true });
315
+ }
316
+ }
317
+ }
318
+
319
+ // pkgs/@akanjs/devkit/mobile/updateUploader.ts
320
+ class UpdateUploader {
321
+ bucket;
322
+ prefix;
323
+ static #manifest = /\.json(?:\.sig)?$/;
324
+ static parseTarget(target) {
325
+ const match = /^s3:\/\/([^/]+)(?:\/(.*))?$/.exec(target.trim());
326
+ if (!match?.[1])
327
+ throw new Error(`--upload takes s3://<bucket>/<prefix>, not ${JSON.stringify(target)}.`);
328
+ return { bucket: match[1], prefix: trimTrailingSlashes(match[2] ?? "") };
329
+ }
330
+ static order(files) {
331
+ const manifests = files.filter((file) => UpdateUploader.#manifest.test(file));
332
+ return {
333
+ releases: files.filter((file) => !UpdateUploader.#manifest.test(file)).sort((a, b) => a.localeCompare(b)),
334
+ manifests: manifests.sort((a, b) => Number(a.endsWith(".json")) - Number(b.endsWith(".json")) || a.localeCompare(b))
335
+ };
336
+ }
337
+ static async releaseFiles(updatesDir, { dir, channel, bundle }) {
338
+ const keyOf = (file) => UpdateUploader.#keyOf(updatesDir, dir, file);
339
+ const v1 = await UpdateUploader.#read(path3.join(dir, `${channel}.json`));
340
+ const pair = v1?.bundle === bundle ? [`${channel}.json.sig`, `${channel}.json`] : [];
341
+ const names = await readdir(path3.join(dir, channel)).catch(() => []);
342
+ for (const name of names.filter((name) => name.endsWith(".json"))) {
343
+ const envelope = await UpdateUploader.#read(path3.join(dir, channel, name));
344
+ const manifest = typeof envelope?.manifest === "string" ? UpdateUploader.#parse(Buffer.from(envelope.manifest, "base64").toString("utf8")) : null;
345
+ if (manifest?.bundle !== bundle)
346
+ continue;
347
+ if (manifest.kind === "app")
348
+ return [...UpdateUploader.#appFiles(manifest), ...pair, `${channel}/${name}`].map(keyOf);
349
+ const hashes = [...new Set(UpdateUploader.#field(manifest.files, "sha256"))];
350
+ if (!hashes.every((hash) => typeof hash === "string" && /^[0-9a-f]{64}$/.test(hash)))
351
+ throw new Error(`${path3.join(dir, channel, name)} lists a file whose sha256 is not 64 hex digits; nothing was uploaded.`);
352
+ return [...hashes.map((hash) => `${UpdatePackFolder.filesDir}/${hash}`), `${channel}/${name}`].map(keyOf);
353
+ }
354
+ if (v1 && pair.length)
355
+ return [...UpdateUploader.#appFiles(v1), ...pair].map(keyOf);
356
+ throw new Error(`${dir} holds no ${channel} manifest of release ${bundle}; nothing was uploaded.`);
357
+ }
358
+ static #appFiles(manifest) {
359
+ return [manifest.archive?.url, ...UpdateUploader.#field(manifest.patches, "url")];
360
+ }
361
+ static #keyOf(updatesDir, dir, file) {
362
+ const resolved = typeof file === "string" ? path3.resolve(dir, file) : "";
363
+ const key = path3.relative(updatesDir, resolved);
364
+ if (!resolved.startsWith(`${path3.resolve(dir)}${path3.sep}`) || key.startsWith("..") || path3.isAbsolute(key))
365
+ throw new Error(`The release in ${dir} names ${typeof file === "string" ? JSON.stringify(file) : "a file with no path"}, which is not inside that folder; nothing was uploaded.`);
366
+ return key.split(path3.sep).join("/");
367
+ }
368
+ static #field(list, key) {
369
+ return Array.isArray(list) ? list.map((item) => isRecord(item) ? item[key] : undefined) : [];
370
+ }
371
+ static async#read(file) {
372
+ const text = await Bun.file(file).text().catch(() => "");
373
+ return UpdateUploader.#parse(text);
374
+ }
375
+ static #parse(text) {
376
+ try {
377
+ const value = JSON.parse(text);
378
+ return isRecord(value) ? value : null;
379
+ } catch {
380
+ return null;
381
+ }
382
+ }
383
+ constructor(bucket, prefix) {
384
+ this.bucket = bucket;
385
+ this.prefix = prefix;
386
+ }
387
+ static forTarget(target) {
388
+ const { bucket, prefix } = UpdateUploader.parseTarget(target);
389
+ return new UpdateUploader(new Bun.S3Client({ bucket }), prefix);
390
+ }
391
+ async upload(updatesDir, release) {
392
+ const { releases, manifests } = UpdateUploader.order(await UpdateUploader.releaseFiles(updatesDir, release));
393
+ const keyOf = (file) => this.prefix ? `${this.prefix}/${file}` : file;
394
+ let uploaded = 0;
395
+ let skipped = 0;
396
+ for (const file of releases) {
397
+ if (await this.bucket.exists(keyOf(file))) {
398
+ skipped++;
399
+ continue;
400
+ }
401
+ await this.bucket.write(keyOf(file), Bun.file(path3.join(updatesDir, file)));
402
+ uploaded++;
403
+ }
404
+ for (const file of manifests) {
405
+ const type = file.endsWith(".json") ? "application/json" : "text/plain";
406
+ await this.bucket.write(keyOf(file), Bun.file(path3.join(updatesDir, file)), { type });
407
+ uploaded++;
408
+ }
409
+ return { uploaded, skipped };
410
+ }
411
+ }
412
+
413
+ // pkgs/@akanjs/devkit/mobile/desktopRelease.ts
414
+ class DesktopRelease {
415
+ dir;
416
+ manifest;
417
+ payloads;
418
+ platform;
419
+ arch;
420
+ channel;
421
+ manifestFiles;
422
+ static #authenticode = `$ErrorActionPreference = 'Stop'
423
+ $ProgressPreference = 'SilentlyContinue'
424
+ $signature = Get-AuthenticodeSignature -LiteralPath $env:AKAN_RELEASE_EXE
425
+ $subject = if ("$($signature.Status)" -ceq 'Valid') { "$($signature.SignerCertificate.Subject)" } else { '' }
426
+ Set-Content -LiteralPath $env:AKAN_SIGNER_OUT -Value $subject -Encoding UTF8`;
427
+ constructor(dir, manifest, payloads, platform, arch, channel, manifestFiles) {
428
+ this.dir = dir;
429
+ this.manifest = manifest;
430
+ this.payloads = payloads;
431
+ this.platform = platform;
432
+ this.arch = arch;
433
+ this.channel = channel;
434
+ this.manifestFiles = manifestFiles;
435
+ }
436
+ static async read(updatesDir, {
437
+ platform,
438
+ arch,
439
+ channel,
440
+ appId,
441
+ target,
442
+ publicKeys,
443
+ revokedKeys = [],
444
+ api
445
+ }) {
446
+ const folder = `${platform}-${arch}`;
447
+ const dir = path4.join(updatesDir, folder);
448
+ const envelopeName = `${channel}/app.json`;
449
+ const envelopePath = path4.join(dir, channel, "app.json");
450
+ const envelope = await readFile(envelopePath).catch(() => null);
451
+ if (!envelope)
452
+ throw new Error(`${envelopePath} is missing: run \`akan publish-update\` first.`);
453
+ const opened = DesktopRelease.#open(api, envelope, publicKeys, revokedKeys);
454
+ if (typeof opened === "string")
455
+ throw new Error(`${envelopePath}: ${opened}; publish the release again.`);
456
+ const manifest = DesktopRelease.#parse(opened);
457
+ if (manifest?.schema !== 2 || manifest.kind !== "app" || manifest.app !== appId || manifest.platform !== platform || manifest.arch !== arch || manifest.channel !== channel || manifest.target !== target || typeof manifest.bundle !== "string" || typeof manifest.sequence !== "number" || typeof manifest.build !== "number" || !manifest.archive)
458
+ throw new Error(`${envelopePath} is not a release of ${appId}${target ? ` target ${target}` : ""} for ${folder} on channel ${channel}.`);
459
+ const { archive, bundle, sequence, build } = manifest;
460
+ const legacy = await DesktopRelease.#legacyPair(api, dir, channel, publicKeys[0], manifest);
461
+ const keys = await UpdateUploader.releaseFiles(updatesDir, { dir, channel, bundle });
462
+ const expected = new Map([{ url: archive.url, size: archive.size, sha256: archive.gzSha256 }, ...manifest.patches ?? []].map(({ url, size, sha256 }) => [path4.posix.normalize(url), { size, sha256 }]));
463
+ const payloads = keys.flatMap((key) => {
464
+ const name = key.slice(folder.length + 1);
465
+ const digest = expected.get(name);
466
+ return digest ? [{ name, ...digest }] : [];
467
+ });
468
+ return new DesktopRelease(dir, { ...manifest, archive, bundle, sequence, build }, payloads, platform, arch, channel, [{ name: envelopeName, bytes: envelope }, ...legacy]);
469
+ }
470
+ static async#legacyPair(api, dir, channel, publicKey, manifest) {
471
+ const [bytes, signature] = await Promise.all([`${channel}.json`, `${channel}.json.sig`].map((name) => readFile(path4.join(dir, name)).catch(() => null)));
472
+ if (!bytes || !signature || !publicKey)
473
+ return [];
474
+ const v1 = DesktopRelease.#parse(bytes);
475
+ if (v1?.schema !== 1 || v1.bundle !== manifest.bundle || v1.sequence !== manifest.sequence)
476
+ return [];
477
+ if (!api.verifyManifest(bytes, new TextDecoder().decode(signature).trim(), publicKey))
478
+ return [];
479
+ return [
480
+ { name: `${channel}.json`, bytes },
481
+ { name: `${channel}.json.sig`, bytes: signature }
482
+ ];
483
+ }
484
+ record(signer) {
485
+ const { platform, arch, channel } = this;
486
+ const builtAt = new Date(this.manifest.build * 1000).toISOString();
487
+ return { schema: 2, cli: AkanAppConfig.akanVersion, platform, arch, channel, signer, builtAt };
488
+ }
489
+ async withArchive(record, use) {
490
+ const tmp = await mkdtemp2(path4.join(os2.tmpdir(), "akan-release-"));
491
+ try {
492
+ const archive = path4.join(tmp, "release.tar");
493
+ const tar = await TarWriter.create(archive, { mtime: this.manifest.sequence });
494
+ try {
495
+ await tar.add("./release.json", new Blob([`${JSON.stringify(record, null, 2)}
496
+ `]));
497
+ for (const { name, bytes } of this.manifestFiles)
498
+ await tar.add(`./${name}`, new Blob([bytes]));
499
+ for (const { name, size, sha256 } of this.payloads) {
500
+ const file = Bun.file(path4.join(this.dir, name));
501
+ const what = `${path4.join(this.dir, name)} is not the file ${this.channel}/app.json names`;
502
+ if (!await file.exists() || file.size !== size)
503
+ throw new Error(`${what}: publish the release again.`);
504
+ if (await tar.add(`./${name}`, file) !== sha256)
505
+ throw new Error(`${what} (its sha256 differs).`);
506
+ }
507
+ await tar.close();
508
+ } catch (error) {
509
+ await tar.discard();
510
+ throw error;
511
+ }
512
+ return await use(archive);
513
+ } finally {
514
+ await rm3(tmp, { recursive: true, force: true });
515
+ }
516
+ }
517
+ async signer({
518
+ exeName,
519
+ host = process.platform,
520
+ run = DesktopRelease.#run
521
+ }) {
522
+ if (this.platform === "linux")
523
+ return { signer: null, unread: null };
524
+ const app = this.manifest.files?.[0]?.path;
525
+ if (!app || !/^[^/\\]+$/.test(app) || app === "." || app === "..")
526
+ return { signer: null, unread: `${this.channel}/app.json names no app folder` };
527
+ if (this.platform === "macos" && host !== "darwin")
528
+ return { signer: null, unread: "codesign reads a macOS app's signer on macOS only" };
529
+ if (this.platform === "windows" && host !== "win32")
530
+ return { signer: null, unread: "PowerShell reads a Windows app's Authenticode signer on Windows only" };
531
+ const tmp = await mkdtemp2(path4.join(os2.tmpdir(), "akan-signer-"));
532
+ try {
533
+ const archive = path4.join(this.dir, this.manifest.archive.url);
534
+ return this.platform === "macos" ? await DesktopRelease.#teamOf(run, archive, tmp, app) : await DesktopRelease.#subjectOf(run, archive, tmp, path4.posix.join(app, `${exeName}.exe`));
535
+ } finally {
536
+ await rm3(tmp, { recursive: true, force: true });
537
+ }
538
+ }
539
+ static async#teamOf(run, archive, tmp, app) {
540
+ const contents = `${app}/Contents`;
541
+ await run([
542
+ "/usr/bin/tar",
543
+ "-xzf",
544
+ archive,
545
+ "-C",
546
+ tmp,
547
+ ...["Info.plist", "MacOS/*", "_CodeSignature/*"].flatMap((entry) => ["--include", `${contents}/${entry}`])
548
+ ]);
549
+ if (!await Bun.file(path4.join(tmp, contents, "Info.plist")).exists())
550
+ return { signer: null, unread: `the archive holds no ${contents}/Info.plist` };
551
+ const { output } = await run(["/usr/bin/codesign", "--display", "--verbose=2", path4.join(tmp, app)]);
552
+ const teamId = /^TeamIdentifier=([A-Z0-9]{10})$/m.exec(output)?.[1];
553
+ if (teamId)
554
+ return { signer: { teamId }, unread: null };
555
+ if (/^TeamIdentifier=not set$/m.test(output) || /code object is not signed at all/.test(output))
556
+ return { signer: null, unread: null };
557
+ return { signer: null, unread: `codesign could not read ${app}: ${output.trim().split(`
558
+ `)[0] ?? ""}` };
559
+ }
560
+ static async#subjectOf(run, archive, tmp, exe) {
561
+ const tar = path4.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe");
562
+ await run([tar, "-xzf", archive, "-C", tmp, exe]);
563
+ const extracted = path4.join(tmp, exe);
564
+ if (!await Bun.file(extracted).exists())
565
+ return { signer: null, unread: `the archive holds no ${exe}` };
566
+ const out = path4.join(tmp, "signer.txt");
567
+ const { code } = await run([
568
+ path4.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
569
+ "-NoProfile",
570
+ "-NonInteractive",
571
+ "-EncodedCommand",
572
+ Buffer.from(DesktopRelease.#authenticode, "utf16le").toString("base64")
573
+ ], { env: { AKAN_RELEASE_EXE: extracted, AKAN_SIGNER_OUT: out } });
574
+ if (code !== 0)
575
+ return { signer: null, unread: `PowerShell could not read the Authenticode signature of ${exe}` };
576
+ const subject = (await readFile(out, "utf8").catch(() => "")).replace(/^\uFEFF/, "").trim();
577
+ return { signer: subject ? { subject } : null, unread: null };
578
+ }
579
+ static #open(api, envelope, publicKeys, revokedKeys) {
580
+ try {
581
+ return api.openEnvelope(new TextDecoder().decode(envelope), publicKeys, revokedKeys).manifest;
582
+ } catch (error) {
583
+ return toError(error).message;
584
+ }
585
+ }
586
+ static #parse(bytes) {
587
+ try {
588
+ const value = JSON.parse(new TextDecoder().decode(bytes));
589
+ return isRecord2(value) ? value : null;
590
+ } catch {
591
+ return null;
592
+ }
593
+ }
594
+ static async#run(cmd, { env } = {}) {
595
+ try {
596
+ const proc = Bun.spawn(cmd, {
597
+ env: { ...process.env, ...env },
598
+ stdin: "ignore",
599
+ stdout: "pipe",
600
+ stderr: "pipe"
601
+ });
602
+ const [code, stdout, stderr] = await Promise.all([
603
+ proc.exited,
604
+ new Response(proc.stdout).text(),
605
+ new Response(proc.stderr).text()
606
+ ]);
607
+ return { code, output: `${stdout}${stderr}` };
608
+ } catch (error) {
609
+ return { code: -1, output: toError(error).message };
610
+ }
611
+ }
612
+ }
613
+
614
+ // pkgs/@akanjs/devkit/mobile/nativeApi.ts
615
+ import path5 from "path";
141
616
 
142
617
  class NativeApi {
143
618
  static supportedMajor = 0;
144
- static minimumVersion = "0.12.0";
619
+ static minimumVersion = "0.13.0";
145
620
  static entryOf(appDir) {
146
621
  const workspaceEntry = NativeApi.#resolve("@akanjs/native/api", appDir);
147
622
  if (workspaceEntry)
@@ -149,7 +624,7 @@ class NativeApi {
149
624
  const akanjsPackage = NativeApi.#resolve("akanjs/package.json", appDir);
150
625
  if (!akanjsPackage)
151
626
  throw new Error(`akanjs is not installed for ${appDir}; the native build ships inside it.`);
152
- return path2.join(path2.dirname(akanjsPackage), "vendor", "@akanjs", "native", "packages", "cli", "src", "api.ts");
627
+ return path5.join(path5.dirname(akanjsPackage), "vendor", "@akanjs", "native", "packages", "cli", "src", "api.ts");
153
628
  }
154
629
  static async load(appDir) {
155
630
  const entry = NativeApi.entryOf(appDir);
@@ -171,8 +646,8 @@ class NativeApi {
171
646
  }
172
647
 
173
648
  // pkgs/@akanjs/devkit/mobile/nativeApp.ts
174
- import path8 from "path";
175
- import { toError } from "akanjs/common";
649
+ import path10 from "path";
650
+ import { toError as toError2 } from "akanjs/common";
176
651
 
177
652
  // pkgs/@akanjs/devkit/mobile/nativeAppLine.ts
178
653
  class NativeAppLine {
@@ -231,7 +706,7 @@ class NativeAppLine {
231
706
 
232
707
  // pkgs/@akanjs/devkit/mobile/nativeConfig.ts
233
708
  import { readFileSync } from "fs";
234
- import path3 from "path";
709
+ import path6 from "path";
235
710
  import { trimSlashes } from "akanjs/common";
236
711
 
237
712
  // pkgs/@akanjs/devkit/mobile/usageDescriptions.ts
@@ -314,11 +789,11 @@ class NativeConfig {
314
789
  warnings.push(`Permission '${permission}' has no native plugin yet; the app ships without it.`);
315
790
  return used;
316
791
  });
317
- const abs = (relative) => path3.resolve(appPath, relative);
792
+ const abs = (relative) => path6.resolve(appPath, relative);
318
793
  const updates = NativeConfig.#updates(target, env);
319
- const folders = new Set(nativePlugins.map((plugin) => path3.resolve(plugin.dir)));
794
+ const folders = new Set(nativePlugins.map((plugin) => path6.resolve(plugin.dir)));
320
795
  const folderIds = new Set(nativePlugins.map((plugin) => plugin.id));
321
- const listed = (target.plugins ?? []).filter((spec) => NativeConfig.#isId(spec) ? !folderIds.has(spec) : !folders.has(path3.resolve(appPath, spec)));
796
+ const listed = (target.plugins ?? []).filter((spec) => NativeConfig.#isId(spec) ? !folderIds.has(spec) : !folders.has(path6.resolve(appPath, spec)));
322
797
  const plugins = [
323
798
  ...new Set([
324
799
  ...NativeConfig.basePlugins,
@@ -374,7 +849,7 @@ class NativeConfig {
374
849
  app: {
375
850
  id: resolveAppId(target.appId, platform),
376
851
  name: target.appName,
377
- fileName: target.fileName ?? NativeConfig.fileNameOf(path3.basename(appPath)),
852
+ fileName: target.fileName ?? NativeConfig.fileNameOf(path6.basename(appPath)),
378
853
  version: target.version,
379
854
  build: target.buildNum
380
855
  },
@@ -431,7 +906,7 @@ class NativeConfig {
431
906
  static #updates(target, env) {
432
907
  const { url, publicKey, publicKeys, channel = env, ...rest } = target.updates ?? {};
433
908
  const keys = publicKeys ? { publicKeys: [...publicKeys] } : publicKey ? { publicKey } : null;
434
- return url && keys ? { ...rest, url, ...keys, ...channel ? { channel } : {} } : undefined;
909
+ return url && keys ? { ...rest, url, ...keys, ...channel ? { channel } : {}, target: target.name } : undefined;
435
910
  }
436
911
  static fileNameOf(name) {
437
912
  return /[^-.](?:.*[^-.])?/.exec(name.replace(/[^A-Za-z0-9._-]/g, "-"))?.[0] ?? "app";
@@ -440,14 +915,14 @@ class NativeConfig {
440
915
  if (NativeConfig.#isId(spec))
441
916
  return spec;
442
917
  try {
443
- const { id } = JSON.parse(readFileSync(path3.join(path3.resolve(appPath, spec), "native-plugin.json"), "utf8"));
918
+ const { id } = JSON.parse(readFileSync(path6.join(path6.resolve(appPath, spec), "native-plugin.json"), "utf8"));
444
919
  return typeof id === "string" ? id : spec;
445
920
  } catch {
446
921
  return spec;
447
922
  }
448
923
  }
449
924
  static #isId(spec) {
450
- return !spec.startsWith(".") && !path3.isAbsolute(spec);
925
+ return !spec.startsWith(".") && !path6.isAbsolute(spec);
451
926
  }
452
927
  static #compact(value) {
453
928
  const kept = Object.entries(value).filter(([, entry]) => Array.isArray(entry) ? entry.length > 0 : entry && typeof entry === "object" ? Object.keys(entry).length > 0 : entry !== undefined);
@@ -467,24 +942,24 @@ class NativeConfig {
467
942
  }
468
943
 
469
944
  // pkgs/@akanjs/devkit/mobile/nativePluginFolders.ts
470
- import { readdir } from "fs/promises";
471
- import path4 from "path";
945
+ import { readdir as readdir2 } from "fs/promises";
946
+ import path7 from "path";
472
947
 
473
948
  class NativePluginFolders {
474
949
  static folder = "native";
475
950
  static async in(root, owner) {
476
- const base = path4.join(root, NativePluginFolders.folder);
477
- const entries = await readdir(base, { withFileTypes: true }).catch(() => []);
951
+ const base = path7.join(root, NativePluginFolders.folder);
952
+ const entries = await readdir2(base, { withFileTypes: true }).catch(() => []);
478
953
  const folders = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
479
954
  return await Promise.all(folders.sort().map(async (name) => {
480
955
  const where = `${owner}/${NativePluginFolders.folder}/${name}`;
481
- const manifest = Bun.file(path4.join(base, name, "native-plugin.json"));
956
+ const manifest = Bun.file(path7.join(base, name, "native-plugin.json"));
482
957
  if (!await manifest.exists())
483
958
  throw new Error(`${where} has no native-plugin.json; a folder in native/ is one native plugin.`);
484
959
  const { id } = await manifest.json();
485
960
  if (id !== name)
486
961
  throw new Error(`${where}/native-plugin.json has id ${JSON.stringify(id)}; name the folder after its id.`);
487
- return { id, dir: path4.join(base, name), owner };
962
+ return { id, dir: path7.join(base, name), owner };
488
963
  }));
489
964
  }
490
965
  static select(own, fromLibs) {
@@ -503,14 +978,14 @@ class NativePluginFolders {
503
978
  const root = app.workspace.workspaceRoot;
504
979
  const [own, ...fromLibs] = await Promise.all([
505
980
  NativePluginFolders.in(app.cwdPath, `apps/${app.name}`),
506
- ...scanInfo.getLibs().map((lib) => NativePluginFolders.in(path4.join(root, "libs", lib), `libs/${lib}`))
981
+ ...scanInfo.getLibs().map((lib) => NativePluginFolders.in(path7.join(root, "libs", lib), `libs/${lib}`))
507
982
  ]);
508
983
  return NativePluginFolders.select(own ?? [], fromLibs.flat());
509
984
  }
510
985
  }
511
986
 
512
987
  // pkgs/@akanjs/devkit/mobile/nativePublicEnv.ts
513
- import { createHash } from "crypto";
988
+ import { createHash as createHash2 } from "crypto";
514
989
  class NativePublicEnv {
515
990
  static derivedKeys = [
516
991
  "AKAN_PUBLIC_APP_NAME",
@@ -529,7 +1004,7 @@ class NativePublicEnv {
529
1004
  return Object.fromEntries(Object.keys(env).filter((key) => key.startsWith("AKAN_PUBLIC_") && !NativePublicEnv.derivedKeys.includes(key)).sort().map((key) => [key, String(env[key])]));
530
1005
  }
531
1006
  static hash(publicEnv) {
532
- return createHash("sha256").update(JSON.stringify(NativePublicEnv.of(publicEnv))).digest("hex");
1007
+ return createHash2("sha256").update(JSON.stringify(NativePublicEnv.of(publicEnv))).digest("hex");
533
1008
  }
534
1009
  static problems(publicEnv) {
535
1010
  const keys = Object.keys(publicEnv);
@@ -609,8 +1084,8 @@ class NativePublicEnv {
609
1084
  }
610
1085
 
611
1086
  // pkgs/@akanjs/devkit/mobile/nativeWebDir.ts
612
- import { cp, mkdir as mkdir2, rm as rm2, stat } from "fs/promises";
613
- import path5 from "path";
1087
+ import { cp, mkdir as mkdir2, rm as rm4, stat } from "fs/promises";
1088
+ import path8 from "path";
614
1089
  import { trimSlashes as trimSlashes2 } from "akanjs/common";
615
1090
 
616
1091
  class NativeWebDir {
@@ -638,7 +1113,7 @@ ${script}${html.slice(at)}`;
638
1113
  }
639
1114
  static #targetTag = "<script>window.__AKAN_MOBILE_TARGET__=";
640
1115
  async clear() {
641
- await rm2(this.dir, { recursive: true, force: true });
1116
+ await rm4(this.dir, { recursive: true, force: true });
642
1117
  await mkdir2(this.dir, { recursive: true });
643
1118
  }
644
1119
  async assemble(target, { html, publicDir, fontsDir }) {
@@ -648,12 +1123,12 @@ ${script}${html.slice(at)}`;
648
1123
  if (publicDir && await NativeWebDir.#isDir(publicDir))
649
1124
  await cp(publicDir, this.dir, { recursive: true });
650
1125
  if (fontsDir && await NativeWebDir.#isDir(fontsDir))
651
- await cp(fontsDir, path5.join(this.dir, "_akan", "fonts"), { recursive: true });
652
- if (await NativeWebDir.#isDir(path5.join(this.dir, NativeWebDir.reservedEntry)))
1126
+ await cp(fontsDir, path8.join(this.dir, "_akan", "fonts"), { recursive: true });
1127
+ if (await NativeWebDir.#isDir(path8.join(this.dir, NativeWebDir.reservedEntry)))
653
1128
  throw new Error(`public/${NativeWebDir.reservedEntry} is reserved for the native runtime.`);
654
- await Bun.write(path5.join(this.dir, "index.html"), NativeWebDir.injectTarget(await Bun.file(html).text(), target));
1129
+ await Bun.write(path8.join(this.dir, "index.html"), NativeWebDir.injectTarget(await Bun.file(html).text(), target));
655
1130
  const files = await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: this.dir, onlyFiles: true, dot: true }));
656
- return files.map((file) => file.split(path5.sep).join("/")).sort();
1131
+ return files.map((file) => file.split(path8.sep).join("/")).sort();
657
1132
  }
658
1133
  static async#isDir(dir) {
659
1134
  try {
@@ -665,8 +1140,8 @@ ${script}${html.slice(at)}`;
665
1140
  }
666
1141
 
667
1142
  // pkgs/@akanjs/devkit/mobile/serverBundleSecrets.ts
668
- import { readdir as readdir2, readFile, stat as stat2 } from "fs/promises";
669
- import path6 from "path";
1143
+ import { readdir as readdir3, readFile as readFile2, stat as stat2 } from "fs/promises";
1144
+ import path9 from "path";
670
1145
  class ServerBundleSecrets {
671
1146
  workspaceRoot;
672
1147
  appDir;
@@ -678,8 +1153,8 @@ class ServerBundleSecrets {
678
1153
  this.appDir = appDir;
679
1154
  }
680
1155
  async envFiles() {
681
- const dirs = [path6.join(this.appDir, "env"), ...(await this.#libDirs()).map((lib) => path6.join(lib, "env"))];
682
- const files = await Promise.all(dirs.map(async (dir) => (await readdir2(dir).catch(() => [])).filter((name) => /^env\.server\.[A-Za-z0-9.-]+\.ts$/.test(name) && !/\.(type|example)\.ts$/.test(name)).map((name) => path6.join(dir, name))));
1156
+ const dirs = [path9.join(this.appDir, "env"), ...(await this.#libDirs()).map((lib) => path9.join(lib, "env"))];
1157
+ const files = await Promise.all(dirs.map(async (dir) => (await readdir3(dir).catch(() => [])).filter((name) => /^env\.server\.[A-Za-z0-9.-]+\.ts$/.test(name) && !/\.(type|example)\.ts$/.test(name)).map((name) => path9.join(dir, name))));
683
1158
  return files.flat();
684
1159
  }
685
1160
  async assertClean(bundleDir) {
@@ -687,7 +1162,7 @@ class ServerBundleSecrets {
687
1162
  const secrets = [];
688
1163
  for (const file of await this.envFiles()) {
689
1164
  try {
690
- const value = await ServerEnvProfile.evaluate(file, path6.dirname(path6.dirname(file)));
1165
+ const value = await ServerEnvProfile.evaluate(file, path9.dirname(path9.dirname(file)));
691
1166
  secrets.push(...ServerEnvProfile.secretValues(value).map((secret) => ({ file, ...secret })));
692
1167
  } catch {
693
1168
  unread.push(ServerBundleSecrets.#relative(this.workspaceRoot, file));
@@ -698,7 +1173,7 @@ class ServerBundleSecrets {
698
1173
  const sought = secrets.map((secret) => ({ secret, needles: ServerBundleSecrets.#needles(secret.value) }));
699
1174
  const found = [];
700
1175
  for (const bundled of await ServerBundleSecrets.#files(bundleDir)) {
701
- const text = await readFile(bundled, "latin1");
1176
+ const text = await readFile2(bundled, "latin1");
702
1177
  for (const { secret, needles } of sought)
703
1178
  if (needles.some((needle) => text.includes(needle)))
704
1179
  found.push({ bundled, secret });
@@ -719,7 +1194,7 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
719
1194
  return coded;
720
1195
  for (const dir of [this.appDir, ...await this.#libDirs()])
721
1196
  for (const file of await ServerBundleSecrets.#sources(dir)) {
722
- const text = await readFile(file, "utf8");
1197
+ const text = await readFile2(file, "utf8");
723
1198
  for (const value of plain)
724
1199
  if (text.includes(value))
725
1200
  coded.add(value);
@@ -727,8 +1202,8 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
727
1202
  return coded;
728
1203
  }
729
1204
  async#libDirs() {
730
- const libsDir = path6.join(this.workspaceRoot, "libs");
731
- return (await readdir2(libsDir).catch(() => [])).map((lib) => path6.join(libsDir, lib));
1205
+ const libsDir = path9.join(this.workspaceRoot, "libs");
1206
+ return (await readdir3(libsDir).catch(() => [])).map((lib) => path9.join(libsDir, lib));
732
1207
  }
733
1208
  static #needles(value) {
734
1209
  const escaped = JSON.stringify(value).slice(1, -1);
@@ -741,12 +1216,12 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
741
1216
  return /^export default (["'`])([\s\S]*)\1;?\s*$/.exec(code)?.[2] ?? value;
742
1217
  }
743
1218
  static #relative(from, to) {
744
- return path6.relative(from, to).split(path6.sep).join("/");
1219
+ return path9.relative(from, to).split(path9.sep).join("/");
745
1220
  }
746
1221
  static async#files(dir) {
747
1222
  const files = [];
748
- for (const entry of await readdir2(dir, { withFileTypes: true })) {
749
- const file = path6.join(dir, entry.name);
1223
+ for (const entry of await readdir3(dir, { withFileTypes: true })) {
1224
+ const file = path9.join(dir, entry.name);
750
1225
  if (entry.isDirectory()) {
751
1226
  if (entry.name !== "node_modules")
752
1227
  files.push(...await ServerBundleSecrets.#files(file));
@@ -757,10 +1232,10 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
757
1232
  }
758
1233
  static async#sources(dir) {
759
1234
  const files = [];
760
- for (const entry of await readdir2(dir, { withFileTypes: true }).catch(() => [])) {
1235
+ for (const entry of await readdir3(dir, { withFileTypes: true }).catch(() => [])) {
761
1236
  if (entry.name.startsWith("."))
762
1237
  continue;
763
- const file = path6.join(dir, entry.name);
1238
+ const file = path9.join(dir, entry.name);
764
1239
  if (entry.isDirectory()) {
765
1240
  if (!ServerBundleSecrets.#notSource.has(entry.name))
766
1241
  files.push(...await ServerBundleSecrets.#sources(file));
@@ -771,88 +1246,6 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
771
1246
  }
772
1247
  }
773
1248
 
774
- // pkgs/@akanjs/devkit/mobile/updatePackFolder.ts
775
- import { mkdtemp, rm as rm3 } from "fs/promises";
776
- import os from "os";
777
- import path7 from "path";
778
- class UpdatePackFolder {
779
- static packFile = "pack.json";
780
- static compatFile = "compat.json";
781
- static bundleFile = "bundle.json";
782
- static templateFile = "manifest.template.json";
783
- static filesDir = "files";
784
- static #records = [
785
- UpdatePackFolder.templateFile,
786
- UpdatePackFolder.bundleFile,
787
- UpdatePackFolder.packFile,
788
- UpdatePackFolder.compatFile
789
- ];
790
- static #sha256 = /^[0-9a-f]{64}$/;
791
- static async clear(dir) {
792
- await Promise.all([UpdatePackFolder.packFile, UpdatePackFolder.compatFile].map((name) => rm3(path7.join(dir, name), { force: true })));
793
- }
794
- static async read(dir) {
795
- const file = Bun.file(path7.join(dir, UpdatePackFolder.packFile));
796
- if (!await file.exists())
797
- throw new Error(`${dir} holds no ${UpdatePackFolder.packFile}: give the folder \`akan pack-update\` wrote.`);
798
- const pack = await file.json();
799
- if (pack.schema !== 1)
800
- throw new Error(`${dir}/${UpdatePackFolder.packFile} is schema ${pack.schema}, and this akan reads schema 1.`);
801
- return { ...pack, out: path7.resolve(dir) };
802
- }
803
- static async write({ out, ...record }) {
804
- await Bun.write(path7.join(out, UpdatePackFolder.packFile), `${JSON.stringify(record, null, 2)}
805
- `);
806
- }
807
- static async writeCompat(pack, compat) {
808
- pack.compat = compat;
809
- await Bun.write(path7.join(pack.out, UpdatePackFolder.compatFile), `${JSON.stringify(compat, null, 2)}
810
- `);
811
- }
812
- static async readBundle(file) {
813
- return await Bun.file(file).json();
814
- }
815
- static storeBuildVerdict({ out, compat }, then) {
816
- if (!compat || compat.compatible)
817
- return null;
818
- return new ExitCodeError(`The pack in ${out} needs a new store build; it differs from the one ${compat.against} came from:
819
- - ${compat.problems.join(`
820
- - `)}${then ? `
821
- ${then}` : ""}`, 2);
822
- }
823
- static async withArchive(pack, use) {
824
- const { templateFile, filesDir } = UpdatePackFolder;
825
- const template = Bun.file(path7.join(pack.out, templateFile));
826
- if (!await template.exists())
827
- throw new Error(`${pack.out} holds no ${templateFile}: give the folder \`akan pack-update\` wrote.`);
828
- const { files = [] } = await template.json();
829
- const hashes = [...new Set(files.map((file) => file.sha256))];
830
- if (!hashes.every((hash) => typeof hash === "string" && UpdatePackFolder.#sha256.test(hash)))
831
- throw new Error(`${pack.out}/${templateFile} lists a file whose sha256 is not 64 hex digits.`);
832
- const present = await Promise.all(UpdatePackFolder.#records.map((name) => Bun.file(path7.join(pack.out, name)).exists()));
833
- const entries = [
834
- ...UpdatePackFolder.#records.filter((_, idx) => present[idx]),
835
- ...hashes.map((hash) => `${filesDir}/${hash}`)
836
- ];
837
- const dir = await mkdtemp(path7.join(os.tmpdir(), "akan-pack-"));
838
- try {
839
- const tar = Bun.spawn(["tar", "-czf", "pack.tgz", "-C", pack.out, "-T", "-"], {
840
- cwd: dir,
841
- stdin: new Blob([entries.map((entry) => `./${entry}
842
- `).join("")]),
843
- stdout: "ignore",
844
- stderr: "pipe"
845
- });
846
- const [code, stderr] = await Promise.all([tar.exited, new Response(tar.stderr).text()]);
847
- if (code !== 0)
848
- throw new Error(`tar of ${pack.out} failed: ${stderr.trim()}`);
849
- return await use(path7.join(dir, "pack.tgz"));
850
- } finally {
851
- await rm3(dir, { recursive: true, force: true });
852
- }
853
- }
854
- }
855
-
856
1249
  // pkgs/@akanjs/devkit/mobile/nativeApp.ts
857
1250
  class NativeApp {
858
1251
  app;
@@ -865,14 +1258,14 @@ class NativeApp {
865
1258
  this.app = app;
866
1259
  this.target = target;
867
1260
  this.env = env;
868
- this.targetRoot = path8.join(app.workspace.workspaceRoot, "dist", "native", app.name, target.name);
869
- this.web = new NativeWebDir(path8.join(this.targetRoot, "web"));
1261
+ this.targetRoot = path10.join(app.workspace.workspaceRoot, "dist", "native", app.name, target.name);
1262
+ this.web = new NativeWebDir(path10.join(this.targetRoot, "web"));
870
1263
  }
871
1264
  outDir(platform) {
872
- return path8.join(this.targetRoot, "build", platform);
1265
+ return path10.join(this.targetRoot, "build", platform);
873
1266
  }
874
1267
  devOutDir(platform) {
875
- return path8.join(this.targetRoot, "dev", platform);
1268
+ return path10.join(this.targetRoot, "dev", platform);
876
1269
  }
877
1270
  indexPath(platform) {
878
1271
  const { config } = this.target;
@@ -882,13 +1275,13 @@ class NativeApp {
882
1275
  async assembleWeb(platform) {
883
1276
  const dist = this.app.dist.cwdPath;
884
1277
  return await this.web.assemble({ ...this.target.config, indexPath: this.indexPath(platform) }, {
885
- html: path8.join(dist, "csr", targetHtmlFilename(this.target.config)),
886
- publicDir: path8.join(dist, "public"),
887
- fontsDir: path8.join(dist, ".akan", "artifact", "fonts")
1278
+ html: path10.join(dist, "csr", targetHtmlFilename(this.target.config)),
1279
+ publicDir: path10.join(dist, "public"),
1280
+ fontsDir: path10.join(dist, ".akan", "artifact", "fonts")
888
1281
  });
889
1282
  }
890
1283
  get binDir() {
891
- return path8.join(this.targetRoot, "bin");
1284
+ return path10.join(this.targetRoot, "bin");
892
1285
  }
893
1286
  async config({
894
1287
  server,
@@ -1047,7 +1440,29 @@ class NativeApp {
1047
1440
  }));
1048
1441
  }
1049
1442
  get updatesDir() {
1050
- return path8.join(this.targetRoot, "updates");
1443
+ return path10.join(this.targetRoot, "updates");
1444
+ }
1445
+ async publishedRelease(platform, { arch, channel }) {
1446
+ this.#assertUpdates();
1447
+ const [api, { config }] = await Promise.all([
1448
+ NativeApi.load(this.app.cwdPath),
1449
+ this.config({ platform, stageBin: false })
1450
+ ]);
1451
+ const { updates } = config;
1452
+ const publicKeys = updates?.publicKeys ?? (updates?.publicKey ? [updates.publicKey] : []);
1453
+ if (!updates || !publicKeys.length)
1454
+ throw new Error(`Native target '${this.target.name}' has no updates key.`);
1455
+ const release = await DesktopRelease.read(this.updatesDir, {
1456
+ platform,
1457
+ arch,
1458
+ channel: channel ?? updates.channel ?? "production",
1459
+ appId: config.app.id,
1460
+ ...updates.target ? { target: updates.target } : {},
1461
+ publicKeys,
1462
+ revokedKeys: updates.revokedKeys ?? [],
1463
+ api
1464
+ });
1465
+ return { release, url: updates.url, exeName: config.app.fileName ?? "" };
1051
1466
  }
1052
1467
  async publishUpdate(platform, {
1053
1468
  channel,
@@ -1118,7 +1533,7 @@ class NativeApp {
1118
1533
  ...resetSequence ? { resetSequence } : {}
1119
1534
  });
1120
1535
  } catch (error) {
1121
- throw new Error(`Native target '${this.target.name}': ${toError(error).message}`, {
1536
+ throw new Error(`Native target '${this.target.name}': ${toError2(error).message}`, {
1122
1537
  cause: error
1123
1538
  });
1124
1539
  }
@@ -1152,11 +1567,11 @@ class NativeApp {
1152
1567
  const { api, config } = await this.prepare(platform);
1153
1568
  if (!config.updates)
1154
1569
  throw new Error(`Native target '${this.target.name}' takes no updates: add native.updates: { url, publicKey } to akan.config.ts first.`);
1155
- const dir = path8.resolve(out ?? path8.join(this.updatesDir, platform));
1570
+ const dir = path10.resolve(out ?? path10.join(this.updatesDir, platform));
1156
1571
  await UpdatePackFolder.clear(dir);
1157
1572
  const packed = await this.#recorded(dir, publicEnv, api.packUpdate({ ...this.#task(platform, config), platform, out: dir }));
1158
1573
  const channel = config.updates.channel ?? "production";
1159
- const bundle = await UpdatePackFolder.readBundle(path8.join(packed.out, UpdatePackFolder.bundleFile));
1574
+ const bundle = await UpdatePackFolder.readBundle(path10.join(packed.out, UpdatePackFolder.bundleFile));
1160
1575
  const pack = {
1161
1576
  schema: 1,
1162
1577
  app: this.app.name,
@@ -1193,7 +1608,7 @@ bundle.json records none, so no update can be checked against this build.`);
1193
1608
  }
1194
1609
  async#recorded(dir, publicEnv, build) {
1195
1610
  const result = await build;
1196
- const file = path8.join(dir, UpdatePackFolder.bundleFile);
1611
+ const file = path10.join(dir, UpdatePackFolder.bundleFile);
1197
1612
  if (!publicEnv || !await Bun.file(file).exists())
1198
1613
  return result;
1199
1614
  const bundle = await UpdatePackFolder.readBundle(file);
@@ -1256,4 +1671,4 @@ bundle.json records none, so no update can be checked against this build.`);
1256
1671
  }
1257
1672
  }
1258
1673
 
1259
- export { DesktopBin, NativePublicEnv, UpdatePackFolder, NativeApp };
1674
+ export { DesktopBin, UpdatePackFolder, UpdateUploader, NativePublicEnv, NativeApp };