@akanjs/cli 3.1.1-rc.0 → 3.1.1-rc.10

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 (78) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-4pnxwptq.js → CodeAgent-8d5qs787.js} +2 -2
  3. package/{CodeTui-hhndze8h.js → CodeTui-z5vkm9ea.js} +1 -1
  4. package/TunnelShare-qkm8zp03.js +14 -0
  5. package/{agent.command-p02330r6.js → agent.command-ydftceda.js} +5 -5
  6. package/akanCode.js +2 -2
  7. package/{application.command-ywks5ywm.js → application.command-wthg8nn9.js} +18 -13
  8. package/{applicationBuildRunner-9cnnsdm5.js → applicationBuildRunner-t2r84sz6.js} +72 -26
  9. package/buildBatch.proc.js +5 -5
  10. package/{cloud.command-1tzkvje1.js → cloud.command-sz11hpre.js} +22 -17
  11. package/cloud.script-nqevg5qw.js +24 -0
  12. package/{code.command-16pm1p2v.js → code.command-9h3yrzhe.js} +6 -6
  13. package/{context.command-6ys86sqf.js → context.command-15j9b7c0.js} +16 -16
  14. package/context.runner-8gg030b0.js +25 -0
  15. package/{guideline.command-3zay3d8g.js → guideline.command-snh85ctf.js} +2 -2
  16. package/guidelines/agentRule/agentRule.instruction.md +21 -4
  17. package/guidelines/conventions/conventions.instruction.md +17 -10
  18. package/guidelines/mcpRule/mcpRule.instruction.md +13 -6
  19. package/guidelines/pageRule/pageRule.instruction.md +21 -5
  20. package/guidelines/queryRule/queryRule.instruction.md +13 -1
  21. package/guidelines/runtimeRule/runtimeRule.instruction.md +20 -2
  22. package/guidelines/ssrRule/ssrRule.instruction.md +6 -1
  23. package/guidelines/transportRule/transportRule.instruction.md +12 -5
  24. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +2 -1
  25. package/incrementalBuilder.proc.js +3 -3
  26. package/{index-jgs8z8xb.js → index-0fz95kxe.js} +1 -1
  27. package/{index-1f33g2z5.js → index-2azahjaw.js} +81 -28
  28. package/{index-kcbq2qcf.js → index-2mwc0g0d.js} +1 -1
  29. package/{index-qkcwsg6r.js → index-2xcc2ax5.js} +2 -2
  30. package/{index-68c3gzvg.js → index-301pdbzz.js} +56 -9
  31. package/{index-z6v7k9sb.js → index-31es1yev.js} +24 -2
  32. package/{index-p4dnj2wc.js → index-3wypz6xj.js} +59 -8
  33. package/{index-e9e9cebg.js → index-40brg4px.js} +3 -3
  34. package/{index-tk3jg2bm.js → index-42j4a8zq.js} +2 -2
  35. package/{index-1mfyyxh5.js → index-4vgbysa0.js} +3 -3
  36. package/{index-9hbhm6cs.js → index-55j120r8.js} +1 -1
  37. package/{index-vg28jsf9.js → index-6txx6a9p.js} +214 -71
  38. package/{index-zn6bn1s2.js → index-74tjjsnc.js} +4 -4
  39. package/{index-g2s33373.js → index-905qdgqp.js} +1 -1
  40. package/{index-qtkycaqn.js → index-9th4gszy.js} +38 -21
  41. package/{index-bb4hj03s.js → index-a58emady.js} +10 -10
  42. package/{index-4w3skd33.js → index-a5dhqkdr.js} +3 -3
  43. package/{index-sh9mmp5v.js → index-b70zct19.js} +7 -7
  44. package/{index-z9xepn8t.js → index-bt438yxm.js} +556 -142
  45. package/{index-ngpn9hzy.js → index-espk51ah.js} +2 -2
  46. package/{index-b5vptvnt.js → index-hmt54t45.js} +4 -4
  47. package/{index-qfzfaq96.js → index-j9vyj3dj.js} +3 -3
  48. package/{index-ekpp5tax.js → index-js6geqjn.js} +4 -97
  49. package/{index-fmder14z.js → index-pcwzkdqb.js} +1 -1
  50. package/{index-jaa81e9r.js → index-qfp55x1y.js} +4 -4
  51. package/{index-sng3vt0p.js → index-skk9zc1x.js} +2 -2
  52. package/{index-rr7jk14m.js → index-wcej7g4z.js} +13 -10
  53. package/{index-q8age5az.js → index-xb8809yb.js} +2 -2
  54. package/{index-ynqxpwx6.js → index-xjf5j657.js} +1 -1
  55. package/index.js +22 -22
  56. package/{library.command-a8n9h8j4.js → library.command-gycrwhf1.js} +3 -3
  57. package/{localRegistry.command-1e6m7w2f.js → localRegistry.command-jtd8gaes.js} +12 -12
  58. package/{module.command-b6f1p1xa.js → module.command-v6hgs1bc.js} +5 -5
  59. package/{package.command-tc27ftmy.js → package.command-shzpcfph.js} +3 -3
  60. package/package.json +2 -2
  61. package/{page.command-m5wyqfkd.js → page.command-ptxn5kqk.js} +3 -3
  62. package/{pipeline.command-4qxyafpz.js → pipeline.command-zz31pgax.js} +2 -2
  63. package/{primitive.command-9yaatk0d.js → primitive.command-a1vse91z.js} +6 -6
  64. package/{projectTypecheck-87k6z6ab.js → projectTypecheck-2ztky9cf.js} +1 -1
  65. package/{quality.command-ht1wjhv8.js → quality.command-ah8qcakd.js} +387 -73
  66. package/{repair.command-evg9g911.js → repair.command-cvazbz99.js} +5 -5
  67. package/{scalar.command-xsejjeq1.js → scalar.command-0acvyp26.js} +4 -4
  68. package/{subspace.command-ps12q5y7.js → subspace.command-822qx2bx.js} +8 -8
  69. package/templates/app/tsconfig.json.template +2 -7
  70. package/templates/env/_env.server.type.ts +10 -5
  71. package/templates/facetIndex/index.ts +2 -2
  72. package/templates/workspaceRoot/bunfig.toml.template +0 -4
  73. package/{tunnel.command-khzgvrj8.js → tunnel.command-ycmja19q.js} +7 -7
  74. package/{workflow.command-qpyq0ya5.js → workflow.command-abb1d5xy.js} +10 -10
  75. package/{workspace.command-3dq7e9g2.js → workspace.command-qm7cw29v.js} +33 -32
  76. package/TunnelShare-zmq6bbar.js +0 -14
  77. package/cloud.script-8g83xqdg.js +0 -24
  78. 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-wcej7g4z.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-xb8809yb.js";
