Skip to content

Commit 117be1b

Browse files
fix(cli): explain missing optional native packages
Include the expected package and version in the launcher error and explain release-age cutoffs and omitted optional dependencies. Co-authored-by: moriya-fumio-thd <[email protected]>
1 parent b02470a commit 117be1b

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎apps/ccusage/src/cli.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import process from 'node:process';
77
import { fileURLToPath } from 'node:url';
88

99
const require = createRequire(import.meta.url);
10+
/** @type {{ version: string }} */
11+
const packageJson = require('../package.json');
12+
const wrapperVersion = packageJson.version;
1013

1114
/**
1215
* @typedef {{ args: string[]; command: string } | { errorMessage: string }} CliRuntime
@@ -103,8 +106,16 @@ function resolveCliRuntime({
103106
};
104107
}
105108

109+
const target = `${platform}-${arch}`;
110+
const packageName = getNativePackageName(platform, arch);
111+
if (packageName == null) {
112+
return {
113+
errorMessage: `ccusage does not provide a native binary for ${target}.\n`,
114+
};
115+
}
116+
106117
return {
107-
errorMessage: `ccusage native binary is not available for ${platform}-${arch}. Reinstall ccusage so optional native dependencies are installed.\n`,
118+
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`,
108119
};
109120
}
110121

‎apps/ccusage/src/cli.test.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'node:assert/strict';
22
import { EventEmitter } from 'node:events';
3+
import { createRequire } from 'node:module';
34
import { describe, it, mock } from 'node:test';
45
import {
56
createNativeSpawner,
@@ -9,6 +10,10 @@ import {
910
resolveNativeBinary,
1011
} from './cli.js';
1112

13+
const require = createRequire(import.meta.url);
14+
/** @type {{ version: string }} */
15+
const packageJson = require('../package.json');
16+
1217
void describe(resolveCliRuntime.name, () => {
1318
void it('resolves the native package binary for the current supported platform', () => {
1419
const actual = resolveNativeBinary({
@@ -58,8 +63,21 @@ void describe(resolveCliRuntime.name, () => {
5863
platform: 'darwin',
5964
}),
6065
{
61-
errorMessage:
62-
'ccusage native binary is not available for darwin-arm64. Reinstall ccusage so optional native dependencies are installed.\n',
66+
errorMessage: `Missing optional native package "@ccusage/ccusage-darwin-arm64@${packageJson.version}" for darwin-arm64. 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`,
67+
},
68+
);
69+
});
70+
71+
void it('reports unsupported native binary targets without suggesting an optional package', () => {
72+
assert.deepEqual(
73+
resolveCliRuntime({
74+
arch: 'riscv64',
75+
argv: [],
76+
nativeBinaryPath: null,
77+
platform: 'freebsd',
78+
}),
79+
{
80+
errorMessage: 'ccusage does not provide a native binary for freebsd-riscv64.\n',
6381
},
6482
);
6583
});

0 commit comments

Comments
 (0)