@nathanstephenson/flow 0.1.9-beta.1 → 0.1.9

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/build-id CHANGED
@@ -1 +1 @@
1
- 83c54249-3555-4f16-bfe2-c3cb050450f6
1
+ 235c05f3-6e6d-4e26-beea-f86917941ad2
@@ -442,6 +442,54 @@ import { execFile } from "node:child_process";
442
442
  import { promisify } from "node:util";
443
443
  import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, unlinkSync as unlinkSync3 } from "node:fs";
444
444
  import { join as join4 } from "node:path";
445
+
446
+ // src/daemon/release-checker.ts
447
+ var STABLE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
448
+ var BETA = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-beta\.(0|[1-9]\d*)$/;
449
+ var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
450
+ function parsed(version) {
451
+ const match = SEMVER.exec(version);
452
+ if (!match) return void 0;
453
+ return {
454
+ core: [Number(match[1]), Number(match[2]), Number(match[3])],
455
+ prerelease: match[4]?.split(".") ?? []
456
+ };
457
+ }
458
+ function compareIdentifiers(left, right) {
459
+ const leftNumber = /^\d+$/.test(left) ? Number(left) : void 0;
460
+ const rightNumber = /^\d+$/.test(right) ? Number(right) : void 0;
461
+ if (leftNumber !== void 0 && rightNumber !== void 0) return Math.sign(leftNumber - rightNumber);
462
+ if (leftNumber !== void 0) return -1;
463
+ if (rightNumber !== void 0) return 1;
464
+ return left.localeCompare(right);
465
+ }
466
+ function compareVersions(left, right) {
467
+ const a = parsed(left), b = parsed(right);
468
+ if (!a || !b) throw new Error("Invalid semantic version");
469
+ for (let index = 0; index < 3; index += 1) {
470
+ const difference = a.core[index] - b.core[index];
471
+ if (difference) return Math.sign(difference);
472
+ }
473
+ if (!a.prerelease.length && !b.prerelease.length) return 0;
474
+ if (!a.prerelease.length) return 1;
475
+ if (!b.prerelease.length) return -1;
476
+ for (let index = 0; index < Math.max(a.prerelease.length, b.prerelease.length); index += 1) {
477
+ const av = a.prerelease[index], bv = b.prerelease[index];
478
+ if (av === void 0) return -1;
479
+ if (bv === void 0) return 1;
480
+ const difference = compareIdentifiers(av, bv);
481
+ if (difference) return difference;
482
+ }
483
+ return 0;
484
+ }
485
+ function isReleaseVersion(version) {
486
+ return STABLE.test(version) || BETA.test(version);
487
+ }
488
+ function newerReleaseVersion(installed, candidate) {
489
+ return isReleaseVersion(candidate) && compareVersions(candidate, installed) > 0;
490
+ }
491
+
492
+ // src/cli/systemd-update.ts
445
493
  var exec = promisify(execFile);
