revdeck 0.13.0 → 0.14.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/daemon.js CHANGED
@@ -1413,7 +1413,7 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
1413
1413
  init_redact();
1414
1414
 
1415
1415
  // src/version.ts
1416
- var VERSION = "0.13.0";
1416
+ var VERSION = "0.14.0";
1417
1417
  var PROTOCOL_VERSION = 2;
1418
1418
 
1419
1419
  // src/daemon/main.ts
@@ -3786,6 +3786,147 @@ function toReviewView(review, now = Date.now()) {
3786
3786
  };
3787
3787
  }
3788
3788
 
3789
+ // src/daemon/update.ts
3790
+ init_errors();
3791
+
3792
+ // src/core/update.ts
3793
+ function parseVersion(value) {
3794
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value.trim());
3795
+ if (!match) return null;
3796
+ return {
3797
+ major: Number(match[1]),
3798
+ minor: Number(match[2]),
3799
+ patch: Number(match[3]),
3800
+ prerelease: match[4] ? match[4].split(".") : []
3801
+ };
3802
+ }
3803
+ function comparePrerelease(left, right) {
3804
+ if (!left.length && !right.length) return 0;
3805
+ if (!left.length) return 1;
3806
+ if (!right.length) return -1;
3807
+ const length = Math.max(left.length, right.length);
3808
+ for (let index = 0; index < length; index += 1) {
3809
+ const a = left[index];
3810
+ const b = right[index];
3811
+ if (a === void 0) return -1;
3812
+ if (b === void 0) return 1;
3813
+ const aNumeric = /^\d+$/.test(a);
3814
+ const bNumeric = /^\d+$/.test(b);
3815
+ if (aNumeric && bNumeric) {
3816
+ const delta = Number(a) - Number(b);
3817
+ if (delta !== 0) return delta < 0 ? -1 : 1;
3818
+ } else if (aNumeric !== bNumeric) {
3819
+ return aNumeric ? -1 : 1;
3820
+ } else {
3821
+ const delta = a < b ? -1 : a > b ? 1 : 0;
3822
+ if (delta !== 0) return delta;
3823
+ }
3824
+ }
3825
+ return 0;
3826
+ }
3827
+ function compareVersions(left, right) {
3828
+ const a = parseVersion(left);
3829
+ const b = parseVersion(right);
3830
+ if (!a || !b) return 0;
3831
+ const delta = a.major - b.major || a.minor - b.minor || a.patch - b.patch;
3832
+ if (delta !== 0) return delta < 0 ? -1 : 1;
3833
+ return comparePrerelease(a.prerelease, b.prerelease);
3834
+ }
3835
+ function isNewerVersion(latest, current2) {
3836
+ return compareVersions(latest, current2) > 0;
3837
+ }
3838
+
3839
+ // src/daemon/update.ts
3840
+ init_locale();
3841
+ var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
3842
+ var ERROR_TTL_MS = 5 * 60 * 1e3;
3843
+ var REQUEST_TIMEOUT_MS = 5e3;
3844
+ var DIST_TAGS_URL = "https://registry.npmjs.org/-/package/revdeck/dist-tags";
3845
+ var RELEASE_TAG_URL = "https://github.com/katrov/revdeck/releases/tag/v";
3846
+ var UpdateChecker = class {
3847
+ currentVersion;
3848
+ fetchImpl;
3849
+ now;
3850
+ ttlMs;
3851
+ enabled;
3852
+ cache = null;
3853
+ pending = null;
3854
+ constructor(options = {}) {
3855
+ this.currentVersion = options.currentVersion ?? VERSION;
3856
+ this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
3857
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
3858
+ this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
3859
+ this.enabled = (options.env ?? process.env).REVDECK_UPDATE_CHECK !== "0";
3860
+ }
3861
+ base() {
3862
+ return {
3863
+ enabled: this.enabled,
3864
+ current: this.currentVersion,
3865
+ latest: null,
3866
+ updateAvailable: false,
3867
+ releaseUrl: null,
3868
+ checkedAt: null
3869
+ };
3870
+ }
3871
+ async check(force = false) {
3872
+ if (!this.enabled) return this.base();
3873
+ const now = this.now().getTime();
3874
+ if (!force && this.cache) {
3875
+ const ttl = this.cache.info.error ? ERROR_TTL_MS : this.ttlMs;
3876
+ if (now - this.cache.at < ttl) return this.cache.info;
3877
+ }
3878
+ if (this.pending) return this.pending;
3879
+ this.pending = this.fetchLatest().then((latest) => this.success(latest)).catch((error) => this.failure(error)).finally(() => {
3880
+ this.pending = null;
3881
+ });
3882
+ return this.pending;
3883
+ }
3884
+ async fetchLatest() {
3885
+ const response = await this.fetchImpl(DIST_TAGS_URL, {
3886
+ headers: {
3887
+ accept: "application/json",
3888
+ "user-agent": `revdeck/${this.currentVersion}`
3889
+ },
3890
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
3891
+ });
3892
+ if (!response.ok) {
3893
+ throw new Error(`npm registry: HTTP ${response.status}`);
3894
+ }
3895
+ const data = await response.json();
3896
+ const latest = typeof data.latest === "string" ? data.latest.trim().replace(/^v/, "") : "";
3897
+ if (!parseVersion(latest)) {
3898
+ throw new Error(tr("npm registry: \u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F \u0432 dist-tags", "npm registry: invalid version in dist-tags"));
3899
+ }
3900
+ return latest;
3901
+ }
3902
+ success(latest) {
3903
+ const updateAvailable = isNewerVersion(latest, this.currentVersion);
3904
+ const info = {
3905
+ enabled: true,
3906
+ current: this.currentVersion,
3907
+ latest,
3908
+ updateAvailable,
3909
+ releaseUrl: updateAvailable ? `${RELEASE_TAG_URL}${latest}` : null,
3910
+ checkedAt: this.now().toISOString()
3911
+ };
3912
+ this.cache = { info, at: this.now().getTime() };
3913
+ return info;
3914
+ }
3915
+ failure(error) {
3916
+ const previous = this.cache?.info;
3917
+ const info = {
3918
+ ...this.base(),
3919
+ latest: previous?.latest ?? null,
3920
+ updateAvailable: previous?.updateAvailable ?? false,
3921
+ releaseUrl: previous?.releaseUrl ?? null,
3922
+ checkedAt: previous?.checkedAt ?? null,
3923
+ error: tr(`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F: ${messageOf(error)}`, `could not check for updates: ${messageOf(error)}`).slice(0, 400)
3924
+ };
3925
+ this.cache = { info, at: this.now().getTime() };
3926
+ return info;
3927
+ }
3928
+ };
3929
+
3789
3930
  // src/cli/format.ts
