@inquirerer/utils 3.2.5 → 3.3.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/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, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
3
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck, suppressUpdateCheck } 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, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
4
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck, suppressUpdateCheck } from './update-check';
@@ -34,6 +34,25 @@ export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.Pr
34
34
  skip: false;
35
35
  };
36
36
  export declare function clearUpdateCache(toolName: string): boolean;
37
+ /**
38
+ * Write a cache entry that suppresses the update notification.
39
+ *
40
+ * After a CLI `update` command installs a new version, the currently running
41
+ * binary still reports the OLD version via getPackageJson(__dirname). If we
42
+ * merely clear the cache, the next command will fetch the latest from npm and
43
+ * compare it against the stale pkgVersion, producing a false-positive
44
+ * "Update available" message.
45
+ *
46
+ * By writing the current binary's version as `latestVersion`, the next
47
+ * checkForUpdates call sees latestVersion === pkgVersion and returns
48
+ * hasUpdate: false. Once the cache expires (24 h by default), a fresh check
49
+ * runs against the (by then correct) new binary version.
50
+ *
51
+ * @param toolName - Tool name used for appstash directory (e.g., 'pgpm')
52
+ * @param currentVersion - The version of the currently running binary
53
+ * @returns true if the cache was written successfully
54
+ */
55
+ export declare function suppressUpdateCheck(toolName: string, currentVersion: string): boolean;
37
56
  /**
38
57
  * Checks for updates to a package and caches the result.
39
58
  * Uses appstash for configuration storage.
@@ -52,6 +52,43 @@ export function clearUpdateCache(toolName) {
52
52
  catch { }
53
53
  return false;
54
54
  }
55
+ /**
56
+ * Write a cache entry that suppresses the update notification.
57
+ *
58
+ * After a CLI `update` command installs a new version, the currently running
59
+ * binary still reports the OLD version via getPackageJson(__dirname). If we
60
+ * merely clear the cache, the next command will fetch the latest from npm and
61
+ * compare it against the stale pkgVersion, producing a false-positive
62
+ * "Update available" message.
63
+ *
64
+ * By writing the current binary's version as `latestVersion`, the next
65
+ * checkForUpdates call sees latestVersion === pkgVersion and returns
66
+ * hasUpdate: false. Once the cache expires (24 h by default), a fresh check
67
+ * runs against the (by then correct) new binary version.
68
+ *
69
+ * @param toolName - Tool name used for appstash directory (e.g., 'pgpm')
70
+ * @param currentVersion - The version of the currently running binary
71
+ * @returns true if the cache was written successfully
72
+ */
73
+ export function suppressUpdateCheck(toolName, currentVersion) {
74
+ try {
75
+ const dirs = appstash(toolName);
76
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
77
+ if (!fs.existsSync(dirs.cache)) {
78
+ fs.mkdirSync(dirs.cache, { recursive: true });
79
+ }
80
+ fs.writeFileSync(cacheFile, JSON.stringify({
81
+ latestVersion: currentVersion,
82
+ timestamp: Date.now()
83
+ }));
84
+ return true;
85
+ }
86
+ catch {
87
+ // If writing fails, fall back to clearing the old cache
88
+ clearUpdateCache(toolName);
89
+ return false;
90
+ }
91
+ }
55
92
  function isNewerVersion(latest, current) {
56
93
  if (semver.valid(latest) && semver.valid(current)) {
57
94
  return semver.gt(latest, current);
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, clearUpdateCache, shouldSkipUpdateCheck } from './update-check';
3
+ export { checkForUpdates, clearUpdateCache, shouldSkipUpdateCheck, suppressUpdateCheck } 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.clearUpdateCache = exports.checkForUpdates = exports.getPackageName = exports.getPackageVersion = exports.getPackageJson = exports.cliExitWithError = exports.extractFirst = exports.parseArgv = void 0;
3
+ exports.suppressUpdateCheck = 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; } });
@@ -14,3 +14,4 @@ var update_check_1 = require("./update-check");
14
14
  Object.defineProperty(exports, "checkForUpdates", { enumerable: true, get: function () { return update_check_1.checkForUpdates; } });
15
15
  Object.defineProperty(exports, "clearUpdateCache", { enumerable: true, get: function () { return update_check_1.clearUpdateCache; } });
16
16
  Object.defineProperty(exports, "shouldSkipUpdateCheck", { enumerable: true, get: function () { return update_check_1.shouldSkipUpdateCheck; } });