446
494
  function parseSystemdUpdate(value) {
447
495
  const c = value;
@@ -506,7 +554,7 @@ async function launchSystemdUpdate(root, c, request) {
506
554
  }
507
555
  function readSystemdRequest(root) {
508
556
  const r = JSON.parse(readFileSync3(requestPath(root), "utf8"));
509
- if (!r || typeof r.force !== "boolean" || r.id !== void 0 && !/^[a-f0-9-]{36}$/.test(r.id) || r.version !== void 0 && (typeof r.version !== "string" || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(r.version)) || r.id === void 0 !== (r.version === void 0)) throw new Error("Invalid systemd update request");
557
+ if (!r || typeof r.force !== "boolean" || r.id !== void 0 && !/^[a-f0-9-]{36}$/.test(r.id) || r.version !== void 0 && (typeof r.version !== "string" || !isReleaseVersion(r.version)) || r.id === void 0 !== (r.version === void 0)) throw new Error("Invalid systemd update request");
510
558
  return r;
511
559
  }
512
560
  function clearSystemdRequest(root) {
@@ -544,49 +592,6 @@ async function restoreSystemd(root, c, transaction, old, version) {
544
592
  }
545
593
  }
546
594
 
547
- // src/daemon/release-checker.ts
548
- var STABLE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
549
- var BETA = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-beta\.(0|[1-9]\d*)$/;
550
- var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
551
- function parsed(version) {
552
- const match = SEMVER.exec(version);
553
- if (!match) return void 0;
554
- return {
555
- core: [Number(match[1]), Number(match[2]), Number(match[3])],
556
- prerelease: match[4]?.split(".") ?? []
557
- };
558
- }
559
- function compareIdentifiers(left, right) {
560
- const leftNumber = /^\d+$/.test(left) ? Number(left) : void 0;
561
- const rightNumber = /^\d+$/.test(right) ? Number(right) : void 0;
562
- if (leftNumber !== void 0 && rightNumber !== void 0) return Math.sign(leftNumber - rightNumber);
563
- if (leftNumber !== void 0) return -1;
564
- if (rightNumber !== void 0) return 1;
565
- return left.localeCompare(right);
566
- }
567
- function compareVersions(left, right) {
568
- const a = parsed(left), b = parsed(right);
569
- if (!a || !b) throw new Error("Invalid semantic version");
570
- for (let index = 0; index < 3; index += 1) {
571
- const difference = a.core[index] - b.core[index];
572
- if (difference) return Math.sign(difference);
573
- }
574
- if (!a.prerelease.length && !b.prerelease.length) return 0;
575
- if (!a.prerelease.length) return 1;
576
- if (!b.prerelease.length) return -1;
577
- for (let index = 0; index < Math.max(a.prerelease.length, b.prerelease.length); index += 1) {
578
- const av = a.prerelease[index], bv = b.prerelease[index];
579
- if (av === void 0) return -1;
580
- if (bv === void 0) return 1;
581
- const difference = compareIdentifiers(av, bv);
582
- if (difference) return difference;
583
- }
584
- return 0;
585
- }
586
- function newerReleaseVersion(installed, candidate) {
587
- return (STABLE.test(candidate) || BETA.test(candidate)) && compareVersions(candidate, installed) > 0;
588
- }
589
-
590
595
  // src/cli/update.ts
591
596
  function npmExecutable() {
592
597
  for (const directory of (process.env.PATH ?? "").split(delimiter)) {
@@ -884,7 +889,7 @@ async function bootstrap() {
884
889
  if (!managed) throw new Error("Missing systemd update configuration");
885
890
  await assertSystemdOwner(managed, managed.updater, process.pid);
886
891
  }
887
- const lease = await install.register("83c54249-3555-4f16-bfe2-c3cb050450f6", root, args, process.env.FLOW_UPDATE_CAPABILITY ?? systemdCapability(root));
892
+ const lease = await install.register("235c05f3-6e6d-4e26-beea-f86917941ad2", root, args, process.env.FLOW_UPDATE_CAPABILITY ?? systemdCapability(root));
888
893
  delete process.env.FLOW_UPDATE_CAPABILITY;
889
894
  process.on("exit", lease.release);
890
895
  if (args[0] === "update") {
@@ -4,6 +4,7 @@ import { readFileSync, writeFileSync, unlinkSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { getHostStatus, waitUntil } from "./host-control.js";
6
6
  import { readHost } from "../daemon/ownership.js";
7
+ import { isReleaseVersion } from "../daemon/release-checker.js";
7
8
  const exec = promisify(execFile);
8
9
  export function parseSystemdUpdate(value) {
9
10
  const c = value;
@@ -82,7 +83,7 @@ export async function launchSystemdUpdate(root, c, request) {
82
83
  export function readSystemdRequest(root) {
83
84
  const r = JSON.parse(readFileSync(requestPath(root), 'utf8'));
84
85
  if (!r || typeof r.force !== 'boolean' || (r.id !== undefined && !/^[a-f0-9-]{36}$/.test(r.id)) ||
85
- (r.version !== undefined && (typeof r.version !== 'string' || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(r.version))) || ((r.id === undefined) !== (r.version === undefined)))
86
+ (r.version !== undefined && (typeof r.version !== 'string' || !isReleaseVersion(r.version))) || ((r.id === undefined) !== (r.version === undefined)))
86
87
  throw new Error('Invalid systemd update request');
87
88
  return r;
88
89
  }
@@ -49,9 +49,13 @@ export function compareVersions(left, right) {
49
49
  }
50
50
  return 0;
51
51
  }
52
+ /** The same exact-version policy applies to discovery and persisted update requests. */
53
+ export function isReleaseVersion(version) {
54
+ return STABLE.test(version) || BETA.test(version);
55
+ }
52
56
  /** A release must be stable or `X.Y.Z-beta.N`, and must advance rather than downgrade. */
53
57
  export function newerReleaseVersion(installed, candidate) {
54
- return (STABLE.test(candidate) || BETA.test(candidate)) && compareVersions(candidate, installed) > 0;
58
+ return isReleaseVersion(candidate) && compareVersions(candidate, installed) > 0;
55
59
  }
56
60
  export class ReleaseChecker {
57
61
  cached = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathanstephenson/flow",
3
- "version": "0.1.9-beta.1",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",