3790
3931
  init_redact();
3791
3932
  init_locale();
@@ -4306,6 +4447,7 @@ var ReviewService = class {
4306
4447
  now;
4307
4448
  refreshTtlMs;
4308
4449
  syncIntervalMs;
4450
+ updates;
4309
4451
  timer = null;
4310
4452
  syncing = false;
4311
4453
  /** Ревью, которые уже обновляются: не запускаем параллельный refresh из UI и sync. */
@@ -4321,6 +4463,10 @@ var ReviewService = class {
4321
4463
  this.refreshTtlMs = options.refreshTtlMs ?? 6e4;
4322
4464
  this.syncIntervalMs = options.syncIntervalMs ?? 12e4;
4323
4465
  this.providerFactory = options.providerFactory ?? (async (ref, root) => createProvider(ref, { root }));
4466
+ this.updates = new UpdateChecker({
4467
+ now: this.now,
4468
+ ...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
4469
+ });
4324
4470
  this.events.setMaxListeners(50);
4325
4471
  }
4326
4472
  close() {
@@ -5108,6 +5254,10 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0444\u0438\u0447\
5108
5254
  if (!found) return null;
5109
5255
  return { path: found.path, status: found.status, binary: found.binary, hunks: found.hunks };
5110
5256
  }
5257
+ /** Последняя версия revdeck в npm; force=true — ручная проверка из настроек. */
5258
+ async updateInfo(force = false) {
5259
+ return this.updates.check(force);
5260
+ }
5111
5261
  /**
5112
5262
  * Полный файл на head (или base для удалённого файла), чтобы UI раскрывал
5113
5263
  * скрытые между hunks строки. Локальный git дешевле API платформы, но
@@ -6614,6 +6764,11 @@ data: ${JSON.stringify(event)}
6614
6764
  reply(res, 401, { ok: false, error: "\u043D\u0435\u0442 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u0438" });
6615
6765
  return;
6616
6766
  }
6767
+ if (req.method === "GET" && url.pathname === "/api/update") {
6768
+ const update = await service.updateInfo(url.searchParams.get("refresh") === "1");
6769
+ reply(res, 200, { ok: true, update });
6770
+ return;
6771
+ }
6617
6772
  if (req.method === "GET" && url.pathname === "/api/health") {
6618
6773
  reply(res, 200, { ok: true, version: options.version ?? "dev", reviews: service.listReviews().length });
6619
6774
  return;