15
16
  import {
16
17
  ExitCodeError
17
- } from "./index-p4dnj2wc.js";
18
+ } from "./index-3wypz6xj.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,485 @@ 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
+ await run(["tar.exe", "-xzf", archive, "-C", tmp, exe]);
562
+ const extracted = path4.join(tmp, exe);
563
+ if (!await Bun.file(extracted).exists())
564
+ return { signer: null, unread: `the archive holds no ${exe}` };
565
+ const out = path4.join(tmp, "signer.txt");
566
+ const { code } = await run([
567
+ path4.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
568
+ "-NoProfile",
569
+ "-NonInteractive",
570
+ "-EncodedCommand",
571
+ Buffer.from(DesktopRelease.#authenticode, "utf16le").toString("base64")
572
+ ], { env: { AKAN_RELEASE_EXE: extracted, AKAN_SIGNER_OUT: out } });
573
+ if (code !== 0)
574
+ return { signer: null, unread: `PowerShell could not read the Authenticode signature of ${exe}` };
575
+ const subject = (await readFile(out, "utf8").catch(() => "")).replace(/^\uFEFF/, "").trim();
576
+ return { signer: subject ? { subject } : null, unread: null };
577
+ }
578
+ static #open(api, envelope, publicKeys, revokedKeys) {
579
+ try {
580
+ return api.openEnvelope(new TextDecoder().decode(envelope), publicKeys, revokedKeys).manifest;
581
+ } catch (error) {
582
+ return toError(error).message;
583
+ }
584
+ }
585
+ static #parse(bytes) {
586
+ try {
587
+ const value = JSON.parse(new TextDecoder().decode(bytes));
588
+ return isRecord2(value) ? value : null;
589
+ } catch {
590
+ return null;
591
+ }
592
+ }
593
+ static async#run(cmd, { env } = {}) {
594
+ try {
595
+ const proc = Bun.spawn(cmd, {
596
+ env: { ...process.env, ...env },
597
+ stdin: "ignore",
598
+ stdout: "pipe",
599
+ stderr: "pipe"
600
+ });
601
+ const [code, stdout, stderr] = await Promise.all([
602
+ proc.exited,
603
+ new Response(proc.stdout).text(),
604
+ new Response(proc.stderr).text()
605
+ ]);
606
+ return { code, output: `${stdout}${stderr}` };
607
+ } catch (error) {
608
+ return { code: -1, output: toError(error).message };
609
+ }
610
+ }
611
+ }
612
+
613
+ // pkgs/@akanjs/devkit/mobile/nativeApi.ts
614
+ import path5 from "path";
141
615
 