17
+ Object.defineProperty(exports, "suppressUpdateCheck", { enumerable: true, get: function () { return update_check_1.suppressUpdateCheck; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirerer/utils",
3
- "version": "3.2.5",
3
+ "version": "3.3.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "CLI lifecycle utilities for building command-line applications",
6
6
  "main": "index.js",
@@ -38,5 +38,5 @@
38
38
  "makage": "0.1.10"
39
39
  },
40
40
  "keywords": [],
41
- "gitHead": "fd9721cb17389c4e2f9847169d5a42de2f9746dd"
41
+ "gitHead": "d41fae5dc39192143f7ca9bd0291eb97207e63d6"
42
42
  }
package/update-check.d.ts CHANGED
@@ -34,6 +34,25 @@ export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.Pr
34
34
  skip: false;
35
35
  };
36
36
  export declare function clearUpdateCache(toolName: string): boolean;
37
+ /**
38
+ * Write a cache entry that suppresses the update notification.
39
+ *
40
+ * After a CLI `update` command installs a new version, the currently running
41
+ * binary still reports the OLD version via getPackageJson(__dirname). If we
42
+ * merely clear the cache, the next command will fetch the latest from npm and
43
+ * compare it against the stale pkgVersion, producing a false-positive
44
+ * "Update available" message.
45
+ *
46
+ * By writing the current binary's version as `latestVersion`, the next
47
+ * checkForUpdates call sees latestVersion === pkgVersion and returns
48
+ * hasUpdate: false. Once the cache expires (24 h by default), a fresh check
49
+ * runs against the (by then correct) new binary version.
50
+ *
51
+ * @param toolName - Tool name used for appstash directory (e.g., 'pgpm')
52
+ * @param currentVersion - The version of the currently running binary
53
+ * @returns true if the cache was written successfully
54
+ */
55
+ export declare function suppressUpdateCheck(toolName: string, currentVersion: string): boolean;
37
56
  /**
38
57
  * Checks for updates to a package and caches the result.
39
58
  * Uses appstash for configuration storage.
package/update-check.js CHANGED
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.checkForUpdates = void 0;
40
40
  exports.shouldSkipUpdateCheck = shouldSkipUpdateCheck;
41
41
  exports.clearUpdateCache = clearUpdateCache;
42
+ exports.suppressUpdateCheck = suppressUpdateCheck;
42
43
  const appstash_1 = require("appstash");
43
44
  const fs = __importStar(require("fs"));
44
45
  const path = __importStar(require("path"));
@@ -93,6 +94,43 @@ function clearUpdateCache(toolName) {
93
94
  catch { }
94
95
  return false;
95
96
  }
97
+ /**
98
+ * Write a cache entry that suppresses the update notification.
99
+ *
100
+ * After a CLI `update` command installs a new version, the currently running
101
+ * binary still reports the OLD version via getPackageJson(__dirname). If we
102
+ * merely clear the cache, the next command will fetch the latest from npm and
103
+ * compare it against the stale pkgVersion, producing a false-positive
104
+ * "Update available" message.
105
+ *
106
+ * By writing the current binary's version as `latestVersion`, the next
107
+ * checkForUpdates call sees latestVersion === pkgVersion and returns
108
+ * hasUpdate: false. Once the cache expires (24 h by default), a fresh check
109
+ * runs against the (by then correct) new binary version.
110
+ *
111
+ * @param toolName - Tool name used for appstash directory (e.g., 'pgpm')
112
+ * @param currentVersion - The version of the currently running binary
113
+ * @returns true if the cache was written successfully
114
+ */
115
+ function suppressUpdateCheck(toolName, currentVersion) {
116
+ try {
117
+ const dirs = (0, appstash_1.appstash)(toolName);
118
+ const cacheFile = path.join(dirs.cache, CACHE_FILENAME);
119
+ if (!fs.existsSync(dirs.cache)) {
120
+ fs.mkdirSync(dirs.cache, { recursive: true });
121
+ }
122
+ fs.writeFileSync(cacheFile, JSON.stringify({
123
+ latestVersion: currentVersion,
124
+ timestamp: Date.now()
125
+ }));
126
+ return true;
127
+ }
128
+ catch {
129
+ // If writing fails, fall back to clearing the old cache
130
+ clearUpdateCache(toolName);
131
+ return false;
132
+ }
133
+ }
96
134
  function isNewerVersion(latest, current) {
97
135
  if (semver_1.default.valid(latest) && semver_1.default.valid(current)) {
98
136
  return semver_1.default.gt(latest, current);