@inquirerer/utils 3.0.0 → 3.1.1
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 +1 -1
- package/esm/index.js +1 -1
- package/esm/update-check.d.ts +29 -0
- package/esm/update-check.js +57 -1
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/package.json +4 -4
- package/update-check.d.ts +29 -0
- package/update-check.js +58 -1
package/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { extractFirst } from './argv';
|
|
|
2
2
|
export type { ParsedArgs } from './argv';
|
|
3
3
|
export { cliExitWithError } from './cli-error';
|
|
4
4
|
export type { CliExitOptions } from './cli-error';
|
|
5
|
-
export { checkForUpdates } from './update-check';
|
|
5
|
+
export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
|
|
6
6
|
export type { UpdateCheckOptions, UpdateCheckResult } from './update-check';
|
|
7
7
|
export { getSelfPackageJson, getSelfVersion, getSelfName } from './package-json';
|
|
8
8
|
export type { PackageJsonInfo } from './package-json';
|
package/esm/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export { extractFirst } from './argv';
|
|
|
3
3
|
// CLI error handling
|
|
4
4
|
export { cliExitWithError } from './cli-error';
|
|
5
5
|
// Update checking
|
|
6
|
-
export { checkForUpdates } from './update-check';
|
|
6
|
+
export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
|
|
7
7
|
// Package.json utilities
|
|
8
8
|
export { getSelfPackageJson, getSelfVersion, getSelfName } from './package-json';
|
package/esm/update-check.d.ts
CHANGED
|
@@ -4,15 +4,44 @@ export interface UpdateCheckOptions {
|
|
|
4
4
|
registryBaseUrl?: string;
|
|
5
5
|
toolName?: string;
|
|
6
6
|
ttl?: number;
|
|
7
|
+
/** Force check even in CI or when skip env vars are set */
|
|
8
|
+
force?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface UpdateCheckResult {
|
|
9
11
|
hasUpdate: boolean;
|
|
10
12
|
currentVersion: string;
|
|
11
13
|
latestVersion: string | null;
|
|
12
14
|
message: string | null;
|
|
15
|
+
/** Whether the check was skipped due to CI or env vars */
|
|
16
|
+
skipped?: boolean;
|
|
17
|
+
/** Reason for skipping: 'ci', 'env', or 'tool-env' */
|
|
18
|
+
skipReason?: 'ci' | 'env' | 'tool-env';
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if update checking should be skipped based on environment variables.
|
|
22
|
+
*
|
|
23
|
+
* Skip conditions (in order of precedence):
|
|
24
|
+
* 1. CI environment (process.env.CI is truthy)
|
|
25
|
+
* 2. Generic skip: INQUIRERER_SKIP_UPDATE_CHECK is truthy
|
|
26
|
+
* 3. Tool-specific skip: {TOOLNAME}_SKIP_UPDATE_CHECK is truthy
|
|
27
|
+
*
|
|
28
|
+
* @returns Object with skip status and reason, or null if should not skip
|
|
29
|
+
*/
|
|
30
|
+
export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.ProcessEnv): {
|
|
31
|
+
skip: true;
|
|
32
|
+
reason: 'ci' | 'env' | 'tool-env';
|
|
33
|
+
} | {
|
|
34
|
+
skip: false;
|
|
35
|
+
};
|
|
14
36
|
/**
|
|
15
37
|
* Checks for updates to a package and caches the result.
|
|
16
38
|
* Uses appstash for configuration storage.
|
|
39
|
+
*
|
|
40
|
+
* Automatically skips in CI environments or when skip env vars are set:
|
|
41
|
+
* - CI=true (any CI environment)
|
|
42
|
+
* - INQUIRERER_SKIP_UPDATE_CHECK=1 (generic skip)
|
|
43
|
+
* - {TOOLNAME}_SKIP_UPDATE_CHECK=1 (tool-specific, e.g., PGPM_SKIP_UPDATE_CHECK)
|
|
44
|
+
*
|
|
45
|
+
* Use `force: true` to bypass skip logic.
|
|
17
46
|
*/
|
|
18
47
|
export declare const checkForUpdates: (options: UpdateCheckOptions) => Promise<UpdateCheckResult>;
|
package/esm/update-check.js
CHANGED
|
@@ -1,14 +1,70 @@
|
|
|
1
1
|
import { appstash } from 'appstash';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Converts a tool name to an environment variable name.
|
|
6
|
+
* e.g., "pgpm" -> "PGPM", "my-cli" -> "MY_CLI"
|
|
7
|
+
*/
|
|
8
|
+
function toEnvVarName(toolName) {
|
|
9
|
+
return toolName.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Checks if update checking should be skipped based on environment variables.
|
|
13
|
+
*
|
|
14
|
+
* Skip conditions (in order of precedence):
|
|
15
|
+
* 1. CI environment (process.env.CI is truthy)
|
|
16
|
+
* 2. Generic skip: INQUIRERER_SKIP_UPDATE_CHECK is truthy
|
|
17
|
+
* 3. Tool-specific skip: {TOOLNAME}_SKIP_UPDATE_CHECK is truthy
|
|
18
|
+
*
|
|
19
|
+
* @returns Object with skip status and reason, or null if should not skip
|
|
20
|
+
*/
|
|
21
|
+
export function shouldSkipUpdateCheck(toolName, env = process.env) {
|
|
22
|
+
// Check CI environment
|
|
23
|
+
if (env.CI) {
|
|
24
|
+
return { skip: true, reason: 'ci' };
|
|
25
|
+
}
|
|
26
|
+
// Check generic skip env var
|
|
27
|
+
if (env.INQUIRERER_SKIP_UPDATE_CHECK) {
|
|
28
|
+
return { skip: true, reason: 'env' };
|
|
29
|
+
}
|
|
30
|
+
// Check tool-specific skip env var (derived from toolName)
|
|
31
|
+
if (toolName) {
|
|
32
|
+
const toolEnvVar = `${toEnvVarName(toolName)}_SKIP_UPDATE_CHECK`;
|
|
33
|
+
if (env[toolEnvVar]) {
|
|
34
|
+
return { skip: true, reason: 'tool-env' };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { skip: false };
|
|
38
|
+
}
|
|
4
39
|
const DEFAULT_TTL = 24 * 60 * 60 * 1000; // 24 hours
|
|
5
40
|
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
6
41
|
/**
|
|
7
42
|
* Checks for updates to a package and caches the result.
|
|
8
43
|
* Uses appstash for configuration storage.
|
|
44
|
+
*
|
|
45
|
+
* Automatically skips in CI environments or when skip env vars are set:
|
|
46
|
+
* - CI=true (any CI environment)
|
|
47
|
+
* - INQUIRERER_SKIP_UPDATE_CHECK=1 (generic skip)
|
|
48
|
+
* - {TOOLNAME}_SKIP_UPDATE_CHECK=1 (tool-specific, e.g., PGPM_SKIP_UPDATE_CHECK)
|
|
49
|
+
*
|
|
50
|
+
* Use `force: true` to bypass skip logic.
|
|
9
51
|
*/
|
|
10
52
|
export const checkForUpdates = async (options) => {
|
|
11
|
-
const { pkgName, pkgVersion, registryBaseUrl = DEFAULT_REGISTRY, toolName = pkgName, ttl = DEFAULT_TTL } = options;
|
|
53
|
+
const { pkgName, pkgVersion, registryBaseUrl = DEFAULT_REGISTRY, toolName = pkgName, ttl = DEFAULT_TTL, force = false } = options;
|
|
54
|
+
// Check if we should skip (unless force is true)
|
|
55
|
+
if (!force) {
|
|
56
|
+
const skipResult = shouldSkipUpdateCheck(toolName);
|
|
57
|
+
if (skipResult.skip) {
|
|
58
|
+
return {
|
|
59
|
+
hasUpdate: false,
|
|
60
|
+
currentVersion: pkgVersion,
|
|
61
|
+
latestVersion: null,
|
|
62
|
+
message: null,
|
|
63
|
+
skipped: true,
|
|
64
|
+
skipReason: skipResult.reason
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
12
68
|
const dirs = appstash(toolName);
|
|
13
69
|
const cacheFile = path.join(dirs.cache, 'update-check.json');
|
|
14
70
|
// Check cache first
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { extractFirst } from './argv';
|
|
|
2
2
|
export type { ParsedArgs } from './argv';
|
|
3
3
|
export { cliExitWithError } from './cli-error';
|
|
4
4
|
export type { CliExitOptions } from './cli-error';
|
|
5
|
-
export { checkForUpdates } from './update-check';
|
|
5
|
+
export { checkForUpdates, shouldSkipUpdateCheck } from './update-check';
|
|
6
6
|
export type { UpdateCheckOptions, UpdateCheckResult } from './update-check';
|
|
7
7
|
export { getSelfPackageJson, getSelfVersion, getSelfName } from './package-json';
|
|
8
8
|
export type { PackageJsonInfo } from './package-json';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSelfName = exports.getSelfVersion = exports.getSelfPackageJson = exports.checkForUpdates = exports.cliExitWithError = exports.extractFirst = void 0;
|
|
3
|
+
exports.getSelfName = exports.getSelfVersion = exports.getSelfPackageJson = exports.shouldSkipUpdateCheck = exports.checkForUpdates = exports.cliExitWithError = exports.extractFirst = void 0;
|
|
4
4
|
// Argv utilities
|
|
5
5
|
var argv_1 = require("./argv");
|
|
6
6
|
Object.defineProperty(exports, "extractFirst", { enumerable: true, get: function () { return argv_1.extractFirst; } });
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "cliExitWithError", { enumerable: true, get: func
|
|
|
10
10
|
// Update checking
|
|
11
11
|
var update_check_1 = require("./update-check");
|
|
12
12
|
Object.defineProperty(exports, "checkForUpdates", { enumerable: true, get: function () { return update_check_1.checkForUpdates; } });
|
|
13
|
+
Object.defineProperty(exports, "shouldSkipUpdateCheck", { enumerable: true, get: function () { return update_check_1.shouldSkipUpdateCheck; } });
|
|
13
14
|
// Package.json utilities
|
|
14
15
|
var package_json_1 = require("./package-json");
|
|
15
16
|
Object.defineProperty(exports, "getSelfPackageJson", { enumerable: true, get: function () { return package_json_1.getSelfPackageJson; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirerer/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "CLI lifecycle utilities for building command-line applications",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"test:watch": "jest --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"appstash": "0.2.
|
|
32
|
-
"find-and-require-package-json": "0.8.
|
|
31
|
+
"appstash": "0.2.7",
|
|
32
|
+
"find-and-require-package-json": "0.8.4",
|
|
33
33
|
"minimist": "^1.2.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"makage": "0.1.8"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "bf69015f5975c1f2b8baa452240e3bcdba496cd1"
|
|
41
41
|
}
|
package/update-check.d.ts
CHANGED
|
@@ -4,15 +4,44 @@ export interface UpdateCheckOptions {
|
|
|
4
4
|
registryBaseUrl?: string;
|
|
5
5
|
toolName?: string;
|
|
6
6
|
ttl?: number;
|
|
7
|
+
/** Force check even in CI or when skip env vars are set */
|
|
8
|
+
force?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface UpdateCheckResult {
|
|
9
11
|
hasUpdate: boolean;
|
|
10
12
|
currentVersion: string;
|
|
11
13
|
latestVersion: string | null;
|
|
12
14
|
message: string | null;
|
|
15
|
+
/** Whether the check was skipped due to CI or env vars */
|
|
16
|
+
skipped?: boolean;
|
|
17
|
+
/** Reason for skipping: 'ci', 'env', or 'tool-env' */
|
|
18
|
+
skipReason?: 'ci' | 'env' | 'tool-env';
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if update checking should be skipped based on environment variables.
|
|
22
|
+
*
|
|
23
|
+
* Skip conditions (in order of precedence):
|
|
24
|
+
* 1. CI environment (process.env.CI is truthy)
|
|
25
|
+
* 2. Generic skip: INQUIRERER_SKIP_UPDATE_CHECK is truthy
|
|
26
|
+
* 3. Tool-specific skip: {TOOLNAME}_SKIP_UPDATE_CHECK is truthy
|
|
27
|
+
*
|
|
28
|
+
* @returns Object with skip status and reason, or null if should not skip
|
|
29
|
+
*/
|
|
30
|
+
export declare function shouldSkipUpdateCheck(toolName?: string, env?: NodeJS.ProcessEnv): {
|
|
31
|
+
skip: true;
|
|
32
|
+
reason: 'ci' | 'env' | 'tool-env';
|
|
33
|
+
} | {
|
|
34
|
+
skip: false;
|
|
35
|
+
};
|
|
14
36
|
/**
|
|
15
37
|
* Checks for updates to a package and caches the result.
|
|
16
38
|
* Uses appstash for configuration storage.
|
|
39
|
+
*
|
|
40
|
+
* Automatically skips in CI environments or when skip env vars are set:
|
|
41
|
+
* - CI=true (any CI environment)
|
|
42
|
+
* - INQUIRERER_SKIP_UPDATE_CHECK=1 (generic skip)
|
|
43
|
+
* - {TOOLNAME}_SKIP_UPDATE_CHECK=1 (tool-specific, e.g., PGPM_SKIP_UPDATE_CHECK)
|
|
44
|
+
*
|
|
45
|
+
* Use `force: true` to bypass skip logic.
|
|
17
46
|
*/
|
|
18
47
|
export declare const checkForUpdates: (options: UpdateCheckOptions) => Promise<UpdateCheckResult>;
|
package/update-check.js
CHANGED
|
@@ -34,17 +34,74 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.checkForUpdates = void 0;
|
|
37
|
+
exports.shouldSkipUpdateCheck = shouldSkipUpdateCheck;
|
|
37
38
|
const appstash_1 = require("appstash");
|
|
38
39
|
const fs = __importStar(require("fs"));
|
|
39
40
|
const path = __importStar(require("path"));
|
|
41
|
+
/**
|
|
42
|
+
* Converts a tool name to an environment variable name.
|
|
43
|
+
* e.g., "pgpm" -> "PGPM", "my-cli" -> "MY_CLI"
|
|
44
|
+
*/
|
|
45
|
+
function toEnvVarName(toolName) {
|
|
46
|
+
return toolName.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks if update checking should be skipped based on environment variables.
|
|
50
|
+
*
|
|
51
|
+
* Skip conditions (in order of precedence):
|
|
52
|
+
* 1. CI environment (process.env.CI is truthy)
|
|
53
|
+
* 2. Generic skip: INQUIRERER_SKIP_UPDATE_CHECK is truthy
|
|
54
|
+
* 3. Tool-specific skip: {TOOLNAME}_SKIP_UPDATE_CHECK is truthy
|
|
55
|
+
*
|
|
56
|
+
* @returns Object with skip status and reason, or null if should not skip
|
|
57
|
+
*/
|
|
58
|
+
function shouldSkipUpdateCheck(toolName, env = process.env) {
|
|
59
|
+
// Check CI environment
|
|
60
|
+
if (env.CI) {
|
|
61
|
+
return { skip: true, reason: 'ci' };
|
|
62
|
+
}
|
|
63
|
+
// Check generic skip env var
|
|
64
|
+
if (env.INQUIRERER_SKIP_UPDATE_CHECK) {
|
|
65
|
+
return { skip: true, reason: 'env' };
|
|
66
|
+
}
|
|
67
|
+
// Check tool-specific skip env var (derived from toolName)
|
|
68
|
+
if (toolName) {
|
|
69
|
+
const toolEnvVar = `${toEnvVarName(toolName)}_SKIP_UPDATE_CHECK`;
|
|
70
|
+
if (env[toolEnvVar]) {
|
|
71
|
+
return { skip: true, reason: 'tool-env' };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { skip: false };
|
|
75
|
+
}
|
|
40
76
|
const DEFAULT_TTL = 24 * 60 * 60 * 1000; // 24 hours
|
|
41
77
|
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
42
78
|
/**
|
|
43
79
|
* Checks for updates to a package and caches the result.
|
|
44
80
|
* Uses appstash for configuration storage.
|
|
81
|
+
*
|
|
82
|
+
* Automatically skips in CI environments or when skip env vars are set:
|
|
83
|
+
* - CI=true (any CI environment)
|
|
84
|
+
* - INQUIRERER_SKIP_UPDATE_CHECK=1 (generic skip)
|
|
85
|
+
* - {TOOLNAME}_SKIP_UPDATE_CHECK=1 (tool-specific, e.g., PGPM_SKIP_UPDATE_CHECK)
|
|
86
|
+
*
|
|
87
|
+
* Use `force: true` to bypass skip logic.
|
|
45
88
|
*/
|
|
46
89
|
const checkForUpdates = async (options) => {
|
|
47
|
-
const { pkgName, pkgVersion, registryBaseUrl = DEFAULT_REGISTRY, toolName = pkgName, ttl = DEFAULT_TTL } = options;
|
|
90
|
+
const { pkgName, pkgVersion, registryBaseUrl = DEFAULT_REGISTRY, toolName = pkgName, ttl = DEFAULT_TTL, force = false } = options;
|
|
91
|
+
// Check if we should skip (unless force is true)
|
|
92
|
+
if (!force) {
|
|
93
|
+
const skipResult = shouldSkipUpdateCheck(toolName);
|
|
94
|
+
if (skipResult.skip) {
|
|
95
|
+
return {
|
|
96
|
+
hasUpdate: false,
|
|
97
|
+
currentVersion: pkgVersion,
|
|
98
|
+
latestVersion: null,
|
|
99
|
+
message: null,
|
|
100
|
+
skipped: true,
|
|
101
|
+
skipReason: skipResult.reason
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
48
105
|
const dirs = (0, appstash_1.appstash)(toolName);
|
|
49
106
|
const cacheFile = path.join(dirs.cache, 'update-check.json');
|
|
50
107
|
// Check cache first
|