@withone/cli 1.12.8 → 1.12.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.
Files changed (2) hide show
  1. package/dist/index.js +33 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4406,9 +4406,14 @@ validation rules, and platform-specific details.
4406
4406
  // src/commands/update.ts
4407
4407
  import { createRequire } from "module";
4408
4408
  import { spawn as spawn2 } from "child_process";
4409
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
4410
+ import { homedir } from "os";
4411
+ import { join } from "path";
4409
4412
  var require2 = createRequire(import.meta.url);
4410
4413
  var { version: currentVersion } = require2("../package.json");
4411
- async function checkLatestVersion() {
4414
+ var CACHE_PATH = join(homedir(), ".one", "update-check.json");
4415
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
4416
+ async function fetchLatestVersion() {
4412
4417
  try {
4413
4418
  const res = await fetch("https://registry.npmjs.org/@withone/cli/latest");
4414
4419
  if (!res.ok) return null;
@@ -4418,6 +4423,32 @@ async function checkLatestVersion() {
4418
4423
  return null;
4419
4424
  }
4420
4425
  }
4426
+ function readCache() {
4427
+ try {
4428
+ return JSON.parse(readFileSync(CACHE_PATH, "utf8"));
4429
+ } catch {
4430
+ return null;
4431
+ }
4432
+ }
4433
+ function writeCache(latestVersion) {
4434
+ try {
4435
+ mkdirSync(join(homedir(), ".one"), { recursive: true });
4436
+ writeFileSync(CACHE_PATH, JSON.stringify({ lastCheck: Date.now(), latestVersion }));
4437
+ } catch {
4438
+ }
4439
+ }
4440
+ async function checkLatestVersion() {
4441
+ const version2 = await fetchLatestVersion();
4442
+ if (version2) writeCache(version2);
4443
+ return version2;
4444
+ }
4445
+ async function checkLatestVersionCached() {
4446
+ const cache = readCache();
4447
+ if (cache && Date.now() - cache.lastCheck < CHECK_INTERVAL_MS) {
4448
+ return cache.latestVersion;
4449
+ }
4450
+ return checkLatestVersion();
4451
+ }
4421
4452
  function getCurrentVersion() {
4422
4453
  return currentVersion;
4423
4454
  }
@@ -4508,7 +4539,7 @@ program.hook("preAction", (thisCommand) => {
4508
4539
  }
4509
4540
  const commandName = thisCommand.args?.[0];
4510
4541
  if (commandName !== "update") {
4511
- updateCheckPromise = checkLatestVersion();
4542
+ updateCheckPromise = checkLatestVersionCached();
4512
4543
  }
4513
4544
  });
4514
4545
  program.hook("postAction", async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/cli",
3
- "version": "1.12.8",
3
+ "version": "1.12.9",
4
4
  "description": "CLI for managing One",
5
5
  "type": "module",
6
6
  "files": [