142
616
  class NativeApi {
143
617
  static supportedMajor = 0;
144
- static minimumVersion = "0.12.0";
618
+ static minimumVersion = "0.13.0";
145
619
  static entryOf(appDir) {
146
620
  const workspaceEntry = NativeApi.#resolve("@akanjs/native/api", appDir);
147
621
  if (workspaceEntry)
@@ -149,7 +623,7 @@ class NativeApi {
149
623
  const akanjsPackage = NativeApi.#resolve("akanjs/package.json", appDir);
150
624
  if (!akanjsPackage)
151
625
  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");
626
+ return path5.join(path5.dirname(akanjsPackage), "vendor", "@akanjs", "native", "packages", "cli", "src", "api.ts");
153
627
  }
154
628
  static async load(appDir) {
155
629
  const entry = NativeApi.entryOf(appDir);
@@ -171,8 +645,8 @@ class NativeApi {
171
645
  }
172
646
 
173
647
  // pkgs/@akanjs/devkit/mobile/nativeApp.ts
174
- import path8 from "path";
175
- import { toError } from "akanjs/common";
648
+ import path10 from "path";
649
+ import { toError as toError2 } from "akanjs/common";
176
650
 
177
651
  // pkgs/@akanjs/devkit/mobile/nativeAppLine.ts
178
652
  class NativeAppLine {
@@ -231,7 +705,7 @@ class NativeAppLine {
231
705
 
232
706
  // pkgs/@akanjs/devkit/mobile/nativeConfig.ts
233
707
  import { readFileSync } from "fs";
234
- import path3 from "path";
708
+ import path6 from "path";
235
709
  import { trimSlashes } from "akanjs/common";
236
710
 
237
711
  // pkgs/@akanjs/devkit/mobile/usageDescriptions.ts
@@ -314,11 +788,11 @@ class NativeConfig {
314
788
  warnings.push(`Permission '${permission}' has no native plugin yet; the app ships without it.`);
315
789
  return used;
316
790
  });
317
- const abs = (relative) => path3.resolve(appPath, relative);
791
+ const abs = (relative) => path6.resolve(appPath, relative);
318
792
  const updates = NativeConfig.#updates(target, env);
319
- const folders = new Set(nativePlugins.map((plugin) => path3.resolve(plugin.dir)));
793
+ const folders = new Set(nativePlugins.map((plugin) => path6.resolve(plugin.dir)));
320
794
  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)));
795
+ const listed = (target.plugins ?? []).filter((spec) => NativeConfig.#isId(spec) ? !folderIds.has(spec) : !folders.has(path6.resolve(appPath, spec)));
322
796
  const plugins = [
323
797
  ...new Set([
324
798
  ...NativeConfig.basePlugins,
@@ -374,7 +848,7 @@ class NativeConfig {
374
848
  app: {
375
849
  id: resolveAppId(target.appId, platform),
376
850
  name: target.appName,
377
- fileName: target.fileName ?? NativeConfig.fileNameOf(path3.basename(appPath)),
851
+ fileName: target.fileName ?? NativeConfig.fileNameOf(path6.basename(appPath)),
378
852
  version: target.version,
379
853
  build: target.buildNum
380
854
  },
@@ -431,7 +905,7 @@ class NativeConfig {
431
905
  static #updates(target, env) {
432
906
  const { url, publicKey, publicKeys, channel = env, ...rest } = target.updates ?? {};
433
907
  const keys = publicKeys ? { publicKeys: [...publicKeys] } : publicKey ? { publicKey } : null;
434
- return url && keys ? { ...rest, url, ...keys, ...channel ? { channel } : {} } : undefined;
908
+ return url && keys ? { ...rest, url, ...keys, ...channel ? { channel } : {}, target: target.name } : undefined;
435
909
  }
436
910
  static fileNameOf(name) {
437
911
  return /[^-.](?:.*[^-.])?/.exec(name.replace(/[^A-Za-z0-9._-]/g, "-"))?.[0] ?? "app";
@@ -440,14 +914,14 @@ class NativeConfig {
440
914
  if (NativeConfig.#isId(spec))
441
915
  return spec;
442
916
  try {
443
- const { id } = JSON.parse(readFileSync(path3.join(path3.resolve(appPath, spec), "native-plugin.json"), "utf8"));
917
+ const { id } = JSON.parse(readFileSync(path6.join(path6.resolve(appPath, spec), "native-plugin.json"), "utf8"));
444
918
  return typeof id === "string" ? id : spec;
445
919
  } catch {
446
920
  return spec;
447
921
  }
448
922
  }
449
923
  static #isId(spec) {
450
- return !spec.startsWith(".") && !path3.isAbsolute(spec);
924
+ return !spec.startsWith(".") && !path6.isAbsolute(spec);
451
925
  }
452
926
  static #compact(value) {
453
927
  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 +941,24 @@ class NativeConfig {
467
941
  }
468
942
 
469
943
  // pkgs/@akanjs/devkit/mobile/nativePluginFolders.ts
470
- import { readdir } from "fs/promises";
471
- import path4 from "path";
944
+ import { readdir as readdir2 } from "fs/promises";
945
+ import path7 from "path";
472
946
 
473
947
  class NativePluginFolders {
474
948
  static folder = "native";
475
949
  static async in(root, owner) {
476
- const base = path4.join(root, NativePluginFolders.folder);
477
- const entries = await readdir(base, { withFileTypes: true }).catch(() => []);
950
+ const base = path7.join(root, NativePluginFolders.folder);
951
+ const entries = await readdir2(base, { withFileTypes: true }).catch(() => []);
478
952
  const folders = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
479
953
  return await Promise.all(folders.sort().map(async (name) => {
480
954
  const where = `${owner}/${NativePluginFolders.folder}/${name}`;
481
- const manifest = Bun.file(path4.join(base, name, "native-plugin.json"));
955
+ const manifest = Bun.file(path7.join(base, name, "native-plugin.json"));
482
956
  if (!await manifest.exists())
483
957
  throw new Error(`${where} has no native-plugin.json; a folder in native/ is one native plugin.`);
484
958
  const { id } = await manifest.json();
485
959
  if (id !== name)
486
960
  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 };
961
+ return { id, dir: path7.join(base, name), owner };
488
962
  }));
489
963
  }
490
964
  static select(own, fromLibs) {
@@ -503,14 +977,14 @@ class NativePluginFolders {
503
977
  const root = app.workspace.workspaceRoot;
504
978
  const [own, ...fromLibs] = await Promise.all([
505
979
  NativePluginFolders.in(app.cwdPath, `apps/${app.name}`),
506
- ...scanInfo.getLibs().map((lib) => NativePluginFolders.in(path4.join(root, "libs", lib), `libs/${lib}`))
980
+ ...scanInfo.getLibs().map((lib) => NativePluginFolders.in(path7.join(root, "libs", lib), `libs/${lib}`))
507
981
  ]);
508
982
  return NativePluginFolders.select(own ?? [], fromLibs.flat());
509
983
  }
510
984
  }
511
985
 
512
986
  // pkgs/@akanjs/devkit/mobile/nativePublicEnv.ts
513
- import { createHash } from "crypto";
987
+ import { createHash as createHash2 } from "crypto";
514
988
  class NativePublicEnv {
515
989
  static derivedKeys = [
516
990
  "AKAN_PUBLIC_APP_NAME",
@@ -529,7 +1003,7 @@ class NativePublicEnv {
529
1003
  return Object.fromEntries(Object.keys(env).filter((key) => key.startsWith("AKAN_PUBLIC_") && !NativePublicEnv.derivedKeys.includes(key)).sort().map((key) => [key, String(env[key])]));
530
1004
  }
531
1005
  static hash(publicEnv) {
532
- return createHash("sha256").update(JSON.stringify(NativePublicEnv.of(publicEnv))).digest("hex");
1006
+ return createHash2("sha256").update(JSON.stringify(NativePublicEnv.of(publicEnv))).digest("hex");
533
1007
  }
534
1008
  static problems(publicEnv) {
535
1009
  const keys = Object.keys(publicEnv);
@@ -609,8 +1083,8 @@ class NativePublicEnv {
609
1083
  }
610
1084
 
611
1085
  // pkgs/@akanjs/devkit/mobile/nativeWebDir.ts
612
- import { cp, mkdir as mkdir2, rm as rm2, stat } from "fs/promises";
613
- import path5 from "path";
1086
+ import { cp, mkdir as mkdir2, rm as rm4, stat } from "fs/promises";
1087
+ import path8 from "path";
614
1088
  import { trimSlashes as trimSlashes2 } from "akanjs/common";
615
1089
 
616
1090
  class NativeWebDir {
@@ -638,7 +1112,7 @@ ${script}${html.slice(at)}`;
638
1112
  }
639
1113
  static #targetTag = "<script>window.__AKAN_MOBILE_TARGET__=";
640
1114
  async clear() {
641
- await rm2(this.dir, { recursive: true, force: true });
1115
+ await rm4(this.dir, { recursive: true, force: true });
642
1116
  await mkdir2(this.dir, { recursive: true });
643
1117
  }
644
1118
  async assemble(target, { html, publicDir, fontsDir }) {
@@ -648,12 +1122,12 @@ ${script}${html.slice(at)}`;
648
1122
  if (publicDir && await NativeWebDir.#isDir(publicDir))
649
1123
  await cp(publicDir, this.dir, { recursive: true });
650
1124
  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)))
1125
+ await cp(fontsDir, path8.join(this.dir, "_akan", "fonts"), { recursive: true });
1126
+ if (await NativeWebDir.#isDir(path8.join(this.dir, NativeWebDir.reservedEntry)))
653
1127
  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));
1128
+ await Bun.write(path8.join(this.dir, "index.html"), NativeWebDir.injectTarget(await Bun.file(html).text(), target));
655
1129
  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();
1130
+ return files.map((file) => file.split(path8.sep).join("/")).sort();
657
1131
  }
658
1132
  static async#isDir(dir) {
659
1133
  try {
@@ -665,8 +1139,8 @@ ${script}${html.slice(at)}`;
665
1139
  }
666
1140
 
667
1141
  // pkgs/@akanjs/devkit/mobile/serverBundleSecrets.ts
668
- import { readdir as readdir2, readFile, stat as stat2 } from "fs/promises";
669
- import path6 from "path";
1142
+ import { readdir as readdir3, readFile as readFile2, stat as stat2 } from "fs/promises";
1143
+ import path9 from "path";
670
1144
  class ServerBundleSecrets {
671
1145
  workspaceRoot;
672
1146
  appDir;
@@ -678,8 +1152,8 @@ class ServerBundleSecrets {
678
1152
  this.appDir = appDir;
679
1153
  }
680
1154
  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))));
1155
+ const dirs = [path9.join(this.appDir, "env"), ...(await this.#libDirs()).map((lib) => path9.join(lib, "env"))];
1156
+ 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
1157
  return files.flat();
684
1158
  }
685
1159
  async assertClean(bundleDir) {
@@ -687,7 +1161,7 @@ class ServerBundleSecrets {
687
1161
  const secrets = [];
688
1162
  for (const file of await this.envFiles()) {
689
1163
  try {
690
- const value = await ServerEnvProfile.evaluate(file, path6.dirname(path6.dirname(file)));
1164
+ const value = await ServerEnvProfile.evaluate(file, path9.dirname(path9.dirname(file)));
691
1165
  secrets.push(...ServerEnvProfile.secretValues(value).map((secret) => ({ file, ...secret })));
692
1166
  } catch {
693
1167
  unread.push(ServerBundleSecrets.#relative(this.workspaceRoot, file));
@@ -698,7 +1172,7 @@ class ServerBundleSecrets {
698
1172
  const sought = secrets.map((secret) => ({ secret, needles: ServerBundleSecrets.#needles(secret.value) }));
699
1173
  const found = [];
700
1174
  for (const bundled of await ServerBundleSecrets.#files(bundleDir)) {
701
- const text = await readFile(bundled, "latin1");
1175
+ const text = await readFile2(bundled, "latin1");
702
1176
  for (const { secret, needles } of sought)
703
1177
  if (needles.some((needle) => text.includes(needle)))
704
1178
  found.push({ bundled, secret });
@@ -719,7 +1193,7 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
719
1193
  return coded;
720
1194
  for (const dir of [this.appDir, ...await this.#libDirs()])
721
1195
  for (const file of await ServerBundleSecrets.#sources(dir)) {
722
- const text = await readFile(file, "utf8");
1196
+ const text = await readFile2(file, "utf8");
723
1197
  for (const value of plain)
724
1198
  if (text.includes(value))
725
1199
  coded.add(value);
@@ -727,8 +1201,8 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
727
1201
  return coded;
728
1202
  }
729
1203
  async#libDirs() {
730
- const libsDir = path6.join(this.workspaceRoot, "libs");
731
- return (await readdir2(libsDir).catch(() => [])).map((lib) => path6.join(libsDir, lib));
1204
+ const libsDir = path9.join(this.workspaceRoot, "libs");
1205
+ return (await readdir3(libsDir).catch(() => [])).map((lib) => path9.join(libsDir, lib));
732
1206
  }
733
1207
  static #needles(value) {
734
1208
  const escaped = JSON.stringify(value).slice(1, -1);
@@ -741,12 +1215,12 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
741
1215
  return /^export default (["'`])([\s\S]*)\1;?\s*$/.exec(code)?.[2] ?? value;
742
1216
  }
743
1217
  static #relative(from, to) {
744
- return path6.relative(from, to).split(path6.sep).join("/");
1218
+ return path9.relative(from, to).split(path9.sep).join("/");
745
1219
  }
746
1220
  static async#files(dir) {
747
1221
  const files = [];
748
- for (const entry of await readdir2(dir, { withFileTypes: true })) {
749
- const file = path6.join(dir, entry.name);
1222
+ for (const entry of await readdir3(dir, { withFileTypes: true })) {
1223
+ const file = path9.join(dir, entry.name);
750
1224
  if (entry.isDirectory()) {
751
1225
  if (entry.name !== "node_modules")
752
1226
  files.push(...await ServerBundleSecrets.#files(file));
@@ -757,10 +1231,10 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
757
1231
  }
758
1232
  static async#sources(dir) {
759
1233
  const files = [];
760
- for (const entry of await readdir2(dir, { withFileTypes: true }).catch(() => [])) {
1234
+ for (const entry of await readdir3(dir, { withFileTypes: true }).catch(() => [])) {
761
1235
  if (entry.name.startsWith("."))
762
1236
  continue;
763
- const file = path6.join(dir, entry.name);
1237
+ const file = path9.join(dir, entry.name);
764
1238
  if (entry.isDirectory()) {
765
1239
  if (!ServerBundleSecrets.#notSource.has(entry.name))
766
1240
  files.push(...await ServerBundleSecrets.#sources(file));
@@ -771,88 +1245,6 @@ Build its server with a profile (native.desktop.server.profile), whose bundle le
771
1245
  }
772
1246
  }
773
1247
 
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
1248
  // pkgs/@akanjs/devkit/mobile/nativeApp.ts
857
1249
  class NativeApp {
858
1250
  app;
@@ -865,14 +1257,14 @@ class NativeApp {
865
1257
  this.app = app;
866
1258
  this.target = target;
867
1259
  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"));
1260
+ this.targetRoot = path10.join(app.workspace.workspaceRoot, "dist", "native", app.name, target.name);
1261
+ this.web = new NativeWebDir(path10.join(this.targetRoot, "web"));
870
1262
  }
871
1263
  outDir(platform) {
872
- return path8.join(this.targetRoot, "build", platform);
1264
+ return path10.join(this.targetRoot, "build", platform);
873
1265
  }
874
1266
  devOutDir(platform) {
875
- return path8.join(this.targetRoot, "dev", platform);
1267
+ return path10.join(this.targetRoot, "dev", platform);
876
1268
  }
877
1269
  indexPath(platform) {
878
1270
  const { config } = this.target;
@@ -882,13 +1274,13 @@ class NativeApp {
882
1274
  async assembleWeb(platform) {
883
1275
  const dist = this.app.dist.cwdPath;
884
1276
  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")
1277
+ html: path10.join(dist, "csr", targetHtmlFilename(this.target.config)),
1278
+ publicDir: path10.join(dist, "public"),
1279
+ fontsDir: path10.join(dist, ".akan", "artifact", "fonts")
888
1280
  });
889
1281
  }
890
1282
  get binDir() {
891
- return path8.join(this.targetRoot, "bin");
1283
+ return path10.join(this.targetRoot, "bin");
892
1284
  }
893
1285
  async config({
894
1286
  server,
@@ -1047,7 +1439,29 @@ class NativeApp {
1047
1439
  }));
1048
1440
  }
1049
1441
  get updatesDir() {
1050
- return path8.join(this.targetRoot, "updates");
1442
+ return path10.join(this.targetRoot, "updates");
1443
+ }
1444
+ async publishedRelease(platform, { arch, channel }) {
1445
+ this.#assertUpdates();
1446
+ const [api, { config }] = await Promise.all([
1447
+ NativeApi.load(this.app.cwdPath),
1448
+ this.config({ platform, stageBin: false })
1449
+ ]);
1450
+ const { updates } = config;
1451
+ const publicKeys = updates?.publicKeys ?? (updates?.publicKey ? [updates.publicKey] : []);
1452
+ if (!updates || !publicKeys.length)
1453
+ throw new Error(`Native target '${this.target.name}' has no updates key.`);
1454
+ const release = await DesktopRelease.read(this.updatesDir, {
1455
+ platform,
1456
+ arch,
1457
+ channel: channel ?? updates.channel ?? "production",
1458
+ appId: config.app.id,
1459
+ ...updates.target ? { target: updates.target } : {},
1460
+ publicKeys,
1461
+ revokedKeys: updates.revokedKeys ?? [],
1462
+ api
1463
+ });
1464
+ return { release, url: updates.url, exeName: config.app.fileName ?? "" };
1051
1465
  }
1052
1466
  async publishUpdate(platform, {
1053
1467
  channel,
@@ -1118,7 +1532,7 @@ class NativeApp {
1118
1532
  ...resetSequence ? { resetSequence } : {}
1119
1533
  });
1120
1534
  } catch (error) {
1121
- throw new Error(`Native target '${this.target.name}': ${toError(error).message}`, {
1535
+ throw new Error(`Native target '${this.target.name}': ${toError2(error).message}`, {
1122
1536
  cause: error
1123
1537
  });
1124
1538
  }
@@ -1152,11 +1566,11 @@ class NativeApp {
1152
1566
  const { api, config } = await this.prepare(platform);
1153
1567
  if (!config.updates)
1154
1568
  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));
1569
+ const dir = path10.resolve(out ?? path10.join(this.updatesDir, platform));
1156
1570
  await UpdatePackFolder.clear(dir);
1157
1571
  const packed = await this.#recorded(dir, publicEnv, api.packUpdate({ ...this.#task(platform, config), platform, out: dir }));
1158
1572
  const channel = config.updates.channel ?? "production";
1159
- const bundle = await UpdatePackFolder.readBundle(path8.join(packed.out, UpdatePackFolder.bundleFile));
1573
+ const bundle = await UpdatePackFolder.readBundle(path10.join(packed.out, UpdatePackFolder.bundleFile));
1160
1574
  const pack = {
1161
1575
  schema: 1,
1162
1576
  app: this.app.name,
@@ -1193,7 +1607,7 @@ bundle.json records none, so no update can be checked against this build.`);
1193
1607
  }
1194
1608
  async#recorded(dir, publicEnv, build) {
1195
1609
  const result = await build;
1196
- const file = path8.join(dir, UpdatePackFolder.bundleFile);
1610
+ const file = path10.join(dir, UpdatePackFolder.bundleFile);
1197
1611
  if (!publicEnv || !await Bun.file(file).exists())
1198
1612
  return result;
1199
1613
  const bundle = await UpdatePackFolder.readBundle(file);
@@ -1256,4 +1670,4 @@ bundle.json records none, so no update can be checked against this build.`);
1256
1670
  }
1257
1671
  }
1258
1672
 
1259
- export { DesktopBin, NativePublicEnv, UpdatePackFolder, NativeApp };
1673
+ export { DesktopBin, UpdatePackFolder, UpdateUploader, NativePublicEnv, NativeApp };