ccusage 20.0.51 → 20.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/README.md +11 -2
- package/config-schema.json +2134 -39
- package/package.json +8 -8
- package/src/cli.js +44 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccusage",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.1.1",
|
|
4
4
|
"description": "Analyze coding (agent) CLI token usage and costs from local data",
|
|
5
5
|
"homepage": "https://github.com/ccusage/ccusage#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"@types/node": "^26.6.6"
|
|
27
27
|
},
|
|
28
28
|
"optionalDependencies": {
|
|
29
|
-
"@ccusage/ccusage-darwin-arm64": "20.
|
|
30
|
-
"@ccusage/ccusage-darwin-x64": "20.
|
|
31
|
-
"@ccusage/ccusage-linux-arm64": "20.
|
|
32
|
-
"@ccusage/ccusage-linux-x64": "20.
|
|
33
|
-
"@ccusage/ccusage-win32-arm64": "20.
|
|
34
|
-
"@ccusage/ccusage-win32-x64": "20.
|
|
29
|
+
"@ccusage/ccusage-darwin-arm64": "20.1.1",
|
|
30
|
+
"@ccusage/ccusage-darwin-x64": "20.1.1",
|
|
31
|
+
"@ccusage/ccusage-linux-arm64": "20.1.1",
|
|
32
|
+
"@ccusage/ccusage-linux-x64": "20.1.1",
|
|
33
|
+
"@ccusage/ccusage-win32-arm64": "20.1.1",
|
|
34
|
+
"@ccusage/ccusage-win32-x64": "20.1.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "
|
|
37
|
+
"build": "publint"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import process from 'node:process';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
|
-
/** @type {{ version: string }} */
|
|
10
|
+
/** @type {{ optionalDependencies: Record<string, string>; version: string }} */
|
|
11
11
|
const packageJson = require('../package.json');
|
|
12
12
|
const wrapperVersion = packageJson.version;
|
|
13
13
|
|
|
@@ -25,87 +25,29 @@ const wrapperVersion = packageJson.version;
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {string} [platform]
|
|
27
27
|
* @param {string} [arch]
|
|
28
|
-
* @returns {string | undefined}
|
|
29
28
|
*/
|
|
30
29
|
function getNativePackageName(platform = process.platform, arch = process.arch) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return '@ccusage/ccusage-darwin-arm64';
|
|
34
|
-
}
|
|
35
|
-
if (arch === 'x64') {
|
|
36
|
-
return '@ccusage/ccusage-darwin-x64';
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (platform === 'linux') {
|
|
42
|
-
if (arch === 'arm64') {
|
|
43
|
-
return '@ccusage/ccusage-linux-arm64';
|
|
44
|
-
}
|
|
45
|
-
if (arch === 'x64') {
|
|
46
|
-
return '@ccusage/ccusage-linux-x64';
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (platform === 'win32') {
|
|
52
|
-
if (arch === 'arm64') {
|
|
53
|
-
return '@ccusage/ccusage-win32-arm64';
|
|
54
|
-
}
|
|
55
|
-
if (arch === 'x64') {
|
|
56
|
-
return '@ccusage/ccusage-win32-x64';
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return undefined;
|
|
30
|
+
const packageName = `@ccusage/ccusage-${platform}-${arch}`;
|
|
31
|
+
return Object.hasOwn(packageJson.optionalDependencies, packageName) ? packageName : undefined;
|
|
61
32
|
}
|
|
62
33
|
|
|
63
34
|
/**
|
|
64
35
|
* @param {string} [platform]
|
|
65
|
-
* @returns {string}
|
|
66
36
|
*/
|
|
67
37
|
function getNativeBinarySubpath(platform = process.platform) {
|
|
68
38
|
return platform === 'win32' ? 'bin/ccusage.exe' : 'bin/ccusage';
|
|
69
39
|
}
|
|
70
40
|
|
|
71
41
|
/**
|
|
72
|
-
* @param {{ arch?: string; platform?: string; resolvePath?: (id: string) => string }}
|
|
73
|
-
* @returns {string | undefined}
|
|
74
|
-
*/
|
|
75
|
-
function resolveNativeBinary({
|
|
76
|
-
arch = process.arch,
|
|
77
|
-
platform = process.platform,
|
|
78
|
-
resolvePath = (id) => require.resolve(id),
|
|
79
|
-
} = {}) {
|
|
80
|
-
const packageName = getNativePackageName(platform, arch);
|
|
81
|
-
if (packageName == null) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
return resolvePath(`${packageName}/${getNativeBinarySubpath(platform)}`);
|
|
87
|
-
} catch {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @param {{ arch?: string; argv: string[]; nativeBinaryPath?: string | null; platform?: string }} options
|
|
42
|
+
* @param {{ arch?: string; argv: string[]; platform?: string; resolvePath?: (id: string) => string }} options
|
|
94
43
|
* @returns {CliRuntime}
|
|
95
44
|
*/
|
|
96
45
|
function resolveCliRuntime({
|
|
97
46
|
argv,
|
|
98
47
|
arch = process.arch,
|
|
99
|
-
nativeBinaryPath = resolveNativeBinary(),
|
|
100
48
|
platform = process.platform,
|
|
49
|
+
resolvePath = (id) => require.resolve(id),
|
|
101
50
|
}) {
|
|
102
|
-
if (nativeBinaryPath != null) {
|
|
103
|
-
return {
|
|
104
|
-
args: argv,
|
|
105
|
-
command: nativeBinaryPath,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
51
|
const target = `${platform}-${arch}`;
|
|
110
52
|
const packageName = getNativePackageName(platform, arch);
|
|
111
53
|
if (packageName == null) {
|
|
@@ -114,14 +56,48 @@ function resolveCliRuntime({
|
|
|
114
56
|
};
|
|
115
57
|
}
|
|
116
58
|
|
|
59
|
+
const binarySubpath = getNativeBinarySubpath(platform);
|
|
60
|
+
try {
|
|
61
|
+
return { args: argv, command: resolvePath(`${packageName}/${binarySubpath}`) };
|
|
62
|
+
} catch (binaryError) {
|
|
63
|
+
if (!isModuleNotFound(binaryError)) {
|
|
64
|
+
return { errorMessage: cannotResolveMessage(packageName, target, binaryError) };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
resolvePath(`${packageName}/package.json`);
|
|
70
|
+
} catch (manifestError) {
|
|
71
|
+
if (isModuleNotFound(manifestError)) {
|
|
72
|
+
return {
|
|
73
|
+
errorMessage: `Missing optional native package "${packageName}@${wrapperVersion}" for ${target}. It may be absent because of npm --before/--min-release-age, mise minimum_release_age, or --omit=optional. Reinstall ccusage with optional dependencies enabled and no release-age cutoff.\n`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { errorMessage: cannotResolveMessage(packageName, target, manifestError) };
|
|
77
|
+
}
|
|
117
78
|
return {
|
|
118
|
-
errorMessage: `
|
|
79
|
+
errorMessage: `Native package "${packageName}" for ${target} is installed, but its ${binarySubpath} is missing. Reinstall ccusage.\n`,
|
|
119
80
|
};
|
|
120
81
|
}
|
|
121
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @param {string} packageName
|
|
85
|
+
* @param {string} target
|
|
86
|
+
* @param {unknown} error
|
|
87
|
+
*/
|
|
88
|
+
function cannotResolveMessage(packageName, target, error) {
|
|
89
|
+
return `Cannot resolve native package "${packageName}" for ${target}: ${errorMessage(error)}\n`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {unknown} error
|
|
94
|
+
*/
|
|
95
|
+
function isModuleNotFound(error) {
|
|
96
|
+
return error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND';
|
|
97
|
+
}
|
|
98
|
+
|
|
122
99
|
/**
|
|
123
100
|
* @param {unknown} error
|
|
124
|
-
* @returns {string}
|
|
125
101
|
*/
|
|
126
102
|
function errorMessage(error) {
|
|
127
103
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -129,7 +105,6 @@ function errorMessage(error) {
|
|
|
129
105
|
|
|
130
106
|
/**
|
|
131
107
|
* @param {{ binaryPath: string; chmodPath?: (path: string, mode: number) => void; platform?: string; statPath?: (path: string) => FileMode }} options
|
|
132
|
-
* @returns {string | undefined}
|
|
133
108
|
*/
|
|
134
109
|
function ensureNativeBinaryExecutable({
|
|
135
110
|
binaryPath,
|
|
@@ -155,7 +130,6 @@ function ensureNativeBinaryExecutable({
|
|
|
155
130
|
|
|
156
131
|
/**
|
|
157
132
|
* @param {MainModuleOptions} options
|
|
158
|
-
* @returns {boolean}
|
|
159
133
|
*/
|
|
160
134
|
function isMainModule({ argvEntry = process.argv[1], moduleUrl, realpathPath = realpathSync }) {
|
|
161
135
|
if (argvEntry == null) {
|
|
@@ -228,10 +202,8 @@ function createNativeSpawner({
|
|
|
228
202
|
|
|
229
203
|
for (const signal of forwardedSignals) {
|
|
230
204
|
const handler = () => handleSignal(signal);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
signalHandlers.set(signal, handler);
|
|
234
|
-
} catch {}
|
|
205
|
+
signalSource.on(signal, handler);
|
|
206
|
+
signalHandlers.set(signal, handler);
|
|
235
207
|
}
|
|
236
208
|
});
|
|
237
209
|
}
|
|
@@ -239,7 +211,6 @@ function createNativeSpawner({
|
|
|
239
211
|
/**
|
|
240
212
|
* @param {string[]} argv
|
|
241
213
|
* @param {NativeSpawner} [spawnNative]
|
|
242
|
-
* @returns {Promise<number>}
|
|
243
214
|
*/
|
|
244
215
|
async function runCli(argv, spawnNative = createNativeSpawner()) {
|
|
245
216
|
const runtime = resolveCliRuntime({ argv });
|
|
@@ -272,10 +243,4 @@ if (isMainModule({ moduleUrl: import.meta.url })) {
|
|
|
272
243
|
process.exitCode = await runCli(process.argv.slice(2));
|
|
273
244
|
}
|
|
274
245
|
|
|
275
|
-
export {
|
|
276
|
-
createNativeSpawner,
|
|
277
|
-
ensureNativeBinaryExecutable,
|
|
278
|
-
isMainModule,
|
|
279
|
-
resolveCliRuntime,
|
|
280
|
-
resolveNativeBinary,
|
|
281
|
-
};
|
|
246
|
+
export { createNativeSpawner, ensureNativeBinaryExecutable, isMainModule, resolveCliRuntime };
|