@inquirerer/utils 3.2.2 → 3.2.3

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/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { parseArgv, extractFirst, cliExitWithError, getPackageJson, getPackageVersion, getPackageName } from 'inquirerer';
2
2
  export type { ParsedArgs, ParseArgvOptions, CliExitOptions, PackageJson } from 'inquirerer';
3
- export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
3
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
4
4
  export type { UpdateCheckOptions, UpdateCheckResult } from './update-check';
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Re-export core CLI utilities from inquirerer
2
2
  export { parseArgv, extractFirst, cliExitWithError, getPackageJson, getPackageVersion, getPackageName } from 'inquirerer';
3
3
  // Update checking (requires appstash, not available in inquirerer)
4
- export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
4
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
@@ -33,6 +33,7 @@ export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.Pr
33
33
  } | {
34
34
  skip: false;
35
35
  };
36
+ export declare function clearUpdateCache(toolName: string): boolean;
36
37
  /**
37
38
  * Checks for updates to a package and caches the result.
38
39
  * Uses appstash for configuration storage.
@@ -1,6 +1,7 @@
1
1
  import { appstash } from 'appstash';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
+ import semver from 'semver';
4
5
  /**
5
6
  * Converts a tool name to an environment variable name.
6
7
  * e.g., "pgpm" -> "PGPM", "my-cli" -> "MY_CLI"
@@ -36,8 +37,27 @@ export function shouldSkipUpdateCheck(toolName, env = process.env) {
36
37
  }
37
38
  return { skip: false };
38
39
  }
40
+ const CACHE_FILENAME = 'update-check.json';
39
41
  const DEFAULT_TTL = 24 * 60 * 60 * 1000; // 24 hours
40
42
  const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
43
+ export function clearUpdateCache(toolName) {
44
+ try {
45
+ const dirs = appstash(toolName);
46
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
47
+ if (fs.existsSync(cacheFile)) {
48
+ fs.unlinkSync(cacheFile);
49
+ return true;
50
+ }
51
+ }
52
+ catch { }
53
+ return false;
54
+ }
55
+ function isNewerVersion(latest, current) {
56
+ if (semver.valid(latest) && semver.valid(current)) {
57
+ return semver.gt(latest, current);
58
+ }
59
+ return latest !== current && latest > current;
60
+ }
41
61
  /**
42
62
  * Checks for updates to a package and caches the result.
43
63
  * Uses appstash for configuration storage.
@@ -66,17 +86,17 @@ export const checkForUpdates = async (options) => {
66
86
  }
67
87
  }
68
88
  const dirs = appstash(toolName);
69
- const cacheFile = path.join(dirs.cache, 'update-check.json');
89
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
70
90
  // Check cache first
71
91
  try {
72
92
  if (fs.existsSync(cacheFile)) {
73
93
  const cached = JSON.parse(fs.readFileSync(cacheFile, 'utf-8'));
74
94
  if (Date.now() - cached.timestamp < ttl) {
75
95
  return {
76
- hasUpdate: cached.latestVersion !== pkgVersion && cached.latestVersion > pkgVersion,
96
+ hasUpdate: isNewerVersion(cached.latestVersion, pkgVersion),
77
97
  currentVersion: pkgVersion,
78
98
  latestVersion: cached.latestVersion,
79
- message: cached.latestVersion > pkgVersion
99
+ message: isNewerVersion(cached.latestVersion, pkgVersion)
80
100
  ? `Update available: ${pkgVersion} -> ${cached.latestVersion}`
81
101
  : null
82
102
  };
@@ -113,10 +133,10 @@ export const checkForUpdates = async (options) => {
113
133
  // Cache write failed, continue anyway
114
134
  }
115
135
  return {
116
- hasUpdate: latestVersion !== pkgVersion && latestVersion > pkgVersion,
136
+ hasUpdate: isNewerVersion(latestVersion, pkgVersion),
117
137
  currentVersion: pkgVersion,
118
138
  latestVersion,
119
- message: latestVersion > pkgVersion
139
+ message: isNewerVersion(latestVersion, pkgVersion)
120
140
  ? `Update available: ${pkgVersion} -> ${latestVersion}`
121
141
  : null
122
142
  };
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { parseArgv, extractFirst, cliExitWithError, getPackageJson, getPackageVersion, getPackageName } from 'inquirerer';
2
2
  export type { ParsedArgs, ParseArgvOptions, CliExitOptions, PackageJson } from 'inquirerer';
3
- export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
3
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
4
4
  export type { UpdateCheckOptions, UpdateCheckResult } from './update-check';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldSkipUpdateCheck = exports.checkForUpdates = exports.getPackageName = exports.getPackageVersion = exports.getPackageJson = exports.cliExitWithError = exports.extractFirst = exports.parseArgv = void 0;
3
+ exports.shouldSkipUpdateCheck = exports.clearUpdateCache = exports.checkForUpdates = exports.getPackageName = exports.getPackageVersion = exports.getPackageJson = exports.cliExitWithError = exports.extractFirst = exports.parseArgv = void 0;
4
4
  // Re-export core CLI utilities from inquirerer
5
5
  var inquirerer_1 = require("inquirerer");
6
6
  Object.defineProperty(exports, "parseArgv", { enumerable: true, get: function () { return inquirerer_1.parseArgv; } });
@@ -12,4 +12,5 @@ Object.defineProperty(exports, "getPackageName", { enumerable: true, get: functi
12
12
  // Update checking (requires appstash, not available in inquirerer)
13
13
  var update_check_1 = require("./update-check");
14
14
  Object.defineProperty(exports, "checkForUpdates", { enumerable: true, get: function () { return update_check_1.checkForUpdates; } });
15
+ Object.defineProperty(exports, "clearUpdateCache", { enumerable: true, get: function () { return update_check_1.clearUpdateCache; } });
15
16
  Object.defineProperty(exports, "shouldSkipUpdateCheck", { enumerable: true, get: function () { return update_check_1.shouldSkipUpdateCheck; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirerer/utils",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "CLI lifecycle utilities for building command-line applications",
6
6
  "main": "index.js",
@@ -29,12 +29,14 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "appstash": "0.3.1",
32
- "inquirerer": "4.5.1"
32
+ "inquirerer": "4.5.1",
33
+ "semver": "^7.7.4"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/minimist": "^1.2.5",
37
+ "@types/semver": "^7.7.1",
36
38
  "makage": "0.1.10"
37
39
  },
38
40
  "keywords": [],
39
- "gitHead": "1d2795da97e2217a7df24b2942a0b4e5879ac16f"
41
+ "gitHead": "023d77afdbf727911d26dbcd37aa10e9eb4362c6"
40
42
  }
package/update-check.d.ts CHANGED
@@ -33,6 +33,7 @@ export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.Pr
33
33
  } | {
34
34
  skip: false;
35
35
  };
36
+ export declare function clearUpdateCache(toolName: string): boolean;
36
37
  /**
37
38
  * Checks for updates to a package and caches the result.
38
39
  * Uses appstash for configuration storage.
package/update-check.js CHANGED
@@ -32,12 +32,17 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.checkForUpdates = void 0;
37
40
  exports.shouldSkipUpdateCheck = shouldSkipUpdateCheck;
41
+ exports.clearUpdateCache = clearUpdateCache;
38
42
  const appstash_1 = require("appstash");
39
43
  const fs = __importStar(require("fs"));
40
44
  const path = __importStar(require("path"));
45
+ const semver_1 = __importDefault(require("semver"));
41
46
  /**
42
47
  * Converts a tool name to an environment variable name.
43
48
  * e.g., "pgpm" -> "PGPM", "my-cli" -> "MY_CLI"
@@ -73,8 +78,27 @@ function shouldSkipUpdateCheck(toolName, env = process.env) {
73
78
  }
74
79
  return { skip: false };
75
80
  }
81
+ const CACHE_FILENAME = 'update-check.json';
76
82
  const DEFAULT_TTL = 24 * 60 * 60 * 1000; // 24 hours
77
83
  const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
84
+ function clearUpdateCache(toolName) {
85
+ try {
86
+ const dirs = (0, appstash_1.appstash)(toolName);
87
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
88
+ if (fs.existsSync(cacheFile)) {
89
+ fs.unlinkSync(cacheFile);
90
+ return true;
91
+ }
92
+ }
93
+ catch { }
94
+ return false;
95
+ }
96
+ function isNewerVersion(latest, current) {
97
+ if (semver_1.default.valid(latest) && semver_1.default.valid(current)) {
98
+ return semver_1.default.gt(latest, current);
99
+ }
100
+ return latest !== current && latest > current;
101
+ }
78
102
  /**
79
103
  * Checks for updates to a package and caches the result.
80
104
  * Uses appstash for configuration storage.
@@ -103,17 +127,17 @@ const checkForUpdates = async (options) => {
103
127
  }
104
128
  }
105
129
  const dirs = (0, appstash_1.appstash)(toolName);
106
- const cacheFile = path.join(dirs.cache, 'update-check.json');
130
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
107
131
  // Check cache first
108
132
  try {
109
133
  if (fs.existsSync(cacheFile)) {
110
134
  const cached = JSON.parse(fs.readFileSync(cacheFile, 'utf-8'));
111
135
  if (Date.now() - cached.timestamp < ttl) {
112
136
  return {
113
- hasUpdate: cached.latestVersion !== pkgVersion && cached.latestVersion > pkgVersion,
137
+ hasUpdate: isNewerVersion(cached.latestVersion, pkgVersion),
114
138
  currentVersion: pkgVersion,
115
139
  latestVersion: cached.latestVersion,
116
- message: cached.latestVersion > pkgVersion
140
+ message: isNewerVersion(cached.latestVersion, pkgVersion)
117
141
  ? `Update available: ${pkgVersion} -> ${cached.latestVersion}`
118
142
  : null
119
143
  };
@@ -150,10 +174,10 @@ const checkForUpdates = async (options) => {
150
174
  // Cache write failed, continue anyway
151
175
  }
152
176
  return {
153
- hasUpdate: latestVersion !== pkgVersion && latestVersion > pkgVersion,
177
+ hasUpdate: isNewerVersion(latestVersion, pkgVersion),
154
178
  currentVersion: pkgVersion,
155
179
  latestVersion,
156
- message: latestVersion > pkgVersion
180
+ message: isNewerVersion(latestVersion, pkgVersion)
157
181
  ? `Update available: ${pkgVersion} -> ${latestVersion}`
158
182
  : null
159
183
  };