@adea-ai/app-framework-release-tools 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -18,6 +18,7 @@ var __export = (target, all) => {
18
18
  // src/index.ts
19
19
  var exports_src = {};
20
20
  __export(exports_src, {
21
+ buildLinuxFormats: () => buildLinuxFormats,
21
22
  createDailyNativeReceipt: () => createDailyNativeReceipt,
22
23
  createGitHubPromotionProvider: () => createGitHubPromotionProvider,
23
24
  createGitHubReleasePublisher: () => createGitHubReleasePublisher,
@@ -8439,6 +8440,269 @@ async function stageLinuxPackagePairWithInspection(options, inspect) {
8439
8440
  }
8440
8441
  }
8441
8442
  var stageLinuxPackagePair = (options) => stageLinuxPackagePairWithInspection(options, inspectWithNativeTools);
8443
+ // src/library/linux-format-producer.ts
8444
+ import { createHash as createHash16 } from "crypto";
8445
+ import { createReadStream, createWriteStream } from "fs";
8446
+ import {
8447
+ chmod as chmod4,
8448
+ cp,
8449
+ lstat as lstat20,
8450
+ lutimes,
8451
+ mkdir as mkdir12,
8452
+ mkdtemp as mkdtemp11,
8453
+ open as open14,
8454
+ readdir as readdir12,
8455
+ readlink as readlink3,
8456
+ realpath as realpath11,
8457
+ rm as rm11,
8458
+ utimes,
8459
+ writeFile as writeFile12
8460
+ } from "fs/promises";
8461
+ import { basename as basename16, dirname as dirname15, isAbsolute as isAbsolute6, join as join35, relative as relative6, resolve as resolve17 } from "path";
8462
+ import { pipeline as pipeline2 } from "stream/promises";
8463
+ var component = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
8464
+ var sha256 = /^[a-f0-9]{64}$/;
8465
+ var sum = async (path) => {
8466
+ const hash = createHash16("sha256");
8467
+ for await (const chunk of createReadStream(path))
8468
+ hash.update(chunk);
8469
+ return hash.digest("hex");
8470
+ };
8471
+ var relativeFiles = (value) => value.split("/").every((part) => component.test(part));
8472
+ var text2 = (v) => v.length > 0 && v.length <= 250 && !/[\r\n]/.test(v);
8473
+ function check(ok, message) {
8474
+ if (!ok)
8475
+ throw new Error(message);
8476
+ }
8477
+ async function exactCopy(pin, to) {
8478
+ check(sha256.test(pin.sha256), "Missing protected input digest");
8479
+ const before = await lstat20(pin.path);
8480
+ check(before.isFile() && !before.isSymbolicLink() && before.size > 0, "Expected a regular pinned input");
8481
+ const input = await open14(pin.path, "r");
8482
+ try {
8483
+ const after = await input.stat();
8484
+ check(after.dev === before.dev && after.ino === before.ino && after.size === before.size, "Pinned input changed");
8485
+ await pipeline2(input.createReadStream({ autoClose: false, start: 0, end: before.size - 1 }), createWriteStream(to, { flags: "wx", mode: 384 }));
8486
+ } finally {
8487
+ await input.close();
8488
+ }
8489
+ check((await lstat20(to)).size === before.size && await sum(to) === pin.sha256, "Pinned input digest mismatch");
8490
+ }
8491
+ async function regular(root, path) {
8492
+ const file = join35(root, path);
8493
+ check((await lstat20(file)).isFile() && await realpath11(file) === file, "Required bundle member is not a regular file");
8494
+ return file;
8495
+ }
8496
+ async function elf(path, appImage = false) {
8497
+ const input = await open14(path, "r");
8498
+ try {
8499
+ const h = Buffer.alloc(20);
8500
+ const { bytesRead } = await input.read(h, 0, h.length, 0);
8501
+ check(bytesRead === 20 && h.toString("hex", 0, 6) === "7f454c460201" && h.readUInt16LE(18) === 62 && (!appImage || h.toString("hex", 8, 11) === "414902"), "Expected native Linux x64 executable");
8502
+ } finally {
8503
+ await input.close();
8504
+ }
8505
+ }
8506
+ async function normalizeTree(root, dir = root) {
8507
+ for (const name of await readdir12(dir)) {
8508
+ const file = join35(dir, name);
8509
+ const st = await lstat20(file);
8510
+ if (st.isSymbolicLink()) {
8511
+ check(!isAbsolute6(await readlink3(file)), "Absolute bundle symlink");
8512
+ const target = relative6(root, await realpath11(file));
8513
+ check(target !== ".." && !target.startsWith("../") && !isAbsolute6(target), "Escaping bundle symlink");
8514
+ } else if (st.isDirectory()) {
8515
+ await chmod4(file, 493);
8516
+ await normalizeTree(root, file);
8517
+ } else {
8518
+ check(st.isFile(), "Unsupported bundle entry");
8519
+ await chmod4(file, st.mode & 73 ? 493 : 420);
8520
+ }
8521
+ }
8522
+ }
8523
+ async function normalizeBuildTimes(directory, epoch) {
8524
+ for (const name of (await readdir12(directory)).toSorted()) {
8525
+ const path = join35(directory, name);
8526
+ const info = await lstat20(path);
8527
+ if (info.isSymbolicLink()) {
8528
+ await lutimes(path, epoch, epoch);
8529
+ } else if (info.isDirectory()) {
8530
+ await normalizeBuildTimes(path, epoch);
8531
+ } else {
8532
+ check(info.isFile(), "Unsupported packaging entry");
8533
+ await utimes(path, epoch, epoch);
8534
+ }
8535
+ }
8536
+ await chmod4(directory, 493);
8537
+ await utimes(directory, epoch, epoch);
8538
+ }
8539
+ async function write(root, path, value, mode = 420) {
8540
+ const target = join35(root, path);
8541
+ await mkdir12(dirname15(target), { recursive: true });
8542
+ await writeFile12(target, value, { flag: "wx", mode });
8543
+ await chmod4(target, mode);
8544
+ }
8545
+ function validatePolicy(policy) {
8546
+ check([policy.bundleRoot, policy.artifactStem, policy.desktopId].every((n) => component.test(n)) && /^[a-z0-9][a-z0-9+.-]+$/.test(policy.packageName) && [policy.launcher, policy.icon, ...policy.debSetuid.map((item) => item.path)].every(relativeFiles) && policy.debSetuid.every((item) => sha256.test(item.sha256)) && new Set(policy.debSetuid.map((item) => item.path)).size === policy.debSetuid.length && /^[A-Z][A-Z0-9_]*_LINUX_PACKAGE_FORMAT$/.test(policy.formatEnvironment) && policy.mimeTypes.every((x) => /^x-scheme-handler\/[a-z][a-z0-9+.-]*$/.test(x)) && [policy.name, policy.description, policy.maintainer, policy.homepage].every(text2) && policy.categories.every((x) => /^[A-Za-z0-9]+$/.test(x)) && policy.dependencies.every((x) => /^[a-z0-9][a-z0-9+.-]*(?: \| [a-z0-9][a-z0-9+.-]*)*$/.test(x)), "Invalid app Linux packaging policy");
8547
+ check(new URL(policy.homepage).protocol === "https:", "Expected HTTPS homepage");
8548
+ }
8549
+ async function buildLinuxFormats(input, host) {
8550
+ const { tag, sourceSha, expectedSourceSha, sourceDateEpoch, policy } = input;
8551
+ check(host.os === "linux" && host.arch === "x64", "Requires native Linux x64");
8552
+ check(/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) && /^[a-f0-9]{40}$/.test(sourceSha) && sourceSha === expectedSourceSha, "Wrong protected build source or tag");
8553
+ check(Number.isSafeInteger(sourceDateEpoch) && sourceDateEpoch > 0 && sourceDateEpoch <= 4294967295, "Expected valid protected SOURCE_DATE_EPOCH");
8554
+ const env = { SOURCE_DATE_EPOCH: String(sourceDateEpoch), LC_ALL: "C", TZ: "UTC" };
8555
+ validatePolicy(policy);
8556
+ const requested = resolve17(input.output);
8557
+ const parent = await realpath11(dirname15(requested));
8558
+ const output = join35(parent, basename16(requested));
8559
+ const work = await mkdtemp11(join35(parent, ".linux-formats-"));
8560
+ try {
8561
+ const archive = join35(work, "payload.tar.zst");
8562
+ const tool = join35(work, "appimagetool");
8563
+ const runtime = join35(work, "runtime");
8564
+ for (const [pin, dest] of [
8565
+ [input.archive, archive],
8566
+ [input.tool, tool],
8567
+ [input.runtime, runtime]
8568
+ ])
8569
+ await exactCopy(pin, dest);
8570
+ await elf(tool, true);
8571
+ await elf(runtime, true);
8572
+ await host.inspectAppArchive(archive);
8573
+ check((await lstat20(archive)).isFile() && await sum(archive) === input.archive.sha256, "Payload changed during app inspection");
8574
+ await chmod4(tool, 448);
8575
+ const extracted = join35(work, "extract");
8576
+ await mkdir12(extracted);
8577
+ await host.run("tar", [
8578
+ "--zstd",
8579
+ "--extract",
8580
+ "--file",
8581
+ archive,
8582
+ "--directory",
8583
+ extracted,
8584
+ "--no-same-owner",
8585
+ "--no-same-permissions"
8586
+ ], { env });
8587
+ const source = join35(extracted, policy.bundleRoot);
8588
+ check((await lstat20(source)).isDirectory() && await realpath11(source) === source, "Wrong extracted app root");
8589
+ await chmod4(source, 493);
8590
+ await normalizeTree(source);
8591
+ await elf(await regular(source, policy.launcher));
8592
+ for (const pin of policy.debSetuid) {
8593
+ const file = await regular(source, pin.path);
8594
+ await elf(file);
8595
+ check(await sum(file) === pin.sha256, "DEB setuid helper differs from trusted pin");
8596
+ }
8597
+ const icon = await regular(source, policy.icon);
8598
+ check(policy.icon.endsWith(".svg"), "Expected an SVG application icon");
8599
+ const stem = `${policy.artifactStem}-${tag}-linux-x64`;
8600
+ const debName = `${stem}.deb`;
8601
+ const imageName = `${stem}.AppImage`;
8602
+ const dest = join35(work, "result");
8603
+ await mkdir12(dest);
8604
+ const version = tag.slice(1);
8605
+ const installed = `usr/lib/${policy.packageName}`;
8606
+ const desktopFile = `${policy.desktopId}.desktop`;
8607
+ const desktop = [
8608
+ "[Desktop Entry]",
8609
+ "Type=Application",
8610
+ `Name=${policy.name}`,
8611
+ `Comment=${policy.description}`,
8612
+ `Exec=${policy.packageName} %U`,
8613
+ `Icon=${policy.desktopId}`,
8614
+ `Categories=${policy.categories.join(";")};`,
8615
+ ...policy.mimeTypes.length ? [`MimeType=${policy.mimeTypes.join(";")};`] : [],
8616
+ "Terminal=false",
8617
+ ""
8618
+ ].join(`
8619
+ `);
8620
+ for (const format of ["deb", "appimage"]) {
8621
+ const tree = join35(work, format);
8622
+ await mkdir12(join35(tree, "usr", "lib"), { recursive: true });
8623
+ const bundle = join35(tree, installed);
8624
+ await cp(source, bundle, { recursive: true, verbatimSymlinks: true });
8625
+ await normalizeTree(bundle);
8626
+ await write(tree, `usr/share/applications/${desktopFile}`, desktop);
8627
+ const iconDest = join35(tree, `usr/share/icons/hicolor/scalable/apps/${policy.desktopId}.svg`);
8628
+ await mkdir12(dirname15(iconDest), { recursive: true });
8629
+ await cp(icon, iconDest, { force: false, errorOnExist: true });
8630
+ await chmod4(iconDest, 420);
8631
+ if (format === "deb") {
8632
+ for (const pin of policy.debSetuid)
8633
+ await chmod4(await regular(bundle, pin.path), 2541);
8634
+ await write(tree, `usr/bin/${policy.packageName}`, `#!/bin/sh
8635
+ export ${policy.formatEnvironment}=deb
8636
+ exec '/${installed}/${policy.launcher}' "$@"
8637
+ `, 493);
8638
+ await write(tree, "DEBIAN/control", [
8639
+ `Package: ${policy.packageName}`,
8640
+ `Version: ${version}`,
8641
+ "Architecture: amd64",
8642
+ `Maintainer: ${policy.maintainer}`,
8643
+ `Description: ${policy.description}`,
8644
+ `Homepage: ${policy.homepage}`,
8645
+ ...policy.dependencies.length ? [`Depends: ${policy.dependencies.join(", ")}`] : [],
8646
+ ""
8647
+ ].join(`
8648
+ `));
8649
+ await normalizeBuildTimes(tree, sourceDateEpoch);
8650
+ await host.run("dpkg-deb", ["--root-owner-group", "--threads-max=1", "-Zxz", "--build", tree, join35(dest, debName)], { env });
8651
+ } else {
8652
+ const rootIcon = join35(tree, `${policy.desktopId}.svg`);
8653
+ await cp(icon, rootIcon, { force: false, errorOnExist: true });
8654
+ await chmod4(rootIcon, 420);
8655
+ await write(tree, desktopFile, desktop);
8656
+ await write(tree, "AppRun", [
8657
+ "#!/bin/sh",
8658
+ "set -eu",
8659
+ 'root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',
8660
+ `export ${policy.formatEnvironment}=appimage`,
8661
+ `exec "$root/${installed}/${policy.launcher}" "$@"`,
8662
+ ""
8663
+ ].join(`
8664
+ `), 493);
8665
+ await normalizeBuildTimes(tree, sourceDateEpoch);
8666
+ await host.run("appimagetool", ["--no-appstream", "--runtime-file", runtime, tree, join35(dest, imageName)], {
8667
+ executable: tool,
8668
+ env: { ...env, ARCH: "x86_64", VERSION: version, APPIMAGE_EXTRACT_AND_RUN: "1" }
8669
+ });
8670
+ }
8671
+ }
8672
+ const artifacts = [];
8673
+ for (const name of [debName, imageName]) {
8674
+ const path = await regular(dest, name);
8675
+ const size = (await lstat20(path)).size;
8676
+ check(size > 0, "Empty produced artifact");
8677
+ artifacts.push({ name, size, sha256: await sum(path) });
8678
+ }
8679
+ const receipt = {
8680
+ schema: "linux-package-formats/v1",
8681
+ tag,
8682
+ sourceSha,
8683
+ sourceDateEpoch,
8684
+ platform: "linux-x64",
8685
+ updateArchiveSha256: input.archive.sha256,
8686
+ artifacts
8687
+ };
8688
+ await mkdir12(output);
8689
+ try {
8690
+ for (const item of artifacts)
8691
+ await cp(join35(dest, item.name), join35(output, basename16(item.name)), {
8692
+ force: false,
8693
+ errorOnExist: true
8694
+ });
8695
+ await write(output, "linux-format-build.json", JSON.stringify(receipt) + `
8696
+ `);
8697
+ } catch (error) {
8698
+ await rm11(output, { recursive: true, force: true });
8699
+ throw error;
8700
+ }
8701
+ return receipt;
8702
+ } finally {
8703
+ await rm11(work, { recursive: true, force: true });
8704
+ }
8705
+ }
8442
8706
  // src/framework-loader.ts
8443
8707
  var releaseTools = async () => exports_src;
8444
8708
 
@@ -8462,8 +8726,8 @@ function electrobunArtifacts(appName, platform) {
8462
8726
 
8463
8727
  // src/library/daily-native-observer.ts
8464
8728
  import { execFile as execFile4 } from "child_process";
8465
- import { createHash as createHash16, randomBytes as randomBytes3 } from "crypto";
8466
- import { join as join35, resolve as resolve17 } from "path";
8729
+ import { createHash as createHash17, randomBytes as randomBytes3 } from "crypto";
8730
+ import { join as join36, resolve as resolve18 } from "path";
8467
8731
  import { Effect as Effect25 } from "effect";
8468
8732
  var runDailyNativeDriver = (script, input, env) => new Promise((finish, reject) => {
8469
8733
  const child = execFile4(process.execPath, ["--no-env-file", script], {
@@ -8517,12 +8781,12 @@ function phaseEnvironment(env, profile) {
8517
8781
  ...clean,
8518
8782
  HOME: profile,
8519
8783
  USERPROFILE: profile,
8520
- LOCALAPPDATA: join35(profile, "LocalAppData"),
8521
- XDG_CONFIG_HOME: join35(profile, ".config"),
8522
- XDG_DATA_HOME: join35(profile, ".local", "share"),
8523
- TEMP: join35(profile, "tmp"),
8524
- TMP: join35(profile, "tmp"),
8525
- TMPDIR: join35(profile, "tmp")
8784
+ LOCALAPPDATA: join36(profile, "LocalAppData"),
8785
+ XDG_CONFIG_HOME: join36(profile, ".config"),
8786
+ XDG_DATA_HOME: join36(profile, ".local", "share"),
8787
+ TEMP: join36(profile, "tmp"),
8788
+ TMP: join36(profile, "tmp"),
8789
+ TMPDIR: join36(profile, "tmp")
8526
8790
  };
8527
8791
  }
8528
8792
  function parseBaseline(value, target) {
@@ -8540,7 +8804,7 @@ function driverPath(value) {
8540
8804
  throw new Error("Invalid native observer path");
8541
8805
  return value;
8542
8806
  }
8543
- var fixtureDigest = (nonce) => "sha256:" + createHash16("sha256").update(nonce).digest("hex");
8807
+ var fixtureDigest = (nonce) => "sha256:" + createHash17("sha256").update(nonce).digest("hex");
8544
8808
  var confirmFixture = (value, nonce) => isRecord(value) && hasExactOwnKeys(value, ["digest"]) && value.digest === fixtureDigest(nonce);
8545
8809
  var observeDailyNativeEffect = (options, run) => Effect25.gen(function* () {
8546
8810
  const { env, platform: os, arch, cwd } = yield* ReleaseConfig;
@@ -8582,29 +8846,29 @@ var observeDailyNativeEffect = (options, run) => Effect25.gen(function* () {
8582
8846
  const tempStat = yield* step(() => fs.lstat(temp));
8583
8847
  if (!tempStat.isDirectory() || tempStat.isSymbolicLink())
8584
8848
  return yield* fail("Expected real runner temp directory");
8585
- const root = yield* Effect25.acquireRelease(step(() => fs.mkdtemp(join35(temp, "daily-native-"))), (dir) => Effect25.promise(() => fs.rm(dir, { recursive: true, force: true })));
8849
+ const root = yield* Effect25.acquireRelease(step(() => fs.mkdtemp(join36(temp, "daily-native-"))), (dir) => Effect25.promise(() => fs.rm(dir, { recursive: true, force: true })));
8586
8850
  const make = (name) => Effect25.gen(function* () {
8587
- const dir = join35(root, name);
8851
+ const dir = join36(root, name);
8588
8852
  yield* step(() => fs.mkdir(dir, { mode: 448 }));
8589
8853
  return dir;
8590
8854
  });
8591
8855
  const snapshot = (source, target, names) => Effect25.gen(function* () {
8592
- const directory = resolve17(source);
8856
+ const directory = resolve18(source);
8593
8857
  const info = yield* step(() => fs.lstat(directory));
8594
8858
  if (!info.isDirectory() || info.isSymbolicLink())
8595
8859
  return yield* fail("Expected real native input directory");
8596
8860
  return yield* stageExpectedFilesEffect({
8597
8861
  expected: names,
8598
8862
  directory: target,
8599
- sources: Object.fromEntries(names.map((name) => [name, join35(directory, name)]))
8863
+ sources: Object.fromEntries(names.map((name) => [name, join36(directory, name)]))
8600
8864
  });
8601
8865
  });
8602
8866
  const scriptName = path.endsWith(".mjs") ? "observer.mjs" : "observer.ts";
8603
- const script = join35(root, scriptName);
8867
+ const script = join36(root, scriptName);
8604
8868
  yield* stageExpectedFilesEffect({
8605
8869
  directory: root,
8606
8870
  expected: [scriptName],
8607
- sources: { [scriptName]: join35(cwd, path) }
8871
+ sources: { [scriptName]: join36(cwd, path) }
8608
8872
  });
8609
8873
  const hash = yield* step(() => git.run(["hash-object", "--no-filters", "--", script]));
8610
8874
  if (hash !== blob)
@@ -8619,7 +8883,7 @@ var observeDailyNativeEffect = (options, run) => Effect25.gen(function* () {
8619
8883
  const earlier = previous && baseline ? yield* snapshot(previous.directory, baseline, baselineFiles) : undefined;
8620
8884
  const freshProfile = (name) => Effect25.gen(function* () {
8621
8885
  const dir = yield* make(name);
8622
- yield* step(() => fs.mkdir(join35(dir, "tmp"), { mode: 448 }));
8886
+ yield* step(() => fs.mkdir(join36(dir, "tmp"), { mode: 448 }));
8623
8887
  return dir;
8624
8888
  });
8625
8889
  const fresh = yield* freshProfile("fresh");
@@ -8716,24 +8980,24 @@ var observeDailyNativeEffect = (options, run) => Effect25.gen(function* () {
8716
8980
  }).pipe(Effect25.scoped);
8717
8981
 
8718
8982
  // src/library/daily-batch.ts
8719
- import { join as join36, resolve as resolve18 } from "path";
8983
+ import { join as join37, resolve as resolve19 } from "path";
8720
8984
  import { Effect as Effect26, Exit as Exit4 } from "effect";
8721
8985
  var stageDailyBatchEffect = (options) => Effect26.gen(function* () {
8722
8986
  const fs = yield* ReleaseFs;
8723
- const parent = resolve18(options.parent);
8987
+ const parent = resolve19(options.parent);
8724
8988
  const root = yield* step(() => fs.lstat(parent));
8725
8989
  if (!root.isDirectory() || root.isSymbolicLink())
8726
8990
  return yield* fail("Daily staging needs an existing real scratch parent");
8727
8991
  const original = yield* verifyDailyReleaseMatrixEffect(options);
8728
8992
  const plan = yield* attempt(() => planDailyReleaseMatrix(options.config, options.identity.tag));
8729
- const directory = yield* Effect26.acquireRelease(step(() => fs.mkdtemp(join36(parent, "daily-candidate-"))), (path, exit) => Exit4.isSuccess(exit) ? Effect26.void : Effect26.promise(() => fs.rm(path, { recursive: true, force: true })));
8993
+ const directory = yield* Effect26.acquireRelease(step(() => fs.mkdtemp(join37(parent, "daily-candidate-"))), (path, exit) => Exit4.isSuccess(exit) ? Effect26.void : Effect26.promise(() => fs.rm(path, { recursive: true, force: true })));
8730
8994
  const copy = (source, name, expected) => Effect26.gen(function* () {
8731
- const target = join36(directory, name);
8995
+ const target = join37(directory, name);
8732
8996
  yield* step(() => fs.mkdir(target, { mode: 448 }));
8733
8997
  yield* stageExpectedFilesEffect({
8734
8998
  expected,
8735
8999
  directory: target,
8736
- sources: Object.fromEntries(expected.map((file) => [file, join36(source, file)]))
9000
+ sources: Object.fromEntries(expected.map((file) => [file, join37(source, file)]))
8737
9001
  });
8738
9002
  return target;
8739
9003
  });
@@ -8743,7 +9007,7 @@ var stageDailyBatchEffect = (options) => Effect26.gen(function* () {
8743
9007
  if (original.assets.some((a, index) => a.name !== staged.assets[index]?.name || a.size !== staged.assets[index]?.size || a.digest !== staged.assets[index]?.digest))
8744
9008
  return yield* fail("Daily inputs changed between inspection and local staging");
8745
9009
  const manifest = { schema: "framework/daily-staged-batch/v1", ...staged };
8746
- yield* step(() => fs.writeFile(join36(directory, "candidate.json"), JSON.stringify(manifest) + `
9010
+ yield* step(() => fs.writeFile(join37(directory, "candidate.json"), JSON.stringify(manifest) + `
8747
9011
  `, {
8748
9012
  flag: "wx",
8749
9013
  mode: 384
@@ -8800,10 +9064,10 @@ var provideLivePorts = (program) => program.pipe(Effect27.provideService(Release
8800
9064
  }));
8801
9065
 
8802
9066
  // src/commands/prepare-stable-catalog.ts
8803
- import { createHash as createHash17 } from "crypto";
8804
- import { createReadStream } from "fs";
8805
- import { lstat as lstat20, mkdir as mkdir12, readFile as readFile11, rm as rm11, writeFile as writeFile12 } from "fs/promises";
8806
- import { basename as basename16, dirname as dirname15, join as join37 } from "path";
9067
+ import { createHash as createHash18 } from "crypto";
9068
+ import { createReadStream as createReadStream2 } from "fs";
9069
+ import { lstat as lstat21, mkdir as mkdir13, readFile as readFile11, rm as rm12, writeFile as writeFile13 } from "fs/promises";
9070
+ import { basename as basename17, dirname as dirname16, join as join38 } from "path";
8807
9071
 
8808
9072
  // src/library/stable-catalogs.ts
8809
9073
  function object(value) {
@@ -8964,7 +9228,7 @@ ShortDescription: ${quoted(desc)}
8964
9228
 
8965
9229
  // src/commands/prepare-stable-catalog.ts
8966
9230
  var read2 = async (path) => {
8967
- const stat = await lstat20(path);
9231
+ const stat = await lstat21(path);
8968
9232
  if (!stat.isFile() || stat.size > 1024 * 1024)
8969
9233
  throw new Error("Expected bounded ordinary JSON file");
8970
9234
  return JSON.parse(await readFile11(path, "utf8"));
@@ -8984,11 +9248,11 @@ async function prepareStableCatalogCommand(args) {
8984
9248
  ] = args;
8985
9249
  if (channel !== "homebrew" && channel !== "winget" || phase !== "preflight" && phase !== "published-stable" || !expectedSourceSha || !configPath || !receiptPath || !manifestPath || !artifact || !out || extra.length || phase === "published-stable" !== Boolean(stablePointerPath))
8986
9250
  throw new Error("Expected channel, phase, source SHA, config, receipt, manifest, archive, new output directory [stable pointer]");
8987
- const st = await lstat20(artifact);
9251
+ const st = await lstat21(artifact);
8988
9252
  if (!st.isFile())
8989
9253
  throw new Error("Expected ordinary installer file");
8990
- const hash = createHash17("sha256");
8991
- for await (const chunk of createReadStream(artifact))
9254
+ const hash = createHash18("sha256");
9255
+ for await (const chunk of createReadStream2(artifact))
8992
9256
  hash.update(chunk);
8993
9257
  const files = prepareStableCatalog({
8994
9258
  channel,
@@ -8998,31 +9262,31 @@ async function prepareStableCatalogCommand(args) {
8998
9262
  receipt: await read2(receiptPath),
8999
9263
  manifest: await read2(manifestPath),
9000
9264
  stablePointer: stablePointerPath && await read2(stablePointerPath),
9001
- measuredAsset: { name: basename16(artifact), size: st.size, sha256: hash.digest("hex") }
9265
+ measuredAsset: { name: basename17(artifact), size: st.size, sha256: hash.digest("hex") }
9002
9266
  });
9003
- await mkdir12(out);
9267
+ await mkdir13(out);
9004
9268
  try {
9005
9269
  for (const entry of files) {
9006
- const target = join37(out, entry.path);
9007
- await mkdir12(dirname15(target), { recursive: true });
9008
- await writeFile12(target, entry.contents, { flag: "wx" });
9270
+ const target = join38(out, entry.path);
9271
+ await mkdir13(dirname16(target), { recursive: true });
9272
+ await writeFile13(target, entry.contents, { flag: "wx" });
9009
9273
  }
9010
9274
  return { channel, phase, files: files.length };
9011
9275
  } catch (error) {
9012
- await rm11(out, { recursive: true, force: true });
9276
+ await rm12(out, { recursive: true, force: true });
9013
9277
  throw error;
9014
9278
  }
9015
9279
  }
9016
9280
 
9017
9281
  // src/library/apt/stage-apt-repository.ts
9018
9282
  import { spawnSync as spawnSync2 } from "child_process";
9019
- import { mkdir as mkdir13, readFile as readFile12, rm as rm12, writeFile as writeFile13 } from "fs/promises";
9020
- import { dirname as dirname16, isAbsolute as isAbsolute6, join as join38 } from "path";
9283
+ import { mkdir as mkdir14, readFile as readFile12, rm as rm13, writeFile as writeFile14 } from "fs/promises";
9284
+ import { dirname as dirname17, isAbsolute as isAbsolute7, join as join39 } from "path";
9021
9285
 
9022
9286
  // src/library/apt/apt-metadata.ts
9023
- import { createHash as createHash18 } from "crypto";
9287
+ import { createHash as createHash19 } from "crypto";
9024
9288
  import { gzipSync } from "zlib";
9025
- var sha256 = (data) => createHash18("sha256").update(data).digest("hex");
9289
+ var sha2562 = (data) => createHash19("sha256").update(data).digest("hex");
9026
9290
  function stageAptMetadata({ policy, tag, assets, deb, control, now }) {
9027
9291
  if (!/^v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)$/.test(tag))
9028
9292
  throw new Error("Invalid release tag");
@@ -9033,7 +9297,7 @@ function stageAptMetadata({ policy, tag, assets, deb, control, now }) {
9033
9297
  if (matching.length !== 1)
9034
9298
  throw new Error("Require one staged Debian artifact");
9035
9299
  const asset = matching[0];
9036
- if (!deb.length || asset.size !== deb.length || asset.sha256 !== sha256(deb))
9300
+ if (!deb.length || asset.size !== deb.length || asset.sha256 !== sha2562(deb))
9037
9301
  throw new Error("Staged Debian bytes do not match the verified release inventory");
9038
9302
  const fields = new Map;
9039
9303
  let lines = control.replaceAll(`\r
@@ -9083,7 +9347,7 @@ SHA256: ${asset.sha256}
9083
9347
  "Components: main",
9084
9348
  "Acquire-By-Hash: yes",
9085
9349
  "SHA256:",
9086
- ...members.map(([path, bytes]) => ` ${sha256(bytes)} ${bytes.length} ${path}`),
9350
+ ...members.map(([path, bytes]) => ` ${sha2562(bytes)} ${bytes.length} ${path}`),
9087
9351
  ""
9088
9352
  ].join(`
9089
9353
  `);
@@ -9092,7 +9356,7 @@ SHA256: ${asset.sha256}
9092
9356
  release,
9093
9357
  files: new Map([
9094
9358
  ...members,
9095
- ...members.map(([, bytes]) => [`${directories}/by-hash/SHA256/${sha256(bytes)}`, bytes])
9359
+ ...members.map(([, bytes]) => [`${directories}/by-hash/SHA256/${sha2562(bytes)}`, bytes])
9096
9360
  ])
9097
9361
  };
9098
9362
  }
@@ -9105,22 +9369,22 @@ function cmd(program, options, label) {
9105
9369
  return run.stdout;
9106
9370
  }
9107
9371
  async function add(path, bytes) {
9108
- await mkdir13(dirname16(path), { recursive: true });
9109
- await writeFile13(path, bytes, { flag: "wx" });
9372
+ await mkdir14(dirname17(path), { recursive: true });
9373
+ await writeFile14(path, bytes, { flag: "wx" });
9110
9374
  }
9111
9375
  async function stageAptRepositoryCommand(args) {
9112
9376
  const [tag, policyPath, inventoryPath, packagePath, output, signingHome, trustedFingerprint] = args;
9113
- if (args.length !== 7 || !tag || !/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) || !policyPath || !inventoryPath || !packagePath || !output || !signingHome || !isAbsolute6(signingHome) || !trustedFingerprint || !/^[A-F0-9]{40}$/.test(trustedFingerprint))
9377
+ if (args.length !== 7 || !tag || !/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) || !policyPath || !inventoryPath || !packagePath || !output || !signingHome || !isAbsolute7(signingHome) || !trustedFingerprint || !/^[A-F0-9]{40}$/.test(trustedFingerprint))
9114
9378
  throw new Error("Expected TAG POLICY VERIFIED_INVENTORY DEB NEW_OUTPUT GPG_HOME PINNED_FINGERPRINT");
9115
9379
  const policy = JSON.parse(await readFile12(policyPath, "utf8"));
9116
9380
  const inventory = JSON.parse(await readFile12(inventoryPath, "utf8"));
9117
9381
  if (inventory.tag !== tag || !Array.isArray(inventory.assets))
9118
9382
  throw new Error("Verified inventory does not name requested release");
9119
9383
  const deb = await readFile12(packagePath);
9120
- await mkdir13(output, { mode: 448 });
9384
+ await mkdir14(output, { mode: 448 });
9121
9385
  try {
9122
- const stagedInput = join38(output, ".input.deb");
9123
- await writeFile13(stagedInput, deb, { mode: 384, flag: "wx" });
9386
+ const stagedInput = join39(output, ".input.deb");
9387
+ await writeFile14(stagedInput, deb, { mode: 384, flag: "wx" });
9124
9388
  const control = cmd("dpkg-deb", ["--field", stagedInput], "Debian control inspection failed");
9125
9389
  const staged = stageAptMetadata({
9126
9390
  policy,
@@ -9130,11 +9394,11 @@ async function stageAptRepositoryCommand(args) {
9130
9394
  control,
9131
9395
  now: new Date
9132
9396
  });
9133
- const base = join38(output, "dists", policy.suite);
9134
- await add(join38(output, staged.packagePath), deb);
9397
+ const base = join39(output, "dists", policy.suite);
9398
+ await add(join39(output, staged.packagePath), deb);
9135
9399
  for (const [path, contents] of staged.files)
9136
- await add(join38(base, path), contents);
9137
- await add(join38(base, "Release"), staged.release);
9400
+ await add(join39(base, path), contents);
9401
+ await add(join39(base, "Release"), staged.release);
9138
9402
  const flags = [
9139
9403
  "--batch",
9140
9404
  "--no-tty",
@@ -9151,34 +9415,34 @@ async function stageAptRepositoryCommand(args) {
9151
9415
  ["InRelease", "--clearsign"],
9152
9416
  ["Release.gpg", "--detach-sign"]
9153
9417
  ]) {
9154
- cmd("gpg", [...flags, "--armor", "--output", join38(base, name), mode, join38(base, "Release")], `Could not produce ${name} with the pinned signing identity`);
9418
+ cmd("gpg", [...flags, "--armor", "--output", join39(base, name), mode, join39(base, "Release")], `Could not produce ${name} with the pinned signing identity`);
9155
9419
  }
9156
9420
  const { unlink } = await import("fs/promises");
9157
9421
  await unlink(stagedInput);
9158
- await add(join38(output, "STAGED"), `${tag}
9422
+ await add(join39(output, "STAGED"), `${tag}
9159
9423
  `);
9160
9424
  return { tag, staged: true };
9161
9425
  } catch (error) {
9162
- await rm12(output, { recursive: true, force: true });
9426
+ await rm13(output, { recursive: true, force: true });
9163
9427
  throw error;
9164
9428
  }
9165
9429
  }
9166
9430
 
9167
9431
  // src/linux-channel-proof-cli.ts
9168
9432
  import { spawnSync as spawnSync3 } from "child_process";
9169
- import { createHash as createHash19 } from "crypto";
9170
- import { createReadStream as createReadStream2 } from "fs";
9171
- import { lstat as lstat21, readFile as readFile13, realpath as realpath11 } from "fs/promises";
9172
- import { join as join39 } from "path";
9433
+ import { createHash as createHash20 } from "crypto";
9434
+ import { createReadStream as createReadStream3 } from "fs";
9435
+ import { lstat as lstat22, readFile as readFile13, realpath as realpath12 } from "fs/promises";
9436
+ import { join as join40 } from "path";
9173
9437
  import { pathToFileURL } from "url";
9174
- function check(ok, message) {
9438
+ function check2(ok, message) {
9175
9439
  if (!ok)
9176
9440
  throw new Error(message);
9177
9441
  }
9178
9442
  async function hash(path) {
9179
- check((await lstat21(path)).isFile(), "artifact must be a regular file");
9180
- const digest = createHash19("sha256");
9181
- for await (const chunk of createReadStream2(path))
9443
+ check2((await lstat22(path)).isFile(), "artifact must be a regular file");
9444
+ const digest = createHash20("sha256");
9445
+ for await (const chunk of createReadStream3(path))
9182
9446
  digest.update(chunk);
9183
9447
  return digest.digest("hex");
9184
9448
  }
@@ -9194,56 +9458,56 @@ function options(text, section) {
9194
9458
  continue;
9195
9459
  }
9196
9460
  const field = /^([a-z_]+)\s*=\s*(\S+)$/.exec(line);
9197
- check(matched && field && !values.has(field[1]), "unexpected or duplicate repository option");
9461
+ check2(matched && field && !values.has(field[1]), "unexpected or duplicate repository option");
9198
9462
  values.set(field[1], field[2]);
9199
9463
  }
9200
- check(matched, "expected exactly one repository section");
9464
+ check2(matched, "expected exactly one repository section");
9201
9465
  return values;
9202
9466
  }
9203
9467
  async function verifyRpmStage(stage) {
9204
- check(/^[0-9a-f]{40}$/.test(stage.sourceSha), "expected an exact source commit");
9205
- check(/^[a-z0-9][a-z0-9._+-]*$/.test(stage.packageName), "invalid RPM package name");
9206
- check(/^[a-zA-Z0-9][a-zA-Z0-9._+~^]*$/.test(stage.version), "invalid RPM version");
9207
- check(stage.architecture === "x86_64", "only x86_64 is supported");
9208
- check(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/.test(stage.repoId), "invalid repository ID");
9468
+ check2(/^[0-9a-f]{40}$/.test(stage.sourceSha), "expected an exact source commit");
9469
+ check2(/^[a-z0-9][a-z0-9._+-]*$/.test(stage.packageName), "invalid RPM package name");
9470
+ check2(/^[a-zA-Z0-9][a-zA-Z0-9._+~^]*$/.test(stage.version), "invalid RPM version");
9471
+ check2(stage.architecture === "x86_64", "only x86_64 is supported");
9472
+ check2(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/.test(stage.repoId), "invalid repository ID");
9209
9473
  for (const artifact of [stage.payload, stage.rpm]) {
9210
- check(/^[0-9a-f]{64}$/.test(artifact.sha256), "expected SHA-256");
9211
- check(await hash(artifact.path) === artifact.sha256, "staged artifact digest mismatch");
9474
+ check2(/^[0-9a-f]{64}$/.test(artifact.sha256), "expected SHA-256");
9475
+ check2(await hash(artifact.path) === artifact.sha256, "staged artifact digest mismatch");
9212
9476
  }
9213
- const repo = await realpath11(stage.repository);
9214
- const keyUrl = pathToFileURL(await realpath11(stage.publicKey)).href;
9477
+ const repo = await realpath12(stage.repository);
9478
+ const keyUrl = pathToFileURL(await realpath12(stage.publicKey)).href;
9215
9479
  const config = options(await readFile13(stage.repoFile, "utf8"), stage.repoId);
9216
- check(config.get("baseurl") === pathToFileURL(repo).href, "expected the local repository");
9217
- check(config.get("gpgkey") === keyUrl, "expected the configured QA public key");
9480
+ check2(config.get("baseurl") === pathToFileURL(repo).href, "expected the local repository");
9481
+ check2(config.get("gpgkey") === keyUrl, "expected the configured QA public key");
9218
9482
  for (const flag of ["pkg_gpgcheck", "repo_gpgcheck"]) {
9219
- check(config.get(flag) === "1", `${flag} must be enabled`);
9483
+ check2(config.get(flag) === "1", `${flag} must be enabled`);
9220
9484
  }
9221
9485
  const allowed = new Set(["name", "enabled", "baseurl", "gpgkey", "pkg_gpgcheck", "repo_gpgcheck"]);
9222
- check([...config.keys()].every((key) => allowed.has(key)), "unexpected repository options");
9486
+ check2([...config.keys()].every((key) => allowed.has(key)), "unexpected repository options");
9223
9487
  for (const path of [
9224
9488
  stage.publicKey,
9225
- join39(repo, "repodata/repomd.xml"),
9226
- join39(repo, "repodata/repomd.xml.asc")
9489
+ join40(repo, "repodata/repomd.xml"),
9490
+ join40(repo, "repodata/repomd.xml.asc")
9227
9491
  ]) {
9228
- check((await lstat21(path)).isFile(), "expected regular key and signed metadata files");
9492
+ check2((await lstat22(path)).isFile(), "expected regular key and signed metadata files");
9229
9493
  }
9230
- const result = spawnSync3("rpm", ["-qp", "--queryformat", "%{NAME}|%{VERSION}|%{ARCH}", await realpath11(stage.rpm.path)], { encoding: "utf8", timeout: 1e4 });
9231
- check(result.error?.code !== "ENOENT", "rpm is required for RPM header verification");
9232
- check(result.status === 0 && result.stdout === `${stage.packageName}|${stage.version}|${stage.architecture}`, "RPM header does not match the requested package, version and architecture");
9494
+ const result = spawnSync3("rpm", ["-qp", "--queryformat", "%{NAME}|%{VERSION}|%{ARCH}", await realpath12(stage.rpm.path)], { encoding: "utf8", timeout: 1e4 });
9495
+ check2(result.error?.code !== "ENOENT", "rpm is required for RPM header verification");
9496
+ check2(result.status === 0 && result.stdout === `${stage.packageName}|${stage.version}|${stage.architecture}`, "RPM header does not match the requested package, version and architecture");
9233
9497
  return { kind: "rpm-staging-inputs", sourceSha: stage.sourceSha };
9234
9498
  }
9235
9499
  var systemTalkDenied = /^(org\.freedesktop\.(Flatpak|DBus|systemd1)|org\.gtk\.GDBus)(\.|$)/;
9236
9500
  function verifyFlatpakCapabilities(policy, result) {
9237
- check(/^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*){2,}$/.test(policy.applicationId) && result.applicationId === policy.applicationId, "unexpected Flatpak app identity");
9238
- check(/^[0-9a-f]{40}$/.test(policy.sourceSha) && result.sourceSha === policy.sourceSha && /^[0-9a-f]{64}$/.test(policy.artifactSha256) && result.artifactSha256 === policy.artifactSha256, "Flatpak evidence does not match the expected source and artifact");
9239
- check(result.architecture === "x86_64", "only x86_64 is supported");
9501
+ check2(/^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*){2,}$/.test(policy.applicationId) && result.applicationId === policy.applicationId, "unexpected Flatpak app identity");
9502
+ check2(/^[0-9a-f]{40}$/.test(policy.sourceSha) && result.sourceSha === policy.sourceSha && /^[0-9a-f]{64}$/.test(policy.artifactSha256) && result.artifactSha256 === policy.artifactSha256, "Flatpak evidence does not match the expected source and artifact");
9503
+ check2(result.architecture === "x86_64", "only x86_64 is supported");
9240
9504
  const cap = policy.permissions;
9241
9505
  const actual = result.effectivePermissions;
9242
- check(cap.sockets.every((name) => name === "wayland" || name === "pulseaudio"), "unsafe socket policy");
9243
- check(cap.devices.every((name) => name === "dri"), "unsafe device policy");
9244
- check(cap.sessionTalkNames.every((name) => /^[A-Za-z_][\w-]*(\.[A-Za-z_][\w-]*)+$/.test(name) && !systemTalkDenied.test(name)), "unsafe session-bus policy");
9245
- check(typeof actual.network === "boolean" && typeof cap.network === "boolean" && (!actual.network || cap.network === true) && actual.sockets.every((name) => cap.sockets.some((allowed) => allowed === name)) && actual.devices.every((name) => cap.devices.some((allowed) => allowed === name)) && actual.sessionTalkNames.every((name) => cap.sessionTalkNames.includes(name)) && actual.filesystems.length === 0 && actual.systemTalkNames.length === 0, "effective Flatpak permissions exceed policy");
9246
- check([
9506
+ check2(cap.sockets.every((name) => name === "wayland" || name === "pulseaudio"), "unsafe socket policy");
9507
+ check2(cap.devices.every((name) => name === "dri"), "unsafe device policy");
9508
+ check2(cap.sessionTalkNames.every((name) => /^[A-Za-z_][\w-]*(\.[A-Za-z_][\w-]*)+$/.test(name) && !systemTalkDenied.test(name)), "unsafe session-bus policy");
9509
+ check2(typeof actual.network === "boolean" && typeof cap.network === "boolean" && (!actual.network || cap.network === true) && actual.sockets.every((name) => cap.sockets.some((allowed) => allowed === name)) && actual.devices.every((name) => cap.devices.some((allowed) => allowed === name)) && actual.sessionTalkNames.every((name) => cap.sessionTalkNames.includes(name)) && actual.filesystems.length === 0 && actual.systemTalkNames.length === 0, "effective Flatpak permissions exceed policy");
9510
+ check2([
9247
9511
  result.localRepositoryInstall,
9248
9512
  result.upgradedAndRetainedData,
9249
9513
  result.sandboxedRenderer,
@@ -9257,8 +9521,8 @@ function verifyFlatpakCapabilities(policy, result) {
9257
9521
  }
9258
9522
 
9259
9523
  // src/library/arch-publish.ts
9260
- import { createHash as createHash20 } from "crypto";
9261
- import { join as join40 } from "path";
9524
+ import { createHash as createHash21 } from "crypto";
9525
+ import { join as join41 } from "path";
9262
9526
  import { tmpdir as tmpdir5 } from "os";
9263
9527
  import { Effect as Effect28 } from "effect";
9264
9528
 
@@ -9477,7 +9741,7 @@ var readLicense = (url) => Effect28.gen(function* () {
9477
9741
  return yield* fail("Release license is unavailable");
9478
9742
  }
9479
9743
  const bytes = yield* step(() => readReleaseBytes(response, MAX_LICENSE_BYTES));
9480
- const sha256 = yield* step(async () => createHash20("sha256").update(bytes).digest("hex"));
9744
+ const sha256 = yield* step(async () => createHash21("sha256").update(bytes).digest("hex"));
9481
9745
  return { url, sha256 };
9482
9746
  });
9483
9747
  var git2 = (args) => Effect28.gen(function* () {
@@ -9519,7 +9783,7 @@ var verifyArchRelease = (options) => Effect28.gen(function* () {
9519
9783
  if (!listed)
9520
9784
  return yield* fail(`Missing signed descriptor: ${descriptorPolicy.name}`);
9521
9785
  const bytes = yield* feedBytes(options.feed, `${options.tag}/${descriptorPolicy.name}`, 65536);
9522
- if (!bytes || bytes.length !== listed.size || createHash20("sha256").update(bytes).digest("hex") !== listed.sha256)
9786
+ if (!bytes || bytes.length !== listed.size || createHash21("sha256").update(bytes).digest("hex") !== listed.sha256)
9523
9787
  return yield* fail(`Signed descriptor differs from its release: ${descriptorPolicy.name}`);
9524
9788
  const json = yield* step(async () => {
9525
9789
  try {
@@ -9591,7 +9855,7 @@ var publishArchPackageEffect = (options) => Effect28.gen(function* () {
9591
9855
  const directory = options.printDirectory;
9592
9856
  yield* step(() => fs.mkdir(directory, { recursive: true }));
9593
9857
  for (const [name, contents] of Object.entries({ ...files, ...repositoryFiles }))
9594
- yield* step(() => fs.writeFile(join40(directory, name), contents, { mode: 420 }));
9858
+ yield* step(() => fs.writeFile(join41(directory, name), contents, { mode: 420 }));
9595
9859
  }
9596
9860
  const base = { pkgname: policy.pkgname, pkgver: rendered.pkgver, pkgrel };
9597
9861
  if (options.dryRun)
@@ -9604,14 +9868,14 @@ var publishArchPackageEffect = (options) => Effect28.gen(function* () {
9604
9868
  if (!key.includes("PRIVATE KEY"))
9605
9869
  return yield* fail("AUR_SSH_PRIVATE_KEY_B64 is not a private key");
9606
9870
  return yield* Effect28.gen(function* () {
9607
- const work = yield* step(() => fs.mkdtemp(join40(tmpdir5(), "arch-package-")));
9871
+ const work = yield* step(() => fs.mkdtemp(join41(tmpdir5(), "arch-package-")));
9608
9872
  yield* Effect28.addFinalizer(() => Effect28.promise(() => fs.rm(work, { recursive: true, force: true }).then(() => {
9609
9873
  return;
9610
9874
  }, () => {
9611
9875
  return;
9612
9876
  })));
9613
- const keyFile = join40(work, "aur_id_ed25519");
9614
- const knownHosts = join40(work, "aur_known_hosts");
9877
+ const keyFile = join41(work, "aur_id_ed25519");
9878
+ const knownHosts = join41(work, "aur_known_hosts");
9615
9879
  yield* step(() => fs.mkdir(work, { recursive: true, mode: 448 }));
9616
9880
  yield* step(() => fs.writeFile(keyFile, key.endsWith(`
9617
9881
  `) ? key : `${key}
@@ -9619,7 +9883,7 @@ var publishArchPackageEffect = (options) => Effect28.gen(function* () {
9619
9883
  yield* step(() => fs.writeFile(knownHosts, `${AUR_HOST_KEY}
9620
9884
  `, { mode: 420 }));
9621
9885
  const ssh = `ssh -i "${keyFile}" -o IdentitiesOnly=yes -o UserKnownHostsFile="${knownHosts}" -o StrictHostKeyChecking=yes`;
9622
- const checkout = join40(work, policy.pkgname);
9886
+ const checkout = join41(work, policy.pkgname);
9623
9887
  yield* git2([
9624
9888
  "-c",
9625
9889
  `core.sshCommand=${ssh}`,
@@ -9632,7 +9896,7 @@ var publishArchPackageEffect = (options) => Effect28.gen(function* () {
9632
9896
  checkout
9633
9897
  ]);
9634
9898
  for (const [name, contents] of Object.entries(files))
9635
- yield* step(() => fs.writeFile(join40(checkout, name), contents, { mode: 420 }));
9899
+ yield* step(() => fs.writeFile(join41(checkout, name), contents, { mode: 420 }));
9636
9900
  yield* git2(["-C", checkout, "add", "--", ...Object.keys(files)]);
9637
9901
  const staged = yield* gitExit(["-C", checkout, "diff", "--cached", "--quiet"]);
9638
9902
  if (staged === 0)
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ var __export = (target, all) => {
17
17
  // src/index.ts
18
18
  var exports_src = {};
19
19
  __export(exports_src, {
20
+ buildLinuxFormats: () => buildLinuxFormats,
20
21
  createDailyNativeReceipt: () => createDailyNativeReceipt,
21
22
  createGitHubPromotionProvider: () => createGitHubPromotionProvider,
22
23
  createGitHubReleasePublisher: () => createGitHubReleasePublisher,
@@ -8329,7 +8330,271 @@ async function stageLinuxPackagePairWithInspection(options, inspect) {
8329
8330
  }
8330
8331
  }
8331
8332
  var stageLinuxPackagePair = (options) => stageLinuxPackagePairWithInspection(options, inspectWithNativeTools);
8333
+ // src/library/linux-format-producer.ts
8334
+ import { createHash as createHash16 } from "crypto";
8335
+ import { createReadStream, createWriteStream } from "fs";
8336
+ import {
8337
+ chmod as chmod4,
8338
+ cp,
8339
+ lstat as lstat20,
8340
+ lutimes,
8341
+ mkdir as mkdir12,
8342
+ mkdtemp as mkdtemp11,
8343
+ open as open13,
8344
+ readdir as readdir11,
8345
+ readlink as readlink3,
8346
+ realpath as realpath11,
8347
+ rm as rm11,
8348
+ utimes,
8349
+ writeFile as writeFile12
8350
+ } from "fs/promises";
8351
+ import { basename as basename16, dirname as dirname15, isAbsolute as isAbsolute6, join as join34, relative as relative5, resolve as resolve17 } from "path";
8352
+ import { pipeline as pipeline2 } from "stream/promises";
8353
+ var component = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
8354
+ var sha256 = /^[a-f0-9]{64}$/;
8355
+ var sum = async (path) => {
8356
+ const hash = createHash16("sha256");
8357
+ for await (const chunk of createReadStream(path))
8358
+ hash.update(chunk);
8359
+ return hash.digest("hex");
8360
+ };
8361
+ var relativeFiles = (value) => value.split("/").every((part) => component.test(part));
8362
+ var text2 = (v) => v.length > 0 && v.length <= 250 && !/[\r\n]/.test(v);
8363
+ function check(ok, message) {
8364
+ if (!ok)
8365
+ throw new Error(message);
8366
+ }
8367
+ async function exactCopy(pin, to) {
8368
+ check(sha256.test(pin.sha256), "Missing protected input digest");
8369
+ const before = await lstat20(pin.path);
8370
+ check(before.isFile() && !before.isSymbolicLink() && before.size > 0, "Expected a regular pinned input");
8371
+ const input = await open13(pin.path, "r");
8372
+ try {
8373
+ const after = await input.stat();
8374
+ check(after.dev === before.dev && after.ino === before.ino && after.size === before.size, "Pinned input changed");
8375
+ await pipeline2(input.createReadStream({ autoClose: false, start: 0, end: before.size - 1 }), createWriteStream(to, { flags: "wx", mode: 384 }));
8376
+ } finally {
8377
+ await input.close();
8378
+ }
8379
+ check((await lstat20(to)).size === before.size && await sum(to) === pin.sha256, "Pinned input digest mismatch");
8380
+ }
8381
+ async function regular(root, path) {
8382
+ const file = join34(root, path);
8383
+ check((await lstat20(file)).isFile() && await realpath11(file) === file, "Required bundle member is not a regular file");
8384
+ return file;
8385
+ }
8386
+ async function elf(path, appImage = false) {
8387
+ const input = await open13(path, "r");
8388
+ try {
8389
+ const h = Buffer.alloc(20);
8390
+ const { bytesRead } = await input.read(h, 0, h.length, 0);
8391
+ check(bytesRead === 20 && h.toString("hex", 0, 6) === "7f454c460201" && h.readUInt16LE(18) === 62 && (!appImage || h.toString("hex", 8, 11) === "414902"), "Expected native Linux x64 executable");
8392
+ } finally {
8393
+ await input.close();
8394
+ }
8395
+ }
8396
+ async function normalizeTree(root, dir = root) {
8397
+ for (const name of await readdir11(dir)) {
8398
+ const file = join34(dir, name);
8399
+ const st = await lstat20(file);
8400
+ if (st.isSymbolicLink()) {
8401
+ check(!isAbsolute6(await readlink3(file)), "Absolute bundle symlink");
8402
+ const target = relative5(root, await realpath11(file));
8403
+ check(target !== ".." && !target.startsWith("../") && !isAbsolute6(target), "Escaping bundle symlink");
8404
+ } else if (st.isDirectory()) {
8405
+ await chmod4(file, 493);
8406
+ await normalizeTree(root, file);
8407
+ } else {
8408
+ check(st.isFile(), "Unsupported bundle entry");
8409
+ await chmod4(file, st.mode & 73 ? 493 : 420);
8410
+ }
8411
+ }
8412
+ }
8413
+ async function normalizeBuildTimes(directory, epoch) {
8414
+ for (const name of (await readdir11(directory)).toSorted()) {
8415
+ const path = join34(directory, name);
8416
+ const info = await lstat20(path);
8417
+ if (info.isSymbolicLink()) {
8418
+ await lutimes(path, epoch, epoch);
8419
+ } else if (info.isDirectory()) {
8420
+ await normalizeBuildTimes(path, epoch);
8421
+ } else {
8422
+ check(info.isFile(), "Unsupported packaging entry");
8423
+ await utimes(path, epoch, epoch);
8424
+ }
8425
+ }
8426
+ await chmod4(directory, 493);
8427
+ await utimes(directory, epoch, epoch);
8428
+ }
8429
+ async function write(root, path, value, mode = 420) {
8430
+ const target = join34(root, path);
8431
+ await mkdir12(dirname15(target), { recursive: true });
8432
+ await writeFile12(target, value, { flag: "wx", mode });
8433
+ await chmod4(target, mode);
8434
+ }
8435
+ function validatePolicy(policy) {
8436
+ check([policy.bundleRoot, policy.artifactStem, policy.desktopId].every((n) => component.test(n)) && /^[a-z0-9][a-z0-9+.-]+$/.test(policy.packageName) && [policy.launcher, policy.icon, ...policy.debSetuid.map((item) => item.path)].every(relativeFiles) && policy.debSetuid.every((item) => sha256.test(item.sha256)) && new Set(policy.debSetuid.map((item) => item.path)).size === policy.debSetuid.length && /^[A-Z][A-Z0-9_]*_LINUX_PACKAGE_FORMAT$/.test(policy.formatEnvironment) && policy.mimeTypes.every((x) => /^x-scheme-handler\/[a-z][a-z0-9+.-]*$/.test(x)) && [policy.name, policy.description, policy.maintainer, policy.homepage].every(text2) && policy.categories.every((x) => /^[A-Za-z0-9]+$/.test(x)) && policy.dependencies.every((x) => /^[a-z0-9][a-z0-9+.-]*(?: \| [a-z0-9][a-z0-9+.-]*)*$/.test(x)), "Invalid app Linux packaging policy");
8437
+ check(new URL(policy.homepage).protocol === "https:", "Expected HTTPS homepage");
8438
+ }
8439
+ async function buildLinuxFormats(input, host) {
8440
+ const { tag, sourceSha, expectedSourceSha, sourceDateEpoch, policy } = input;
8441
+ check(host.os === "linux" && host.arch === "x64", "Requires native Linux x64");
8442
+ check(/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) && /^[a-f0-9]{40}$/.test(sourceSha) && sourceSha === expectedSourceSha, "Wrong protected build source or tag");
8443
+ check(Number.isSafeInteger(sourceDateEpoch) && sourceDateEpoch > 0 && sourceDateEpoch <= 4294967295, "Expected valid protected SOURCE_DATE_EPOCH");
8444
+ const env = { SOURCE_DATE_EPOCH: String(sourceDateEpoch), LC_ALL: "C", TZ: "UTC" };
8445
+ validatePolicy(policy);
8446
+ const requested = resolve17(input.output);
8447
+ const parent = await realpath11(dirname15(requested));
8448
+ const output = join34(parent, basename16(requested));
8449
+ const work = await mkdtemp11(join34(parent, ".linux-formats-"));
8450
+ try {
8451
+ const archive = join34(work, "payload.tar.zst");
8452
+ const tool = join34(work, "appimagetool");
8453
+ const runtime = join34(work, "runtime");
8454
+ for (const [pin, dest] of [
8455
+ [input.archive, archive],
8456
+ [input.tool, tool],
8457
+ [input.runtime, runtime]
8458
+ ])
8459
+ await exactCopy(pin, dest);
8460
+ await elf(tool, true);
8461
+ await elf(runtime, true);
8462
+ await host.inspectAppArchive(archive);
8463
+ check((await lstat20(archive)).isFile() && await sum(archive) === input.archive.sha256, "Payload changed during app inspection");
8464
+ await chmod4(tool, 448);
8465
+ const extracted = join34(work, "extract");
8466
+ await mkdir12(extracted);
8467
+ await host.run("tar", [
8468
+ "--zstd",
8469
+ "--extract",
8470
+ "--file",
8471
+ archive,
8472
+ "--directory",
8473
+ extracted,
8474
+ "--no-same-owner",
8475
+ "--no-same-permissions"
8476
+ ], { env });
8477
+ const source = join34(extracted, policy.bundleRoot);
8478
+ check((await lstat20(source)).isDirectory() && await realpath11(source) === source, "Wrong extracted app root");
8479
+ await chmod4(source, 493);
8480
+ await normalizeTree(source);
8481
+ await elf(await regular(source, policy.launcher));
8482
+ for (const pin of policy.debSetuid) {
8483
+ const file = await regular(source, pin.path);
8484
+ await elf(file);
8485
+ check(await sum(file) === pin.sha256, "DEB setuid helper differs from trusted pin");
8486
+ }
8487
+ const icon = await regular(source, policy.icon);
8488
+ check(policy.icon.endsWith(".svg"), "Expected an SVG application icon");
8489
+ const stem = `${policy.artifactStem}-${tag}-linux-x64`;
8490
+ const debName = `${stem}.deb`;
8491
+ const imageName = `${stem}.AppImage`;
8492
+ const dest = join34(work, "result");
8493
+ await mkdir12(dest);
8494
+ const version = tag.slice(1);
8495
+ const installed = `usr/lib/${policy.packageName}`;
8496
+ const desktopFile = `${policy.desktopId}.desktop`;
8497
+ const desktop = [
8498
+ "[Desktop Entry]",
8499
+ "Type=Application",
8500
+ `Name=${policy.name}`,
8501
+ `Comment=${policy.description}`,
8502
+ `Exec=${policy.packageName} %U`,
8503
+ `Icon=${policy.desktopId}`,
8504
+ `Categories=${policy.categories.join(";")};`,
8505
+ ...policy.mimeTypes.length ? [`MimeType=${policy.mimeTypes.join(";")};`] : [],
8506
+ "Terminal=false",
8507
+ ""
8508
+ ].join(`
8509
+ `);
8510
+ for (const format of ["deb", "appimage"]) {
8511
+ const tree = join34(work, format);
8512
+ await mkdir12(join34(tree, "usr", "lib"), { recursive: true });
8513
+ const bundle = join34(tree, installed);
8514
+ await cp(source, bundle, { recursive: true, verbatimSymlinks: true });
8515
+ await normalizeTree(bundle);
8516
+ await write(tree, `usr/share/applications/${desktopFile}`, desktop);
8517
+ const iconDest = join34(tree, `usr/share/icons/hicolor/scalable/apps/${policy.desktopId}.svg`);
8518
+ await mkdir12(dirname15(iconDest), { recursive: true });
8519
+ await cp(icon, iconDest, { force: false, errorOnExist: true });
8520
+ await chmod4(iconDest, 420);
8521
+ if (format === "deb") {
8522
+ for (const pin of policy.debSetuid)
8523
+ await chmod4(await regular(bundle, pin.path), 2541);
8524
+ await write(tree, `usr/bin/${policy.packageName}`, `#!/bin/sh
8525
+ export ${policy.formatEnvironment}=deb
8526
+ exec '/${installed}/${policy.launcher}' "$@"
8527
+ `, 493);
8528
+ await write(tree, "DEBIAN/control", [
8529
+ `Package: ${policy.packageName}`,
8530
+ `Version: ${version}`,
8531
+ "Architecture: amd64",
8532
+ `Maintainer: ${policy.maintainer}`,
8533
+ `Description: ${policy.description}`,
8534
+ `Homepage: ${policy.homepage}`,
8535
+ ...policy.dependencies.length ? [`Depends: ${policy.dependencies.join(", ")}`] : [],
8536
+ ""
8537
+ ].join(`
8538
+ `));
8539
+ await normalizeBuildTimes(tree, sourceDateEpoch);
8540
+ await host.run("dpkg-deb", ["--root-owner-group", "--threads-max=1", "-Zxz", "--build", tree, join34(dest, debName)], { env });
8541
+ } else {
8542
+ const rootIcon = join34(tree, `${policy.desktopId}.svg`);
8543
+ await cp(icon, rootIcon, { force: false, errorOnExist: true });
8544
+ await chmod4(rootIcon, 420);
8545
+ await write(tree, desktopFile, desktop);
8546
+ await write(tree, "AppRun", [
8547
+ "#!/bin/sh",
8548
+ "set -eu",
8549
+ 'root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',
8550
+ `export ${policy.formatEnvironment}=appimage`,
8551
+ `exec "$root/${installed}/${policy.launcher}" "$@"`,
8552
+ ""
8553
+ ].join(`
8554
+ `), 493);
8555
+ await normalizeBuildTimes(tree, sourceDateEpoch);
8556
+ await host.run("appimagetool", ["--no-appstream", "--runtime-file", runtime, tree, join34(dest, imageName)], {
8557
+ executable: tool,
8558
+ env: { ...env, ARCH: "x86_64", VERSION: version, APPIMAGE_EXTRACT_AND_RUN: "1" }
8559
+ });
8560
+ }
8561
+ }
8562
+ const artifacts = [];
8563
+ for (const name of [debName, imageName]) {
8564
+ const path = await regular(dest, name);
8565
+ const size = (await lstat20(path)).size;
8566
+ check(size > 0, "Empty produced artifact");
8567
+ artifacts.push({ name, size, sha256: await sum(path) });
8568
+ }
8569
+ const receipt = {
8570
+ schema: "linux-package-formats/v1",
8571
+ tag,
8572
+ sourceSha,
8573
+ sourceDateEpoch,
8574
+ platform: "linux-x64",
8575
+ updateArchiveSha256: input.archive.sha256,
8576
+ artifacts
8577
+ };
8578
+ await mkdir12(output);
8579
+ try {
8580
+ for (const item of artifacts)
8581
+ await cp(join34(dest, item.name), join34(output, basename16(item.name)), {
8582
+ force: false,
8583
+ errorOnExist: true
8584
+ });
8585
+ await write(output, "linux-format-build.json", JSON.stringify(receipt) + `
8586
+ `);
8587
+ } catch (error) {
8588
+ await rm11(output, { recursive: true, force: true });
8589
+ throw error;
8590
+ }
8591
+ return receipt;
8592
+ } finally {
8593
+ await rm11(work, { recursive: true, force: true });
8594
+ }
8595
+ }
8332
8596
  export {
8597
+ buildLinuxFormats,
8333
8598
  createDailyNativeReceipt,
8334
8599
  createGitHubPromotionProvider,
8335
8600
  createGitHubReleasePublisher,
@@ -1 +1 @@
1
- {"version":"0.4.0","commit":"036b5b3e268cad30543e62668b82ca46287d761d"}
1
+ {"version":"0.5.0","commit":"4fd311cbc06e856436d905add755438537fb53dd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/app-framework-release-tools",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Host-side release tooling for @adea-ai/app-framework apps, on Effect: the release CLIs and the framework package publish. Installing it never adds Effect to the framework itself.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {