modestbench 0.8.0 → 0.9.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/CHANGELOG.md +22 -0
- package/README.md +37 -4
- package/dist/adapters/types.d.cts +1 -1
- package/dist/adapters/types.d.cts.map +1 -1
- package/dist/adapters/types.d.ts +1 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/cli/commands/baseline.cjs +8 -8
- package/dist/cli/commands/baseline.cjs.map +1 -1
- package/dist/cli/commands/baseline.js +8 -8
- package/dist/cli/commands/baseline.js.map +1 -1
- package/dist/cli/commands/init.cjs +2 -2
- package/dist/cli/commands/init.cjs.map +1 -1
- package/dist/cli/commands/init.js +2 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/run.cjs +12 -8
- package/dist/cli/commands/run.cjs.map +1 -1
- package/dist/cli/commands/run.d.cts +1 -13
- package/dist/cli/commands/run.d.cts.map +1 -1
- package/dist/cli/commands/run.d.ts +1 -13
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +11 -7
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/test.cjs +1 -1
- package/dist/cli/commands/test.cjs.map +1 -1
- package/dist/cli/commands/test.js +1 -1
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/index.cjs +655 -870
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +27 -17
- package/dist/cli/index.d.cts.map +1 -1
- package/dist/cli/index.d.ts +27 -17
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +657 -869
- package/dist/cli/index.js.map +1 -1
- package/dist/{core → config}/benchmark-schema.cjs +1 -1
- package/dist/config/benchmark-schema.cjs.map +1 -0
- package/dist/config/benchmark-schema.d.cts +913 -0
- package/dist/config/benchmark-schema.d.cts.map +1 -0
- package/dist/config/benchmark-schema.d.ts +913 -0
- package/dist/config/benchmark-schema.d.ts.map +1 -0
- package/dist/{core → config}/benchmark-schema.js +1 -1
- package/dist/config/benchmark-schema.js.map +1 -0
- package/dist/config/budget-schema.cjs +1 -1
- package/dist/config/budget-schema.cjs.map +1 -1
- package/dist/config/budget-schema.js +1 -1
- package/dist/config/budget-schema.js.map +1 -1
- package/dist/config/schema.cjs +188 -105
- package/dist/config/schema.cjs.map +1 -1
- package/dist/config/schema.d.cts +208 -80
- package/dist/config/schema.d.cts.map +1 -1
- package/dist/config/schema.d.ts +208 -80
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +187 -104
- package/dist/config/schema.js.map +1 -1
- package/dist/core/engine.cjs +50 -45
- package/dist/core/engine.cjs.map +1 -1
- package/dist/core/engine.d.cts.map +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +50 -45
- package/dist/core/engine.js.map +1 -1
- package/dist/core/engines/accurate-engine.cjs +1 -1
- package/dist/core/engines/accurate-engine.cjs.map +1 -1
- package/dist/core/engines/accurate-engine.d.cts.map +1 -1
- package/dist/core/engines/accurate-engine.d.ts.map +1 -1
- package/dist/core/engines/accurate-engine.js +1 -1
- package/dist/core/engines/accurate-engine.js.map +1 -1
- package/dist/core/output-path-resolver.cjs +15 -1
- package/dist/core/output-path-resolver.cjs.map +1 -1
- package/dist/core/output-path-resolver.d.cts +8 -0
- package/dist/core/output-path-resolver.d.cts.map +1 -1
- package/dist/core/output-path-resolver.d.ts +8 -0
- package/dist/core/output-path-resolver.d.ts.map +1 -1
- package/dist/core/output-path-resolver.js +13 -0
- package/dist/core/output-path-resolver.js.map +1 -1
- package/dist/formatters/history/compare.cjs +6 -6
- package/dist/formatters/history/compare.cjs.map +1 -1
- package/dist/formatters/history/compare.js +6 -6
- package/dist/formatters/history/compare.js.map +1 -1
- package/dist/formatters/history/show.cjs +2 -2
- package/dist/formatters/history/show.cjs.map +1 -1
- package/dist/formatters/history/show.js +2 -2
- package/dist/formatters/history/show.js.map +1 -1
- package/dist/formatters/history/trends.cjs +1 -1
- package/dist/formatters/history/trends.cjs.map +1 -1
- package/dist/formatters/history/trends.js +1 -1
- package/dist/formatters/history/trends.js.map +1 -1
- package/dist/reporters/human.cjs +3 -3
- package/dist/reporters/human.cjs.map +1 -1
- package/dist/reporters/human.d.cts.map +1 -1
- package/dist/reporters/human.d.ts.map +1 -1
- package/dist/reporters/human.js +3 -3
- package/dist/reporters/human.js.map +1 -1
- package/dist/reporters/json.cjs +1 -1
- package/dist/reporters/json.cjs.map +1 -1
- package/dist/reporters/json.js +1 -1
- package/dist/reporters/json.js.map +1 -1
- package/dist/reporters/nyan.cjs +1 -1
- package/dist/reporters/nyan.cjs.map +1 -1
- package/dist/reporters/nyan.js +1 -1
- package/dist/reporters/nyan.js.map +1 -1
- package/dist/schema/modestbench-config.schema.json +94 -87
- package/dist/services/budget-evaluator.cjs +10 -8
- package/dist/services/budget-evaluator.cjs.map +1 -1
- package/dist/services/budget-evaluator.d.cts +2 -2
- package/dist/services/budget-evaluator.d.cts.map +1 -1
- package/dist/services/budget-evaluator.d.ts +2 -2
- package/dist/services/budget-evaluator.d.ts.map +1 -1
- package/dist/services/budget-evaluator.js +10 -8
- package/dist/services/budget-evaluator.js.map +1 -1
- package/dist/services/budget-resolver.cjs +214 -0
- package/dist/services/budget-resolver.cjs.map +1 -0
- package/dist/services/budget-resolver.d.cts +98 -0
- package/dist/services/budget-resolver.d.cts.map +1 -0
- package/dist/services/budget-resolver.d.ts +98 -0
- package/dist/services/budget-resolver.d.ts.map +1 -0
- package/dist/services/budget-resolver.js +203 -0
- package/dist/services/budget-resolver.js.map +1 -0
- package/dist/services/config-manager.cjs +2 -2
- package/dist/services/config-manager.cjs.map +1 -1
- package/dist/services/config-manager.js +2 -2
- package/dist/services/config-manager.js.map +1 -1
- package/dist/services/file-loader.cjs +1 -1
- package/dist/services/file-loader.cjs.map +1 -1
- package/dist/services/file-loader.js +1 -1
- package/dist/services/file-loader.js.map +1 -1
- package/dist/services/reporter-registry.cjs +8 -8
- package/dist/services/reporter-registry.cjs.map +1 -1
- package/dist/services/reporter-registry.js +8 -8
- package/dist/services/reporter-registry.js.map +1 -1
- package/dist/types/budgets.d.cts +31 -0
- package/dist/types/budgets.d.cts.map +1 -1
- package/dist/types/budgets.d.ts +31 -0
- package/dist/types/budgets.d.ts.map +1 -1
- package/dist/types/core.cjs.map +1 -1
- package/dist/types/core.d.cts +28 -75
- package/dist/types/core.d.cts.map +1 -1
- package/dist/types/core.d.ts +28 -75
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js.map +1 -1
- package/package.json +24 -15
- package/src/adapters/types.ts +1 -1
- package/src/cli/commands/baseline.ts +8 -8
- package/src/cli/commands/init.ts +2 -2
- package/src/cli/commands/run.ts +18 -6
- package/src/cli/commands/test.ts +1 -1
- package/src/cli/index.ts +806 -942
- package/src/{core → config}/benchmark-schema.ts +1 -1
- package/src/config/budget-schema.ts +1 -1
- package/src/config/schema.ts +379 -302
- package/src/core/engine.ts +74 -69
- package/src/core/engines/accurate-engine.ts +1 -1
- package/src/core/output-path-resolver.ts +14 -0
- package/src/formatters/history/compare.ts +6 -6
- package/src/formatters/history/show.ts +2 -2
- package/src/formatters/history/trends.ts +1 -1
- package/src/reporters/human.ts +5 -3
- package/src/reporters/json.ts +1 -1
- package/src/reporters/nyan.ts +1 -1
- package/src/services/budget-evaluator.ts +15 -11
- package/src/services/budget-resolver.ts +254 -0
- package/src/services/config-manager.ts +2 -2
- package/src/services/file-loader.ts +1 -1
- package/src/services/reporter-registry.ts +8 -8
- package/src/types/budgets.ts +38 -0
- package/src/types/core.ts +64 -99
- package/dist/core/benchmark-schema.cjs.map +0 -1
- package/dist/core/benchmark-schema.d.cts +0 -139
- package/dist/core/benchmark-schema.d.cts.map +0 -1
- package/dist/core/benchmark-schema.d.ts +0 -139
- package/dist/core/benchmark-schema.d.ts.map +0 -1
- package/dist/core/benchmark-schema.js.map +0 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* ModestBench CLI Entry Point
|
|
5
5
|
*
|
|
6
|
-
* Command-line interface using
|
|
6
|
+
* Command-line interface using bargs for command parsing and routing. Provides
|
|
7
7
|
* global options, help generation, and dependency injection setup.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
8
10
|
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.main = exports.cli = void 0;
|
|
13
|
+
const bargs_1 = require("@boneskull/bargs");
|
|
14
14
|
const node_fs_1 = require("node:fs");
|
|
15
15
|
const node_url_1 = require("node:url");
|
|
16
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
17
|
-
const helpers_1 = require("yargs/helpers");
|
|
18
16
|
const bootstrap_js_1 = require("../bootstrap.cjs");
|
|
19
17
|
const constants_js_1 = require("../constants.cjs");
|
|
20
18
|
const index_js_1 = require("../core/engines/index.cjs");
|
|
@@ -28,6 +26,622 @@ const history_js_1 = require("./commands/history.cjs");
|
|
|
28
26
|
const init_js_1 = require("./commands/init.cjs");
|
|
29
27
|
const run_js_1 = require("./commands/run.cjs");
|
|
30
28
|
const test_js_1 = require("./commands/test.cjs");
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Global Options Parser
|
|
31
|
+
// ============================================================================
|
|
32
|
+
const globalOptions = bargs_1.opt.options({
|
|
33
|
+
config: bargs_1.opt.string({
|
|
34
|
+
aliases: ['c'],
|
|
35
|
+
description: 'Path to configuration file',
|
|
36
|
+
}),
|
|
37
|
+
cwd: bargs_1.opt.string({
|
|
38
|
+
description: 'Working directory',
|
|
39
|
+
}),
|
|
40
|
+
json: bargs_1.opt.boolean({
|
|
41
|
+
description: 'Output results in JSON format',
|
|
42
|
+
}),
|
|
43
|
+
'no-color': bargs_1.opt.boolean({
|
|
44
|
+
description: 'Disable colored output',
|
|
45
|
+
}),
|
|
46
|
+
progress: bargs_1.opt.boolean({
|
|
47
|
+
description: 'Show animated progress bar',
|
|
48
|
+
}),
|
|
49
|
+
verbose: bargs_1.opt.boolean({
|
|
50
|
+
aliases: ['v'],
|
|
51
|
+
description: 'Enable verbose output',
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// History Command Parsers
|
|
56
|
+
// ============================================================================
|
|
57
|
+
const historyListParser = bargs_1.opt.options({
|
|
58
|
+
format: bargs_1.opt.enum(['human', 'json', 'csv'], {
|
|
59
|
+
description: 'Output format',
|
|
60
|
+
}),
|
|
61
|
+
limit: bargs_1.opt.number({
|
|
62
|
+
description: 'Maximum number of results',
|
|
63
|
+
}),
|
|
64
|
+
pattern: bargs_1.opt.string({
|
|
65
|
+
description: 'Filter by benchmark name pattern',
|
|
66
|
+
}),
|
|
67
|
+
since: bargs_1.opt.string({
|
|
68
|
+
description: 'Show runs since date (ISO 8601 or relative like "1 week ago")',
|
|
69
|
+
}),
|
|
70
|
+
tag: bargs_1.opt.array('string', {
|
|
71
|
+
aliases: ['t'],
|
|
72
|
+
description: 'Filter by tags',
|
|
73
|
+
}),
|
|
74
|
+
until: bargs_1.opt.string({
|
|
75
|
+
description: 'Show runs until date (ISO 8601 or relative like "1 day ago")',
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
const historyShowParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
79
|
+
format: bargs_1.opt.enum(['human', 'json', 'csv'], {
|
|
80
|
+
description: 'Output format',
|
|
81
|
+
}),
|
|
82
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
83
|
+
description: 'ID of the benchmark run to show',
|
|
84
|
+
name: 'run-id',
|
|
85
|
+
required: true,
|
|
86
|
+
})));
|
|
87
|
+
const historyCompareParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
88
|
+
format: bargs_1.opt.enum(['human', 'json'], {
|
|
89
|
+
description: 'Output format',
|
|
90
|
+
}),
|
|
91
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
92
|
+
description: 'ID of the first benchmark run',
|
|
93
|
+
name: 'run-id1',
|
|
94
|
+
required: true,
|
|
95
|
+
}), bargs_1.pos.string({
|
|
96
|
+
description: 'ID of the second benchmark run',
|
|
97
|
+
name: 'run-id2',
|
|
98
|
+
required: true,
|
|
99
|
+
})));
|
|
100
|
+
const historyTrendsParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
101
|
+
all: bargs_1.opt.boolean({
|
|
102
|
+
aliases: ['a'],
|
|
103
|
+
description: 'Analyze all runs (ignore limit)',
|
|
104
|
+
}),
|
|
105
|
+
format: bargs_1.opt.enum(['human', 'json'], {
|
|
106
|
+
description: 'Output format',
|
|
107
|
+
}),
|
|
108
|
+
limit: bargs_1.opt.number({
|
|
109
|
+
description: 'Maximum number of runs to analyze',
|
|
110
|
+
}),
|
|
111
|
+
since: bargs_1.opt.string({
|
|
112
|
+
description: 'Show trends since date (ISO 8601 or relative like "1 week ago")',
|
|
113
|
+
}),
|
|
114
|
+
tag: bargs_1.opt.array('string', {
|
|
115
|
+
aliases: ['t'],
|
|
116
|
+
description: 'Filter by tags',
|
|
117
|
+
}),
|
|
118
|
+
until: bargs_1.opt.string({
|
|
119
|
+
description: 'Show trends until date (ISO 8601 or relative like "1 day ago")',
|
|
120
|
+
}),
|
|
121
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
122
|
+
description: 'Filter by benchmark name pattern',
|
|
123
|
+
name: 'pattern',
|
|
124
|
+
})));
|
|
125
|
+
const historyCleanParser = (0, bargs_1.map)(bargs_1.opt.options({
|
|
126
|
+
'max-age': bargs_1.opt.number({
|
|
127
|
+
description: 'Remove runs older than this many days',
|
|
128
|
+
}),
|
|
129
|
+
'max-runs': bargs_1.opt.number({
|
|
130
|
+
description: 'Keep only this many most recent runs',
|
|
131
|
+
}),
|
|
132
|
+
'max-size': bargs_1.opt.number({
|
|
133
|
+
description: 'Keep history under this size in bytes',
|
|
134
|
+
}),
|
|
135
|
+
yes: bargs_1.opt.boolean({
|
|
136
|
+
aliases: ['y'],
|
|
137
|
+
description: 'Confirm cleanup without prompting',
|
|
138
|
+
}),
|
|
139
|
+
}), ({ positionals, values }) => {
|
|
140
|
+
if (!values['max-age'] && !values['max-runs'] && !values['max-size']) {
|
|
141
|
+
throw new Error('At least one cleanup criterion must be specified (--max-age, --max-runs, or --max-size)');
|
|
142
|
+
}
|
|
143
|
+
return { positionals, values };
|
|
144
|
+
});
|
|
145
|
+
const historyExportParser = bargs_1.opt.options({
|
|
146
|
+
format: bargs_1.opt.enum(['json', 'csv'], {
|
|
147
|
+
description: 'Export format',
|
|
148
|
+
}),
|
|
149
|
+
output: bargs_1.opt.string({
|
|
150
|
+
aliases: ['o'],
|
|
151
|
+
description: 'Output file path',
|
|
152
|
+
required: true,
|
|
153
|
+
}),
|
|
154
|
+
since: bargs_1.opt.string({
|
|
155
|
+
description: 'Export runs since date',
|
|
156
|
+
}),
|
|
157
|
+
until: bargs_1.opt.string({
|
|
158
|
+
description: 'Export runs until date',
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
// ============================================================================
|
|
162
|
+
// Baseline Command Parsers
|
|
163
|
+
// ============================================================================
|
|
164
|
+
const baselineSetParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
165
|
+
branch: bargs_1.opt.string({
|
|
166
|
+
description: 'Git branch name',
|
|
167
|
+
}),
|
|
168
|
+
commit: bargs_1.opt.string({
|
|
169
|
+
description: 'Git commit SHA (40 characters)',
|
|
170
|
+
}),
|
|
171
|
+
default: bargs_1.opt.boolean({
|
|
172
|
+
description: 'Set as default baseline',
|
|
173
|
+
}),
|
|
174
|
+
'run-id': bargs_1.opt.string({
|
|
175
|
+
description: 'Specific run ID to save (default: most recent)',
|
|
176
|
+
}),
|
|
177
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
178
|
+
description: 'Name for the baseline',
|
|
179
|
+
name: 'name',
|
|
180
|
+
required: true,
|
|
181
|
+
})));
|
|
182
|
+
const baselineListParser = bargs_1.opt.options({
|
|
183
|
+
format: bargs_1.opt.enum(['human', 'json'], {
|
|
184
|
+
description: 'Output format',
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
187
|
+
const baselineShowParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
188
|
+
format: bargs_1.opt.enum(['human', 'json'], {
|
|
189
|
+
description: 'Output format',
|
|
190
|
+
}),
|
|
191
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
192
|
+
description: 'Baseline name to show',
|
|
193
|
+
name: 'name',
|
|
194
|
+
required: true,
|
|
195
|
+
})));
|
|
196
|
+
const baselineDeleteParser = bargs_1.pos.positionals(bargs_1.pos.string({
|
|
197
|
+
description: 'Baseline name to delete',
|
|
198
|
+
name: 'name',
|
|
199
|
+
required: true,
|
|
200
|
+
}));
|
|
201
|
+
const baselineAnalyzeParser = bargs_1.opt.options({
|
|
202
|
+
confidence: bargs_1.opt.number({
|
|
203
|
+
description: 'Confidence level (0.5-0.999, default 0.95)',
|
|
204
|
+
}),
|
|
205
|
+
runs: bargs_1.opt.number({
|
|
206
|
+
description: 'Number of recent runs to analyze',
|
|
207
|
+
}),
|
|
208
|
+
});
|
|
209
|
+
// ============================================================================
|
|
210
|
+
// Run Command Parser
|
|
211
|
+
// ============================================================================
|
|
212
|
+
const runParserBase = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
213
|
+
bail: bargs_1.opt.boolean({
|
|
214
|
+
aliases: ['b'],
|
|
215
|
+
description: 'Stop on first failure',
|
|
216
|
+
}),
|
|
217
|
+
engine: bargs_1.opt.enum([constants_js_1.Engines.TINYBENCH, constants_js_1.Engines.ACCURATE], {
|
|
218
|
+
aliases: ['e'],
|
|
219
|
+
description: 'Benchmark engine: tinybench (default) or accurate (requires --allow-natives-syntax)',
|
|
220
|
+
}),
|
|
221
|
+
exclude: bargs_1.opt.array('string', {
|
|
222
|
+
aliases: ['X'],
|
|
223
|
+
description: 'Exclude patterns',
|
|
224
|
+
}),
|
|
225
|
+
'exclude-tag': bargs_1.opt.array('string', {
|
|
226
|
+
aliases: ['T'],
|
|
227
|
+
description: 'Exclude benchmarks with any of these tags',
|
|
228
|
+
}),
|
|
229
|
+
iterations: bargs_1.opt.number({
|
|
230
|
+
aliases: ['i'],
|
|
231
|
+
description: 'Number of iterations per benchmark',
|
|
232
|
+
}),
|
|
233
|
+
'json-pretty': bargs_1.opt.boolean({
|
|
234
|
+
description: 'Pretty-print JSON output (only affects json reporter)',
|
|
235
|
+
}),
|
|
236
|
+
'limit-by': bargs_1.opt.enum(['time', 'iterations', 'any', 'all'], {
|
|
237
|
+
aliases: ['l', 'limit'],
|
|
238
|
+
description: 'How to limit benchmarks: time (time budget), iterations (sample count), any (either threshold), all (both thresholds)',
|
|
239
|
+
}),
|
|
240
|
+
output: bargs_1.opt.string({
|
|
241
|
+
aliases: ['o'],
|
|
242
|
+
description: 'Output directory for reports',
|
|
243
|
+
}),
|
|
244
|
+
'output-file': bargs_1.opt.string({
|
|
245
|
+
aliases: ['of', 'file'],
|
|
246
|
+
description: 'Custom filename for reporter output (use with single reporter only)',
|
|
247
|
+
}),
|
|
248
|
+
quiet: bargs_1.opt.boolean({
|
|
249
|
+
aliases: ['q'],
|
|
250
|
+
description: 'Minimal output',
|
|
251
|
+
}),
|
|
252
|
+
reporter: bargs_1.opt.array([
|
|
253
|
+
constants_js_1.Reporters.HUMAN,
|
|
254
|
+
constants_js_1.Reporters.JSON,
|
|
255
|
+
constants_js_1.Reporters.CSV,
|
|
256
|
+
constants_js_1.Reporters.NYAN,
|
|
257
|
+
constants_js_1.Reporters.SIMPLE,
|
|
258
|
+
], {
|
|
259
|
+
aliases: ['r'],
|
|
260
|
+
default: [constants_js_1.DEFAULT_REPORTER],
|
|
261
|
+
description: 'Output reporters to use (human,json,csv)',
|
|
262
|
+
}),
|
|
263
|
+
tag: bargs_1.opt.array('string', {
|
|
264
|
+
description: 'Include only benchmarks with any of these tags',
|
|
265
|
+
}),
|
|
266
|
+
time: bargs_1.opt.number({
|
|
267
|
+
aliases: ['t'],
|
|
268
|
+
description: 'Time budget per benchmark in milliseconds',
|
|
269
|
+
}),
|
|
270
|
+
timeout: bargs_1.opt.number({
|
|
271
|
+
description: 'Timeout per benchmark in milliseconds',
|
|
272
|
+
}),
|
|
273
|
+
warmup: bargs_1.opt.number({
|
|
274
|
+
aliases: ['w', 'warm'],
|
|
275
|
+
description: 'Number of warmup iterations',
|
|
276
|
+
}),
|
|
277
|
+
}), bargs_1.pos.positionals(bargs_1.pos.variadic('string', {
|
|
278
|
+
description: 'File paths, directory paths, or glob patterns for benchmark files',
|
|
279
|
+
name: 'pattern',
|
|
280
|
+
})));
|
|
281
|
+
// Add validation via map()
|
|
282
|
+
const runParser = (0, bargs_1.map)(runParserBase, ({ positionals, values }) => {
|
|
283
|
+
if (values.reporter && values.reporter.length > 1 && values['output-file']) {
|
|
284
|
+
throw new Error('--output-file can only be used with a single reporter. Use --output <dir> for multiple reporters.');
|
|
285
|
+
}
|
|
286
|
+
return { positionals, values };
|
|
287
|
+
});
|
|
288
|
+
// ============================================================================
|
|
289
|
+
// Init Command Parser
|
|
290
|
+
// ============================================================================
|
|
291
|
+
const initParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
292
|
+
'config-type': bargs_1.opt.enum(['json', 'yaml', 'js', 'ts'], {
|
|
293
|
+
description: 'Configuration file format',
|
|
294
|
+
}),
|
|
295
|
+
examples: bargs_1.opt.boolean({
|
|
296
|
+
description: 'Include example benchmark files',
|
|
297
|
+
}),
|
|
298
|
+
force: bargs_1.opt.boolean({
|
|
299
|
+
description: 'Overwrite existing files',
|
|
300
|
+
}),
|
|
301
|
+
quiet: bargs_1.opt.boolean({
|
|
302
|
+
aliases: ['q'],
|
|
303
|
+
description: 'Minimal output',
|
|
304
|
+
}),
|
|
305
|
+
yes: bargs_1.opt.boolean({
|
|
306
|
+
aliases: ['y'],
|
|
307
|
+
description: 'Accept all prompts automatically',
|
|
308
|
+
}),
|
|
309
|
+
}), bargs_1.pos.positionals(bargs_1.pos.enum(['basic', 'advanced', 'library'], {
|
|
310
|
+
description: 'Type of project to initialize',
|
|
311
|
+
name: 'type',
|
|
312
|
+
})));
|
|
313
|
+
// ============================================================================
|
|
314
|
+
// Analyze Command Parser
|
|
315
|
+
// ============================================================================
|
|
316
|
+
const analyzeParserBase = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
317
|
+
'filter-file': bargs_1.opt.string({
|
|
318
|
+
description: 'Filter functions by file glob pattern',
|
|
319
|
+
}),
|
|
320
|
+
'group-by-file': bargs_1.opt.boolean({
|
|
321
|
+
description: 'Group results by file',
|
|
322
|
+
}),
|
|
323
|
+
input: bargs_1.opt.string({
|
|
324
|
+
aliases: ['i'],
|
|
325
|
+
description: 'Path to existing *.cpuprofile file',
|
|
326
|
+
}),
|
|
327
|
+
'min-percent': bargs_1.opt.number({
|
|
328
|
+
aliases: ['m', 'min'],
|
|
329
|
+
default: 0.5,
|
|
330
|
+
description: 'Minimum execution percentage to show',
|
|
331
|
+
}),
|
|
332
|
+
top: bargs_1.opt.number({
|
|
333
|
+
aliases: ['n'],
|
|
334
|
+
default: 25,
|
|
335
|
+
description: 'Number of top functions to show',
|
|
336
|
+
}),
|
|
337
|
+
}), bargs_1.pos.positionals(bargs_1.pos.string({
|
|
338
|
+
description: 'Command to analyze (e.g., "npm test")',
|
|
339
|
+
name: 'command',
|
|
340
|
+
})));
|
|
341
|
+
// Add validation
|
|
342
|
+
const analyzeParser = (0, bargs_1.map)(analyzeParserBase, ({ positionals, values }) => {
|
|
343
|
+
const [command] = positionals;
|
|
344
|
+
if (!command && !values.input) {
|
|
345
|
+
throw new Error('Either [command] or --input must be provided');
|
|
346
|
+
}
|
|
347
|
+
return { positionals, values };
|
|
348
|
+
});
|
|
349
|
+
// ============================================================================
|
|
350
|
+
// Test Command Parser
|
|
351
|
+
// ============================================================================
|
|
352
|
+
const testParser = (0, bargs_1.merge)(bargs_1.opt.options({
|
|
353
|
+
bail: bargs_1.opt.boolean({
|
|
354
|
+
aliases: ['b'],
|
|
355
|
+
description: 'Stop on first failure',
|
|
356
|
+
}),
|
|
357
|
+
iterations: bargs_1.opt.number({
|
|
358
|
+
aliases: ['i'],
|
|
359
|
+
default: 100,
|
|
360
|
+
description: 'Number of iterations per test',
|
|
361
|
+
}),
|
|
362
|
+
quiet: bargs_1.opt.boolean({
|
|
363
|
+
aliases: ['q'],
|
|
364
|
+
description: 'Minimal output',
|
|
365
|
+
}),
|
|
366
|
+
warmup: bargs_1.opt.number({
|
|
367
|
+
aliases: ['w'],
|
|
368
|
+
default: 5,
|
|
369
|
+
description: 'Number of warmup iterations',
|
|
370
|
+
}),
|
|
371
|
+
}), bargs_1.pos.positionals(bargs_1.pos.enum(['ava', 'jest', 'mocha', 'node-test'], {
|
|
372
|
+
description: 'Test framework to use',
|
|
373
|
+
name: 'framework',
|
|
374
|
+
required: true,
|
|
375
|
+
}), bargs_1.pos.variadic('string', {
|
|
376
|
+
description: 'Test file paths or glob patterns',
|
|
377
|
+
name: 'files',
|
|
378
|
+
})));
|
|
379
|
+
// ============================================================================
|
|
380
|
+
// Subcommand-specific options
|
|
381
|
+
// ============================================================================
|
|
382
|
+
/**
|
|
383
|
+
* Additional global options for history and baseline subcommands
|
|
384
|
+
*/
|
|
385
|
+
const quietOption = bargs_1.opt.options({
|
|
386
|
+
quiet: bargs_1.opt.boolean({
|
|
387
|
+
description: 'Minimal output',
|
|
388
|
+
}),
|
|
389
|
+
});
|
|
390
|
+
// ============================================================================
|
|
391
|
+
// Main CLI Builder
|
|
392
|
+
// ============================================================================
|
|
393
|
+
/**
|
|
394
|
+
* Synthwave-inspired theme for CLI help output
|
|
395
|
+
*
|
|
396
|
+
* Matches the retro aesthetic used in modestbench reporters
|
|
397
|
+
*/
|
|
398
|
+
const synthwaveTheme = {
|
|
399
|
+
colors: {
|
|
400
|
+
command: bargs_1.ansi.brightMagenta,
|
|
401
|
+
defaultText: bargs_1.ansi.dim,
|
|
402
|
+
defaultValue: bargs_1.ansi.brightYellow,
|
|
403
|
+
description: bargs_1.ansi.brightWhite,
|
|
404
|
+
epilog: bargs_1.ansi.brightWhite,
|
|
405
|
+
example: bargs_1.ansi.cyan,
|
|
406
|
+
flag: bargs_1.ansi.brightCyan,
|
|
407
|
+
positional: bargs_1.ansi.brightMagenta,
|
|
408
|
+
scriptName: bargs_1.ansi.brightCyan + bargs_1.ansi.bold,
|
|
409
|
+
sectionHeader: bargs_1.ansi.magenta + bargs_1.ansi.bold,
|
|
410
|
+
type: bargs_1.ansi.brightWhite + bargs_1.ansi.dim,
|
|
411
|
+
url: bargs_1.ansi.brightCyan + bargs_1.ansi.underline,
|
|
412
|
+
usage: bargs_1.ansi.white,
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
const createCli = (abortController) => {
|
|
416
|
+
return (0, bargs_1.bargs)('modestbench', {
|
|
417
|
+
description: 'A modern benchmark runner for Node.js',
|
|
418
|
+
theme: synthwaveTheme,
|
|
419
|
+
})
|
|
420
|
+
.globals(globalOptions)
|
|
421
|
+
.command('run', runParser, async ({ positionals, values }) => {
|
|
422
|
+
const [pattern] = positionals;
|
|
423
|
+
const context = await createCliContext(values, abortController, values.engine);
|
|
424
|
+
const exitCode = await (0, run_js_1.handleRunCommand)(context, {
|
|
425
|
+
bail: values.bail,
|
|
426
|
+
config: values.config,
|
|
427
|
+
cwd: values.cwd,
|
|
428
|
+
engine: values.engine,
|
|
429
|
+
exclude: values.exclude,
|
|
430
|
+
excludeTags: values['exclude-tag'],
|
|
431
|
+
iterations: values.iterations,
|
|
432
|
+
json: values.json,
|
|
433
|
+
jsonPretty: values['json-pretty'],
|
|
434
|
+
noColor: values['no-color'],
|
|
435
|
+
outputDir: values.output,
|
|
436
|
+
outputFile: values['output-file'],
|
|
437
|
+
pattern,
|
|
438
|
+
progress: values.progress,
|
|
439
|
+
quiet: values.quiet,
|
|
440
|
+
reporters: values.reporter,
|
|
441
|
+
tags: values.tag,
|
|
442
|
+
time: values.time,
|
|
443
|
+
timeout: values.timeout,
|
|
444
|
+
verbose: values.verbose,
|
|
445
|
+
warmup: values.warmup,
|
|
446
|
+
});
|
|
447
|
+
process.exit(exitCode);
|
|
448
|
+
}, 'Run benchmark files')
|
|
449
|
+
.command('history', (history) => history
|
|
450
|
+
.globals(quietOption)
|
|
451
|
+
.command('list', historyListParser, async ({ values }) => {
|
|
452
|
+
const context = await createCliContext(values, abortController);
|
|
453
|
+
const exitCode = await (0, history_js_1.handleListCommand)(context, {
|
|
454
|
+
cwd: values.cwd,
|
|
455
|
+
format: values.format,
|
|
456
|
+
limit: values.limit,
|
|
457
|
+
pattern: values.pattern,
|
|
458
|
+
since: values.since,
|
|
459
|
+
tags: values.tag,
|
|
460
|
+
until: values.until,
|
|
461
|
+
verbose: values.verbose,
|
|
462
|
+
});
|
|
463
|
+
process.exit(exitCode);
|
|
464
|
+
}, 'List recent benchmark runs')
|
|
465
|
+
.command('show', historyShowParser, async ({ positionals, values }) => {
|
|
466
|
+
const [runId] = positionals;
|
|
467
|
+
const context = await createCliContext(values, abortController);
|
|
468
|
+
const exitCode = await (0, history_js_1.handleShowCommand)(context, {
|
|
469
|
+
cwd: values.cwd,
|
|
470
|
+
format: values.format,
|
|
471
|
+
runId,
|
|
472
|
+
verbose: values.verbose,
|
|
473
|
+
});
|
|
474
|
+
process.exit(exitCode);
|
|
475
|
+
}, 'Show detailed results for a specific run')
|
|
476
|
+
.command('compare', historyCompareParser, async ({ positionals, values }) => {
|
|
477
|
+
const [runId1, runId2] = positionals;
|
|
478
|
+
const context = await createCliContext(values, abortController);
|
|
479
|
+
const exitCode = await (0, history_js_1.handleCompareCommand)(context, {
|
|
480
|
+
cwd: values.cwd,
|
|
481
|
+
format: values.format,
|
|
482
|
+
runId1,
|
|
483
|
+
runId2,
|
|
484
|
+
verbose: values.verbose,
|
|
485
|
+
});
|
|
486
|
+
process.exit(exitCode);
|
|
487
|
+
}, 'Compare two benchmark runs')
|
|
488
|
+
.command('trends', historyTrendsParser, async ({ positionals, values }) => {
|
|
489
|
+
const [pattern] = positionals;
|
|
490
|
+
const context = await createCliContext(values, abortController);
|
|
491
|
+
const exitCode = await (0, history_js_1.handleTrendsCommand)(context, {
|
|
492
|
+
all: values.all,
|
|
493
|
+
cwd: values.cwd,
|
|
494
|
+
format: values.format,
|
|
495
|
+
limit: values.limit,
|
|
496
|
+
pattern,
|
|
497
|
+
since: values.since,
|
|
498
|
+
tags: values.tag,
|
|
499
|
+
until: values.until,
|
|
500
|
+
verbose: values.verbose,
|
|
501
|
+
});
|
|
502
|
+
process.exit(exitCode);
|
|
503
|
+
}, 'Show performance trends over time')
|
|
504
|
+
.command('clean', historyCleanParser, async ({ values }) => {
|
|
505
|
+
const context = await createCliContext(values, abortController);
|
|
506
|
+
const exitCode = await (0, history_js_1.handleCleanCommand)(context, {
|
|
507
|
+
confirm: values.yes,
|
|
508
|
+
cwd: values.cwd,
|
|
509
|
+
maxAge: values['max-age'],
|
|
510
|
+
maxRuns: values['max-runs'],
|
|
511
|
+
maxSize: values['max-size'],
|
|
512
|
+
quiet: values.quiet,
|
|
513
|
+
verbose: values.verbose,
|
|
514
|
+
});
|
|
515
|
+
process.exit(exitCode);
|
|
516
|
+
}, 'Clean up old benchmark history')
|
|
517
|
+
.command('export', historyExportParser, async ({ values }) => {
|
|
518
|
+
const context = await createCliContext(values, abortController);
|
|
519
|
+
const exitCode = await (0, history_js_1.handleExportCommand)(context, {
|
|
520
|
+
cwd: values.cwd,
|
|
521
|
+
format: values.format,
|
|
522
|
+
outputPath: values.output,
|
|
523
|
+
quiet: Boolean(values.quiet),
|
|
524
|
+
since: values.since,
|
|
525
|
+
until: values.until,
|
|
526
|
+
verbose: values.verbose,
|
|
527
|
+
});
|
|
528
|
+
process.exitCode = exitCode;
|
|
529
|
+
}, 'Export benchmark history to a file'), 'View and manage benchmark history')
|
|
530
|
+
.command('baseline', (baseline) => baseline
|
|
531
|
+
.globals(quietOption)
|
|
532
|
+
.command('set', baselineSetParser, async ({ positionals, values }) => {
|
|
533
|
+
const [name] = positionals;
|
|
534
|
+
const context = await createCliContext(values, abortController);
|
|
535
|
+
const exitCode = await (0, baseline_js_1.handleSetCommand)(context, {
|
|
536
|
+
branch: values.branch,
|
|
537
|
+
commit: values.commit,
|
|
538
|
+
cwd: values.cwd,
|
|
539
|
+
default: values.default,
|
|
540
|
+
name,
|
|
541
|
+
quiet: Boolean(values.quiet),
|
|
542
|
+
runId: values['run-id'],
|
|
543
|
+
verbose: values.verbose,
|
|
544
|
+
});
|
|
545
|
+
process.exit(exitCode);
|
|
546
|
+
}, 'Save a benchmark run as a baseline')
|
|
547
|
+
.command('list', baselineListParser, async ({ values }) => {
|
|
548
|
+
const context = await createCliContext(values, abortController);
|
|
549
|
+
const exitCode = await (0, baseline_js_1.handleListCommand)(context, {
|
|
550
|
+
cwd: values.cwd,
|
|
551
|
+
format: values.format,
|
|
552
|
+
quiet: Boolean(values.quiet),
|
|
553
|
+
verbose: values.verbose,
|
|
554
|
+
});
|
|
555
|
+
process.exit(exitCode);
|
|
556
|
+
}, 'List all saved baselines')
|
|
557
|
+
.command('show', baselineShowParser, async ({ positionals, values }) => {
|
|
558
|
+
const [name] = positionals;
|
|
559
|
+
const context = await createCliContext(values, abortController);
|
|
560
|
+
const exitCode = await (0, baseline_js_1.handleShowCommand)(context, {
|
|
561
|
+
cwd: values.cwd,
|
|
562
|
+
format: values.format,
|
|
563
|
+
name,
|
|
564
|
+
quiet: Boolean(values.quiet),
|
|
565
|
+
verbose: values.verbose,
|
|
566
|
+
});
|
|
567
|
+
process.exit(exitCode);
|
|
568
|
+
}, 'Show baseline details')
|
|
569
|
+
.command('delete', baselineDeleteParser, async ({ positionals, values }) => {
|
|
570
|
+
const [name] = positionals;
|
|
571
|
+
const context = await createCliContext(values, abortController);
|
|
572
|
+
const exitCode = await (0, baseline_js_1.handleDeleteCommand)(context, {
|
|
573
|
+
cwd: values.cwd,
|
|
574
|
+
name,
|
|
575
|
+
quiet: Boolean(values.quiet),
|
|
576
|
+
verbose: values.verbose,
|
|
577
|
+
});
|
|
578
|
+
process.exit(exitCode);
|
|
579
|
+
}, 'Delete a baseline')
|
|
580
|
+
.command('analyze', baselineAnalyzeParser, async ({ values }) => {
|
|
581
|
+
const context = await createCliContext(values, abortController);
|
|
582
|
+
const exitCode = await (0, baseline_js_1.handleAnalyzeCommand)(context, {
|
|
583
|
+
confidence: values.confidence,
|
|
584
|
+
cwd: values.cwd,
|
|
585
|
+
quiet: Boolean(values.quiet),
|
|
586
|
+
runs: values.runs,
|
|
587
|
+
verbose: values.verbose,
|
|
588
|
+
});
|
|
589
|
+
process.exit(exitCode);
|
|
590
|
+
}, 'Analyze history and suggest performance budgets'), 'Manage performance baselines')
|
|
591
|
+
.command('init', initParser, async ({ positionals, values }) => {
|
|
592
|
+
const [type] = positionals;
|
|
593
|
+
const context = await createCliContext(values, abortController);
|
|
594
|
+
const exitCode = await (0, init_js_1.handleInitCommand)(context, {
|
|
595
|
+
configType: values['config-type'],
|
|
596
|
+
cwd: values.cwd,
|
|
597
|
+
examples: values.examples,
|
|
598
|
+
force: values.force,
|
|
599
|
+
quiet: values.quiet,
|
|
600
|
+
type,
|
|
601
|
+
verbose: values.verbose,
|
|
602
|
+
yes: values.yes,
|
|
603
|
+
});
|
|
604
|
+
process.exitCode = exitCode;
|
|
605
|
+
}, 'Initialize a new benchmark project')
|
|
606
|
+
.command('analyze', analyzeParser, async ({ positionals, values }) => {
|
|
607
|
+
const [command] = positionals;
|
|
608
|
+
// Context not needed for analyze command currently
|
|
609
|
+
const context = {};
|
|
610
|
+
const options = {
|
|
611
|
+
color: !values['no-color'],
|
|
612
|
+
command,
|
|
613
|
+
cwd: values.cwd || process.cwd(),
|
|
614
|
+
filterFile: values['filter-file'],
|
|
615
|
+
groupByFile: values['group-by-file'],
|
|
616
|
+
input: values.input,
|
|
617
|
+
minPercent: values['min-percent'],
|
|
618
|
+
top: values.top,
|
|
619
|
+
};
|
|
620
|
+
process.exitCode = await (0, analyze_js_1.handleAnalyzeCommand)(context, options);
|
|
621
|
+
}, {
|
|
622
|
+
aliases: ['profile'],
|
|
623
|
+
description: 'Analyze code execution and identify benchmark candidates',
|
|
624
|
+
})
|
|
625
|
+
.command('test', testParser, async ({ positionals, values }) => {
|
|
626
|
+
const [framework, files] = positionals;
|
|
627
|
+
const context = await createCliContext(values, abortController);
|
|
628
|
+
const options = {
|
|
629
|
+
bail: values.bail,
|
|
630
|
+
cwd: values.cwd,
|
|
631
|
+
framework,
|
|
632
|
+
iterations: values.iterations,
|
|
633
|
+
json: values.json,
|
|
634
|
+
noColor: values['no-color'],
|
|
635
|
+
pattern: files,
|
|
636
|
+
quiet: values.quiet,
|
|
637
|
+
verbose: values.verbose,
|
|
638
|
+
warmup: values.warmup,
|
|
639
|
+
};
|
|
640
|
+
const exitCode = await (0, test_js_1.handleTestCommand)(context, options);
|
|
641
|
+
process.exit(exitCode);
|
|
642
|
+
}, 'Run test files as benchmarks')
|
|
643
|
+
.defaultCommand('run');
|
|
644
|
+
};
|
|
31
645
|
/**
|
|
32
646
|
* Initialize and run the CLI
|
|
33
647
|
*/
|
|
@@ -44,870 +658,41 @@ exports.cli = cli;
|
|
|
44
658
|
* Main CLI entry point
|
|
45
659
|
*/
|
|
46
660
|
const main = async (argv, abortController) => {
|
|
661
|
+
const controller = abortController ?? new AbortController();
|
|
47
662
|
try {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
// Configure global options and commands
|
|
51
|
-
await cli
|
|
52
|
-
.scriptName('modestbench')
|
|
53
|
-
.option('config', {
|
|
54
|
-
alias: 'c',
|
|
55
|
-
description: 'Path to configuration file',
|
|
56
|
-
global: true,
|
|
57
|
-
type: 'string',
|
|
58
|
-
})
|
|
59
|
-
.option('verbose', {
|
|
60
|
-
alias: 'v',
|
|
61
|
-
defaultDescription: String(run_js_1.RUN_COMMAND_DEFAULTS.verbose),
|
|
62
|
-
description: 'Enable verbose output',
|
|
63
|
-
global: true,
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
})
|
|
66
|
-
.option('no-color', {
|
|
67
|
-
defaultDescription: 'false',
|
|
68
|
-
description: 'Disable colored output',
|
|
69
|
-
global: true,
|
|
70
|
-
type: 'boolean',
|
|
71
|
-
})
|
|
72
|
-
.option('progress', {
|
|
73
|
-
defaultDescription: 'true',
|
|
74
|
-
description: 'Show animated progress bar',
|
|
75
|
-
global: true,
|
|
76
|
-
type: 'boolean',
|
|
77
|
-
})
|
|
78
|
-
.option('json', {
|
|
79
|
-
defaultDescription: 'false',
|
|
80
|
-
description: 'Output results in JSON format',
|
|
81
|
-
global: true,
|
|
82
|
-
type: 'boolean',
|
|
83
|
-
})
|
|
84
|
-
.option('cwd', {
|
|
85
|
-
defaultDescription: '.',
|
|
86
|
-
description: 'Working directory',
|
|
87
|
-
global: true,
|
|
88
|
-
normalize: true,
|
|
89
|
-
type: 'string',
|
|
90
|
-
})
|
|
91
|
-
.help()
|
|
92
|
-
.alias('help', 'h')
|
|
93
|
-
.version()
|
|
94
|
-
.alias('version', 'V')
|
|
95
|
-
.strict()
|
|
96
|
-
.demandCommand(1)
|
|
97
|
-
.recommendCommands()
|
|
98
|
-
.completion()
|
|
99
|
-
.wrap(Math.min(120, cli.terminalWidth()))
|
|
100
|
-
.command(['$0 [pattern..]', 'run [pattern..]'], 'Run benchmark files', (yargs) => yargs
|
|
101
|
-
.positional('pattern', {
|
|
102
|
-
array: true,
|
|
103
|
-
defaultDescription: `(auto-discovered from ${constants_js_1.DEFAULT_BENCHMARK_DIR} directory)`,
|
|
104
|
-
describe: 'File paths, directory paths, or glob patterns for benchmark files',
|
|
105
|
-
type: 'string',
|
|
106
|
-
})
|
|
107
|
-
.option('config', {
|
|
108
|
-
alias: 'c',
|
|
109
|
-
description: 'Path to configuration file',
|
|
110
|
-
type: 'string',
|
|
111
|
-
})
|
|
112
|
-
.option('reporter', {
|
|
113
|
-
alias: 'r',
|
|
114
|
-
array: true,
|
|
115
|
-
choices: Object.values(constants_js_1.Reporters).sort(),
|
|
116
|
-
defaultDescription: constants_js_1.DEFAULT_REPORTER,
|
|
117
|
-
description: 'Output reporters to use (human,json,csv)',
|
|
118
|
-
type: 'string',
|
|
119
|
-
})
|
|
120
|
-
.option('output', {
|
|
121
|
-
alias: 'o',
|
|
122
|
-
description: 'Output directory for reports',
|
|
123
|
-
type: 'string',
|
|
124
|
-
})
|
|
125
|
-
.option('output-file', {
|
|
126
|
-
alias: ['of', 'file'],
|
|
127
|
-
description: 'Custom filename for reporter output (use with single reporter only)',
|
|
128
|
-
requiresArg: true,
|
|
129
|
-
type: 'string',
|
|
130
|
-
})
|
|
131
|
-
.option('iterations', {
|
|
132
|
-
alias: 'i',
|
|
133
|
-
description: 'Number of iterations per benchmark',
|
|
134
|
-
type: 'number',
|
|
135
|
-
})
|
|
136
|
-
.option('time', {
|
|
137
|
-
alias: 't',
|
|
138
|
-
description: 'Time budget per benchmark in milliseconds',
|
|
139
|
-
type: 'number',
|
|
140
|
-
})
|
|
141
|
-
.option('warmup', {
|
|
142
|
-
alias: ['w', 'warm'],
|
|
143
|
-
description: 'Number of warmup iterations',
|
|
144
|
-
type: 'number',
|
|
145
|
-
})
|
|
146
|
-
.option('limit-by', {
|
|
147
|
-
alias: ['l', 'limit'],
|
|
148
|
-
choices: ['time', 'iterations', 'any', 'all'],
|
|
149
|
-
description: 'How to limit benchmarks: time (time budget), iterations (sample count), any (either threshold), all (both thresholds)',
|
|
150
|
-
type: 'string',
|
|
151
|
-
})
|
|
152
|
-
.option('bail', {
|
|
153
|
-
alias: 'b',
|
|
154
|
-
defaultDescription: String(run_js_1.RUN_COMMAND_DEFAULTS.bail),
|
|
155
|
-
description: 'Stop on first failure',
|
|
156
|
-
type: 'boolean',
|
|
157
|
-
})
|
|
158
|
-
.option('exclude', {
|
|
159
|
-
alias: 'X',
|
|
160
|
-
array: true,
|
|
161
|
-
description: 'Exclude patterns (comma-separated)',
|
|
162
|
-
type: 'string',
|
|
163
|
-
})
|
|
164
|
-
.option('timeout', {
|
|
165
|
-
description: 'Timeout per benchmark in milliseconds',
|
|
166
|
-
type: 'number',
|
|
167
|
-
})
|
|
168
|
-
.option('quiet', {
|
|
169
|
-
alias: 'q',
|
|
170
|
-
defaultDescription: String(run_js_1.RUN_COMMAND_DEFAULTS.quiet),
|
|
171
|
-
description: 'Minimal output',
|
|
172
|
-
type: 'boolean',
|
|
173
|
-
})
|
|
174
|
-
.option('tag', {
|
|
175
|
-
array: true,
|
|
176
|
-
description: 'Include only benchmarks with any of these tags',
|
|
177
|
-
type: 'string',
|
|
178
|
-
})
|
|
179
|
-
.option('exclude-tag', {
|
|
180
|
-
alias: 'T',
|
|
181
|
-
array: true,
|
|
182
|
-
description: 'Exclude benchmarks with any of these tags',
|
|
183
|
-
type: 'string',
|
|
184
|
-
})
|
|
185
|
-
.option('engine', {
|
|
186
|
-
alias: 'e',
|
|
187
|
-
choices: Object.values(constants_js_1.Engines),
|
|
188
|
-
defaultDescription: constants_js_1.DEFAULT_ENGINE,
|
|
189
|
-
description: 'Benchmark engine: tinybench (default) or accurate (requires --allow-natives-syntax)',
|
|
190
|
-
type: 'string',
|
|
191
|
-
})
|
|
192
|
-
.example([
|
|
193
|
-
['$0 run', 'Run benchmarks in current directory and bench/'],
|
|
194
|
-
['$0 run benchmarks/', 'Run all benchmarks in a directory'],
|
|
195
|
-
['$0 run src/perf/', 'Run benchmarks in specific directory'],
|
|
196
|
-
['$0 run "src/**/*.bench.js"', 'Run specific glob pattern'],
|
|
197
|
-
['$0 run file1.bench.js file2.bench.js', 'Run specific files'],
|
|
198
|
-
['$0 run benchmarks/ tests/perf/', 'Run multiple directories'],
|
|
199
|
-
['$0 run -r json -r csv', 'Use multiple reporters'],
|
|
200
|
-
['$0 run --iterations 1000', 'Set iteration count'],
|
|
201
|
-
['$0 run --engine accurate', 'Use high-accuracy engine'],
|
|
202
|
-
['$0 run --bail', 'Stop on first failure'],
|
|
203
|
-
])
|
|
204
|
-
.check((argv) => {
|
|
205
|
-
if (argv.reporter &&
|
|
206
|
-
argv.reporter.length > 1 &&
|
|
207
|
-
argv['output-file']) {
|
|
208
|
-
throw new Error('--output-file can only be used with a single reporter. Use --output <dir> for multiple reporters.');
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}), async (argv) => {
|
|
212
|
-
const context = await createCliContext(argv, abortController, argv.engine);
|
|
213
|
-
const exitCode = await (0, run_js_1.handleRunCommand)(context, {
|
|
214
|
-
bail: argv.bail,
|
|
215
|
-
config: argv.config,
|
|
216
|
-
cwd: argv.cwd,
|
|
217
|
-
engine: argv.engine,
|
|
218
|
-
exclude: argv.exclude,
|
|
219
|
-
excludeTags: argv['exclude-tag'],
|
|
220
|
-
iterations: argv.iterations,
|
|
221
|
-
json: argv.json,
|
|
222
|
-
noColor: argv.noColor,
|
|
223
|
-
outputDir: argv.output,
|
|
224
|
-
outputFile: argv['output-file'],
|
|
225
|
-
pattern: argv.pattern,
|
|
226
|
-
progress: argv.progress,
|
|
227
|
-
quiet: argv.quiet,
|
|
228
|
-
reporters: argv.reporter,
|
|
229
|
-
tags: argv.tag,
|
|
230
|
-
time: argv.time,
|
|
231
|
-
timeout: argv.timeout,
|
|
232
|
-
verbose: argv.verbose,
|
|
233
|
-
warmup: argv.warmup,
|
|
234
|
-
});
|
|
235
|
-
process.exit(exitCode);
|
|
236
|
-
})
|
|
237
|
-
.command('history', 'View and manage benchmark history', (yargs) => yargs
|
|
238
|
-
.command('list', 'List recent benchmark runs', (yargs) => yargs
|
|
239
|
-
.option('since', {
|
|
240
|
-
description: 'Show runs since date (ISO 8601 or relative like "1 week ago")',
|
|
241
|
-
type: 'string',
|
|
242
|
-
})
|
|
243
|
-
.option('until', {
|
|
244
|
-
description: 'Show runs until date (ISO 8601 or relative like "1 day ago")',
|
|
245
|
-
type: 'string',
|
|
246
|
-
})
|
|
247
|
-
.option('pattern', {
|
|
248
|
-
description: 'Filter by benchmark name pattern',
|
|
249
|
-
type: 'string',
|
|
250
|
-
})
|
|
251
|
-
.option('tag', {
|
|
252
|
-
alias: 't',
|
|
253
|
-
array: true,
|
|
254
|
-
description: 'Filter by tags (comma-separated)',
|
|
255
|
-
type: 'string',
|
|
256
|
-
})
|
|
257
|
-
.option('limit', {
|
|
258
|
-
defaultDescription: '10',
|
|
259
|
-
description: 'Maximum number of results',
|
|
260
|
-
type: 'number',
|
|
261
|
-
})
|
|
262
|
-
.option('format', {
|
|
263
|
-
choices: ['human', 'json', 'csv'],
|
|
264
|
-
defaultDescription: 'human',
|
|
265
|
-
description: 'Output format',
|
|
266
|
-
type: 'string',
|
|
267
|
-
})
|
|
268
|
-
.example([
|
|
269
|
-
['$0 history list', 'List recent benchmark runs'],
|
|
270
|
-
[
|
|
271
|
-
'$0 history list --since "1 week ago"',
|
|
272
|
-
'List runs from last week',
|
|
273
|
-
],
|
|
274
|
-
['$0 history list --limit 20', 'List 20 most recent runs'],
|
|
275
|
-
['$0 history list --format json', 'List runs in JSON format'],
|
|
276
|
-
]), async (argv) => {
|
|
277
|
-
const context = await createCliContext(argv, abortController);
|
|
278
|
-
const exitCode = await (0, history_js_1.handleListCommand)(context, {
|
|
279
|
-
cwd: argv.cwd,
|
|
280
|
-
format: argv.format,
|
|
281
|
-
limit: argv.limit,
|
|
282
|
-
pattern: argv.pattern,
|
|
283
|
-
since: argv.since,
|
|
284
|
-
tags: argv.tag,
|
|
285
|
-
until: argv.until,
|
|
286
|
-
verbose: argv.verbose,
|
|
287
|
-
});
|
|
288
|
-
process.exit(exitCode);
|
|
289
|
-
})
|
|
290
|
-
.command('show <run-id>', 'Show detailed results for a specific run', (yargs) => yargs
|
|
291
|
-
.positional('run-id', {
|
|
292
|
-
demandOption: true,
|
|
293
|
-
describe: 'ID of the benchmark run to show',
|
|
294
|
-
type: 'string',
|
|
295
|
-
})
|
|
296
|
-
.option('format', {
|
|
297
|
-
choices: ['human', 'json', 'csv'],
|
|
298
|
-
defaultDescription: 'human',
|
|
299
|
-
description: 'Output format',
|
|
300
|
-
type: 'string',
|
|
301
|
-
})
|
|
302
|
-
.example([
|
|
303
|
-
[
|
|
304
|
-
'$0 history show abc123',
|
|
305
|
-
'Show detailed results for run abc123',
|
|
306
|
-
],
|
|
307
|
-
[
|
|
308
|
-
'$0 history show abc123 --format json',
|
|
309
|
-
'Show run in JSON format',
|
|
310
|
-
],
|
|
311
|
-
]), async (argv) => {
|
|
312
|
-
const context = await createCliContext(argv, abortController);
|
|
313
|
-
const exitCode = await (0, history_js_1.handleShowCommand)(context, {
|
|
314
|
-
cwd: argv.cwd,
|
|
315
|
-
format: argv.format,
|
|
316
|
-
runId: argv['run-id'],
|
|
317
|
-
verbose: argv.verbose,
|
|
318
|
-
});
|
|
319
|
-
process.exit(exitCode);
|
|
320
|
-
})
|
|
321
|
-
.command('compare <run-id1> <run-id2>', 'Compare two benchmark runs', (yargs) => yargs
|
|
322
|
-
.positional('run-id1', {
|
|
323
|
-
demandOption: true,
|
|
324
|
-
describe: 'ID of the first benchmark run',
|
|
325
|
-
type: 'string',
|
|
326
|
-
})
|
|
327
|
-
.positional('run-id2', {
|
|
328
|
-
demandOption: true,
|
|
329
|
-
describe: 'ID of the second benchmark run',
|
|
330
|
-
type: 'string',
|
|
331
|
-
})
|
|
332
|
-
.option('format', {
|
|
333
|
-
choices: ['human', 'json'],
|
|
334
|
-
defaultDescription: 'human',
|
|
335
|
-
description: 'Output format',
|
|
336
|
-
type: 'string',
|
|
337
|
-
})
|
|
338
|
-
.example([
|
|
339
|
-
['$0 history compare abc123 def456', 'Compare two runs'],
|
|
340
|
-
[
|
|
341
|
-
'$0 history compare abc123 def456 --format json',
|
|
342
|
-
'Compare in JSON format',
|
|
343
|
-
],
|
|
344
|
-
]), async (argv) => {
|
|
345
|
-
const context = await createCliContext(argv, abortController);
|
|
346
|
-
const exitCode = await (0, history_js_1.handleCompareCommand)(context, {
|
|
347
|
-
cwd: argv.cwd,
|
|
348
|
-
format: argv.format,
|
|
349
|
-
runId1: argv['run-id1'],
|
|
350
|
-
runId2: argv['run-id2'],
|
|
351
|
-
verbose: argv.verbose,
|
|
352
|
-
});
|
|
353
|
-
process.exit(exitCode);
|
|
354
|
-
})
|
|
355
|
-
.command('trends [pattern]', 'Show performance trends over time', (yargs) => yargs
|
|
356
|
-
.positional('pattern', {
|
|
357
|
-
describe: 'Filter by benchmark name pattern',
|
|
358
|
-
type: 'string',
|
|
359
|
-
})
|
|
360
|
-
.option('since', {
|
|
361
|
-
description: 'Show trends since date (ISO 8601 or relative like "1 week ago")',
|
|
362
|
-
type: 'string',
|
|
363
|
-
})
|
|
364
|
-
.option('until', {
|
|
365
|
-
description: 'Show trends until date (ISO 8601 or relative like "1 day ago")',
|
|
366
|
-
type: 'string',
|
|
367
|
-
})
|
|
368
|
-
.option('tag', {
|
|
369
|
-
alias: 't',
|
|
370
|
-
array: true,
|
|
371
|
-
description: 'Filter by tags (comma-separated)',
|
|
372
|
-
type: 'string',
|
|
373
|
-
})
|
|
374
|
-
.option('limit', {
|
|
375
|
-
description: 'Maximum number of runs to analyze',
|
|
376
|
-
type: 'number',
|
|
377
|
-
})
|
|
378
|
-
.option('all', {
|
|
379
|
-
alias: 'a',
|
|
380
|
-
defaultDescription: 'false',
|
|
381
|
-
description: 'Analyze all runs (ignore limit)',
|
|
382
|
-
type: 'boolean',
|
|
383
|
-
})
|
|
384
|
-
.option('format', {
|
|
385
|
-
choices: ['human', 'json'],
|
|
386
|
-
defaultDescription: 'human',
|
|
387
|
-
description: 'Output format',
|
|
388
|
-
type: 'string',
|
|
389
|
-
})
|
|
390
|
-
.example([
|
|
391
|
-
[
|
|
392
|
-
'$0 history trends',
|
|
393
|
-
'Show performance trends for all benchmarks',
|
|
394
|
-
],
|
|
395
|
-
[
|
|
396
|
-
'$0 history trends --since "1 month ago"',
|
|
397
|
-
'Show trends from last month',
|
|
398
|
-
],
|
|
399
|
-
[
|
|
400
|
-
'$0 history trends "array-*"',
|
|
401
|
-
'Show trends for array benchmarks',
|
|
402
|
-
],
|
|
403
|
-
[
|
|
404
|
-
'$0 history trends --format json',
|
|
405
|
-
'Output trends in JSON format',
|
|
406
|
-
],
|
|
407
|
-
]), async (argv) => {
|
|
408
|
-
const context = await createCliContext(argv, abortController);
|
|
409
|
-
const exitCode = await (0, history_js_1.handleTrendsCommand)(context, {
|
|
410
|
-
all: argv.all,
|
|
411
|
-
cwd: argv.cwd,
|
|
412
|
-
format: argv.format,
|
|
413
|
-
limit: argv.limit,
|
|
414
|
-
pattern: argv.pattern,
|
|
415
|
-
since: argv.since,
|
|
416
|
-
tags: argv.tag,
|
|
417
|
-
until: argv.until,
|
|
418
|
-
verbose: argv.verbose,
|
|
419
|
-
});
|
|
420
|
-
process.exit(exitCode);
|
|
421
|
-
})
|
|
422
|
-
.command('clean', 'Clean up old benchmark history', (yargs) => yargs
|
|
423
|
-
.option('max-age', {
|
|
424
|
-
description: 'Remove runs older than this many days',
|
|
425
|
-
type: 'number',
|
|
426
|
-
})
|
|
427
|
-
.option('max-runs', {
|
|
428
|
-
description: 'Keep only this many most recent runs',
|
|
429
|
-
type: 'number',
|
|
430
|
-
})
|
|
431
|
-
.option('max-size', {
|
|
432
|
-
description: 'Keep history under this size in bytes',
|
|
433
|
-
type: 'number',
|
|
434
|
-
})
|
|
435
|
-
.option('yes', {
|
|
436
|
-
alias: 'y',
|
|
437
|
-
description: 'Confirm cleanup without prompting',
|
|
438
|
-
type: 'boolean',
|
|
439
|
-
})
|
|
440
|
-
.option('quiet', {
|
|
441
|
-
default: false,
|
|
442
|
-
description: 'Minimal output',
|
|
443
|
-
type: 'boolean',
|
|
444
|
-
})
|
|
445
|
-
.check((argv) => {
|
|
446
|
-
if (!argv['max-age'] &&
|
|
447
|
-
!argv['max-runs'] &&
|
|
448
|
-
!argv['max-size']) {
|
|
449
|
-
throw new Error('At least one cleanup criterion must be specified (--max-age, --max-runs, or --max-size)');
|
|
450
|
-
}
|
|
451
|
-
return true;
|
|
452
|
-
})
|
|
453
|
-
.example([
|
|
454
|
-
[
|
|
455
|
-
'$0 history clean --max-runs 50 --yes',
|
|
456
|
-
'Keep only latest 50 runs',
|
|
457
|
-
],
|
|
458
|
-
[
|
|
459
|
-
'$0 history clean --max-age 30',
|
|
460
|
-
'Preview removing runs older than 30 days',
|
|
461
|
-
],
|
|
462
|
-
[
|
|
463
|
-
'$0 history clean --max-size 10485760',
|
|
464
|
-
'Keep history under 10MB',
|
|
465
|
-
],
|
|
466
|
-
]), async (argv) => {
|
|
467
|
-
const context = await createCliContext(argv, abortController);
|
|
468
|
-
const exitCode = await (0, history_js_1.handleCleanCommand)(context, {
|
|
469
|
-
confirm: argv.yes,
|
|
470
|
-
cwd: argv.cwd,
|
|
471
|
-
maxAge: argv['max-age'],
|
|
472
|
-
maxRuns: argv['max-runs'],
|
|
473
|
-
maxSize: argv['max-size'],
|
|
474
|
-
quiet: argv.quiet,
|
|
475
|
-
verbose: argv.verbose,
|
|
476
|
-
});
|
|
477
|
-
process.exit(exitCode);
|
|
478
|
-
})
|
|
479
|
-
.command('export', 'Export benchmark history to a file', (yargs) => yargs
|
|
480
|
-
.option('format', {
|
|
481
|
-
choices: ['json', 'csv'],
|
|
482
|
-
defaultDescription: 'json',
|
|
483
|
-
description: 'Export format',
|
|
484
|
-
type: 'string',
|
|
485
|
-
})
|
|
486
|
-
.option('output', {
|
|
487
|
-
alias: 'o',
|
|
488
|
-
demandOption: true,
|
|
489
|
-
description: 'Output file path',
|
|
490
|
-
type: 'string',
|
|
491
|
-
})
|
|
492
|
-
.option('since', {
|
|
493
|
-
description: 'Export runs since date',
|
|
494
|
-
type: 'string',
|
|
495
|
-
})
|
|
496
|
-
.option('until', {
|
|
497
|
-
description: 'Export runs until date',
|
|
498
|
-
type: 'string',
|
|
499
|
-
})
|
|
500
|
-
.example([
|
|
501
|
-
[
|
|
502
|
-
'$0 history export -o history.json',
|
|
503
|
-
'Export all history to JSON',
|
|
504
|
-
],
|
|
505
|
-
[
|
|
506
|
-
'$0 history export -o history.csv --format csv',
|
|
507
|
-
'Export to CSV',
|
|
508
|
-
],
|
|
509
|
-
[
|
|
510
|
-
'$0 history export -o recent.json --since "1 week ago"',
|
|
511
|
-
'Export recent runs',
|
|
512
|
-
],
|
|
513
|
-
]), async (argv) => {
|
|
514
|
-
const context = await createCliContext(argv, abortController);
|
|
515
|
-
const exitCode = await (0, history_js_1.handleExportCommand)(context, {
|
|
516
|
-
cwd: argv.cwd,
|
|
517
|
-
format: argv.format,
|
|
518
|
-
outputPath: argv.output,
|
|
519
|
-
quiet: Boolean(argv.quiet),
|
|
520
|
-
since: argv.since,
|
|
521
|
-
until: argv.until,
|
|
522
|
-
verbose: argv.verbose,
|
|
523
|
-
});
|
|
524
|
-
process.exitCode = exitCode;
|
|
525
|
-
})
|
|
526
|
-
.demandCommand(1, 'You must specify a history subcommand')
|
|
527
|
-
.strict()
|
|
528
|
-
.example([
|
|
529
|
-
['$0 history list', 'List recent benchmark runs'],
|
|
530
|
-
['$0 history show <run-id>', 'Show detailed results'],
|
|
531
|
-
['$0 history compare <run-id1> <run-id2>', 'Compare two runs'],
|
|
532
|
-
['$0 history trends', 'Show performance trends'],
|
|
533
|
-
['$0 history clean --max-runs 50', 'Keep only latest 50 runs'],
|
|
534
|
-
['$0 history export -o data.json', 'Export history'],
|
|
535
|
-
]))
|
|
536
|
-
.command('baseline', 'Manage performance baselines', (yargs) => {
|
|
537
|
-
return yargs
|
|
538
|
-
.command('set <name>', 'Save a benchmark run as a baseline', (yargs) => {
|
|
539
|
-
return yargs
|
|
540
|
-
.positional('name', {
|
|
541
|
-
describe: 'Name for the baseline',
|
|
542
|
-
type: 'string',
|
|
543
|
-
})
|
|
544
|
-
.option('run-id', {
|
|
545
|
-
description: 'Specific run ID to save (default: most recent)',
|
|
546
|
-
type: 'string',
|
|
547
|
-
})
|
|
548
|
-
.option('commit', {
|
|
549
|
-
description: 'Git commit SHA (40 characters)',
|
|
550
|
-
type: 'string',
|
|
551
|
-
})
|
|
552
|
-
.option('branch', {
|
|
553
|
-
description: 'Git branch name',
|
|
554
|
-
type: 'string',
|
|
555
|
-
})
|
|
556
|
-
.option('default', {
|
|
557
|
-
defaultDescription: 'false',
|
|
558
|
-
description: 'Set as default baseline',
|
|
559
|
-
type: 'boolean',
|
|
560
|
-
})
|
|
561
|
-
.example([
|
|
562
|
-
[
|
|
563
|
-
'$0 baseline set production-v1.0',
|
|
564
|
-
'Save most recent run as baseline',
|
|
565
|
-
],
|
|
566
|
-
['$0 baseline set v1.0 --default', 'Save and set as default'],
|
|
567
|
-
[
|
|
568
|
-
'$0 baseline set v1.0 --commit abc123...',
|
|
569
|
-
'Save with commit info',
|
|
570
|
-
],
|
|
571
|
-
]);
|
|
572
|
-
}, async (argv) => {
|
|
573
|
-
const context = await createCliContext(argv, abortController);
|
|
574
|
-
const exitCode = await (0, baseline_js_1.handleSetCommand)(context, {
|
|
575
|
-
branch: argv.branch,
|
|
576
|
-
commit: argv.commit,
|
|
577
|
-
cwd: argv.cwd,
|
|
578
|
-
default: argv.default,
|
|
579
|
-
name: String(argv.name),
|
|
580
|
-
quiet: Boolean(argv.quiet),
|
|
581
|
-
runId: argv['run-id'],
|
|
582
|
-
verbose: argv.verbose,
|
|
583
|
-
});
|
|
584
|
-
process.exit(exitCode);
|
|
585
|
-
})
|
|
586
|
-
.command('list', 'List all saved baselines', (yargs) => {
|
|
587
|
-
return yargs
|
|
588
|
-
.option('format', {
|
|
589
|
-
choices: ['human', 'json'],
|
|
590
|
-
defaultDescription: 'human',
|
|
591
|
-
description: 'Output format',
|
|
592
|
-
type: 'string',
|
|
593
|
-
})
|
|
594
|
-
.example([
|
|
595
|
-
['$0 baseline list', 'List all baselines'],
|
|
596
|
-
['$0 baseline list --format json', 'List in JSON format'],
|
|
597
|
-
]);
|
|
598
|
-
}, async (argv) => {
|
|
599
|
-
const context = await createCliContext(argv, abortController);
|
|
600
|
-
const exitCode = await (0, baseline_js_1.handleListCommand)(context, {
|
|
601
|
-
cwd: argv.cwd,
|
|
602
|
-
format: argv.format,
|
|
603
|
-
quiet: Boolean(argv.quiet),
|
|
604
|
-
verbose: argv.verbose,
|
|
605
|
-
});
|
|
606
|
-
process.exit(exitCode);
|
|
607
|
-
})
|
|
608
|
-
.command('show <name>', 'Show baseline details', (yargs) => {
|
|
609
|
-
return yargs
|
|
610
|
-
.positional('name', {
|
|
611
|
-
describe: 'Baseline name to show',
|
|
612
|
-
type: 'string',
|
|
613
|
-
})
|
|
614
|
-
.option('format', {
|
|
615
|
-
choices: ['human', 'json'],
|
|
616
|
-
defaultDescription: 'human',
|
|
617
|
-
description: 'Output format',
|
|
618
|
-
type: 'string',
|
|
619
|
-
})
|
|
620
|
-
.example([
|
|
621
|
-
['$0 baseline show production-v1.0', 'Show baseline details'],
|
|
622
|
-
[
|
|
623
|
-
'$0 baseline show v1.0 --format json',
|
|
624
|
-
'Show in JSON format',
|
|
625
|
-
],
|
|
626
|
-
]);
|
|
627
|
-
}, async (argv) => {
|
|
628
|
-
const context = await createCliContext(argv, abortController);
|
|
629
|
-
const exitCode = await (0, baseline_js_1.handleShowCommand)(context, {
|
|
630
|
-
cwd: argv.cwd,
|
|
631
|
-
format: argv.format,
|
|
632
|
-
name: String(argv.name),
|
|
633
|
-
quiet: Boolean(argv.quiet),
|
|
634
|
-
verbose: argv.verbose,
|
|
635
|
-
});
|
|
636
|
-
process.exit(exitCode);
|
|
637
|
-
})
|
|
638
|
-
.command('delete <name>', 'Delete a baseline', (yargs) => {
|
|
639
|
-
return yargs
|
|
640
|
-
.positional('name', {
|
|
641
|
-
describe: 'Baseline name to delete',
|
|
642
|
-
type: 'string',
|
|
643
|
-
})
|
|
644
|
-
.example([
|
|
645
|
-
['$0 baseline delete old-baseline', 'Delete a baseline'],
|
|
646
|
-
]);
|
|
647
|
-
}, async (argv) => {
|
|
648
|
-
const context = await createCliContext(argv, abortController);
|
|
649
|
-
const exitCode = await (0, baseline_js_1.handleDeleteCommand)(context, {
|
|
650
|
-
cwd: argv.cwd,
|
|
651
|
-
name: String(argv.name),
|
|
652
|
-
quiet: Boolean(argv.quiet),
|
|
653
|
-
verbose: argv.verbose,
|
|
654
|
-
});
|
|
655
|
-
process.exit(exitCode);
|
|
656
|
-
})
|
|
657
|
-
.command('analyze', 'Analyze history and suggest performance budgets', (yargs) => {
|
|
658
|
-
return yargs
|
|
659
|
-
.option('runs', {
|
|
660
|
-
defaultDescription: '10',
|
|
661
|
-
description: 'Number of recent runs to analyze',
|
|
662
|
-
type: 'number',
|
|
663
|
-
})
|
|
664
|
-
.option('confidence', {
|
|
665
|
-
defaultDescription: '0.95',
|
|
666
|
-
description: 'Confidence level (0.5-0.999, default 0.95)',
|
|
667
|
-
type: 'number',
|
|
668
|
-
})
|
|
669
|
-
.example([
|
|
670
|
-
[
|
|
671
|
-
'$0 baseline analyze',
|
|
672
|
-
'Analyze last 10 runs with 95% confidence',
|
|
673
|
-
],
|
|
674
|
-
['$0 baseline analyze --runs 20', 'Analyze last 20 runs'],
|
|
675
|
-
[
|
|
676
|
-
'$0 baseline analyze --confidence 0.90',
|
|
677
|
-
'Use 90% confidence level',
|
|
678
|
-
],
|
|
679
|
-
]);
|
|
680
|
-
}, async (argv) => {
|
|
681
|
-
const context = await createCliContext(argv, abortController);
|
|
682
|
-
const exitCode = await (0, baseline_js_1.handleAnalyzeCommand)(context, {
|
|
683
|
-
confidence: argv.confidence,
|
|
684
|
-
cwd: argv.cwd,
|
|
685
|
-
quiet: Boolean(argv.quiet),
|
|
686
|
-
runs: argv.runs,
|
|
687
|
-
verbose: argv.verbose,
|
|
688
|
-
});
|
|
689
|
-
process.exit(exitCode);
|
|
690
|
-
})
|
|
691
|
-
.demandCommand(1, 'You must specify a baseline subcommand')
|
|
692
|
-
.strict()
|
|
693
|
-
.example([
|
|
694
|
-
['$0 baseline set production-v1.0', 'Save current run as baseline'],
|
|
695
|
-
['$0 baseline list', 'List all baselines'],
|
|
696
|
-
['$0 baseline show production-v1.0', 'Show baseline details'],
|
|
697
|
-
['$0 baseline delete old-baseline', 'Delete a baseline'],
|
|
698
|
-
['$0 baseline analyze', 'Suggest budgets from history'],
|
|
699
|
-
]);
|
|
700
|
-
})
|
|
701
|
-
.command('init [type]', 'Initialize a new benchmark project', (yargs) => {
|
|
702
|
-
return yargs
|
|
703
|
-
.positional('type', {
|
|
704
|
-
choices: ['basic', 'advanced', 'library'],
|
|
705
|
-
defaultDescription: 'basic',
|
|
706
|
-
describe: 'Type of project to initialize',
|
|
707
|
-
type: 'string',
|
|
708
|
-
})
|
|
709
|
-
.option('examples', {
|
|
710
|
-
defaultDescription: 'true',
|
|
711
|
-
description: 'Include example benchmark files',
|
|
712
|
-
type: 'boolean',
|
|
713
|
-
})
|
|
714
|
-
.option('config-type', {
|
|
715
|
-
choices: ['json', 'yaml', 'js', 'ts'],
|
|
716
|
-
defaultDescription: 'json',
|
|
717
|
-
description: 'Configuration file format',
|
|
718
|
-
type: 'string',
|
|
719
|
-
})
|
|
720
|
-
.option('force', {
|
|
721
|
-
defaultDescription: 'false',
|
|
722
|
-
description: 'Overwrite existing files',
|
|
723
|
-
type: 'boolean',
|
|
724
|
-
})
|
|
725
|
-
.option('yes', {
|
|
726
|
-
alias: 'y',
|
|
727
|
-
defaultDescription: 'false',
|
|
728
|
-
description: 'Accept all prompts automatically',
|
|
729
|
-
type: 'boolean',
|
|
730
|
-
})
|
|
731
|
-
.option('quiet', {
|
|
732
|
-
alias: 'q',
|
|
733
|
-
defaultDescription: 'false',
|
|
734
|
-
description: 'Minimal output',
|
|
735
|
-
type: 'boolean',
|
|
736
|
-
})
|
|
737
|
-
.example([
|
|
738
|
-
['$0 init', 'Initialize a basic project'],
|
|
739
|
-
[
|
|
740
|
-
'$0 init advanced --config-type ts',
|
|
741
|
-
'Initialize advanced project with TypeScript config',
|
|
742
|
-
],
|
|
743
|
-
[
|
|
744
|
-
'$0 init library --no-examples',
|
|
745
|
-
'Initialize library project without examples',
|
|
746
|
-
],
|
|
747
|
-
]);
|
|
748
|
-
}, async (argv) => {
|
|
749
|
-
const context = await createCliContext(argv, abortController);
|
|
750
|
-
const exitCode = await (0, init_js_1.handleInitCommand)(context, {
|
|
751
|
-
configType: argv['config-type'],
|
|
752
|
-
cwd: argv.cwd,
|
|
753
|
-
examples: argv.examples,
|
|
754
|
-
force: argv.force,
|
|
755
|
-
quiet: argv.quiet,
|
|
756
|
-
type: argv.type,
|
|
757
|
-
verbose: argv.verbose,
|
|
758
|
-
yes: argv.yes,
|
|
759
|
-
});
|
|
760
|
-
process.exitCode = exitCode;
|
|
761
|
-
})
|
|
762
|
-
.command(['analyze [command]', 'profile [command]'], 'Analyze code execution and identify benchmark candidates', (yargs) => {
|
|
763
|
-
return yargs
|
|
764
|
-
.positional('command', {
|
|
765
|
-
description: 'Command to analyze (e.g., "npm test")',
|
|
766
|
-
type: 'string',
|
|
767
|
-
})
|
|
768
|
-
.option('input', {
|
|
769
|
-
alias: 'i',
|
|
770
|
-
description: 'Path to existing *.cpuprofile file',
|
|
771
|
-
type: 'string',
|
|
772
|
-
})
|
|
773
|
-
.option('filter-file', {
|
|
774
|
-
description: 'Filter functions by file glob pattern',
|
|
775
|
-
type: 'string',
|
|
776
|
-
})
|
|
777
|
-
.option('min-percent', {
|
|
778
|
-
alias: ['m', 'min'],
|
|
779
|
-
default: 0.5,
|
|
780
|
-
description: 'Minimum execution percentage to show',
|
|
781
|
-
type: 'number',
|
|
782
|
-
})
|
|
783
|
-
.option('top', {
|
|
784
|
-
alias: 'n',
|
|
785
|
-
default: 25,
|
|
786
|
-
description: 'Number of top functions to show',
|
|
787
|
-
type: 'number',
|
|
788
|
-
})
|
|
789
|
-
.option('group-by-file', {
|
|
790
|
-
default: false,
|
|
791
|
-
description: 'Group results by file',
|
|
792
|
-
type: 'boolean',
|
|
793
|
-
})
|
|
794
|
-
.check((argv) => {
|
|
795
|
-
if (!argv.command && !argv.input) {
|
|
796
|
-
throw new Error('Either [command] or --input must be provided');
|
|
797
|
-
}
|
|
798
|
-
return true;
|
|
799
|
-
});
|
|
800
|
-
}, async (argv) => {
|
|
801
|
-
// Context not needed for analyze command currently
|
|
802
|
-
const context = {};
|
|
803
|
-
const options = {
|
|
804
|
-
color: !argv.noColor,
|
|
805
|
-
command: argv.command,
|
|
806
|
-
cwd: argv.cwd || process.cwd(),
|
|
807
|
-
filterFile: argv.filterFile,
|
|
808
|
-
groupByFile: argv.groupByFile,
|
|
809
|
-
input: argv.input,
|
|
810
|
-
minPercent: argv.minPercent,
|
|
811
|
-
top: argv.top,
|
|
812
|
-
};
|
|
813
|
-
process.exitCode = await (0, analyze_js_1.handleAnalyzeCommand)(context, options);
|
|
814
|
-
})
|
|
815
|
-
.command('test <framework> [files..]', 'Run test files as benchmarks (captures tests from Jest, Mocha, node:test, or AVA)', (yargs) => {
|
|
816
|
-
return yargs
|
|
817
|
-
.positional('framework', {
|
|
818
|
-
choices: ['ava', 'jest', 'mocha', 'node-test'],
|
|
819
|
-
demandOption: true,
|
|
820
|
-
describe: 'Test framework to use',
|
|
821
|
-
nargs: 1,
|
|
822
|
-
type: 'string',
|
|
823
|
-
})
|
|
824
|
-
.positional('files', {
|
|
825
|
-
array: true,
|
|
826
|
-
describe: 'Test file paths or glob patterns',
|
|
827
|
-
type: 'string',
|
|
828
|
-
})
|
|
829
|
-
.option('iterations', {
|
|
830
|
-
alias: 'i',
|
|
831
|
-
default: 100,
|
|
832
|
-
description: 'Number of iterations per test',
|
|
833
|
-
type: 'number',
|
|
834
|
-
})
|
|
835
|
-
.option('warmup', {
|
|
836
|
-
alias: 'w',
|
|
837
|
-
default: 5,
|
|
838
|
-
description: 'Number of warmup iterations',
|
|
839
|
-
type: 'number',
|
|
840
|
-
})
|
|
841
|
-
.option('bail', {
|
|
842
|
-
alias: 'b',
|
|
843
|
-
default: false,
|
|
844
|
-
description: 'Stop on first failure',
|
|
845
|
-
type: 'boolean',
|
|
846
|
-
})
|
|
847
|
-
.option('quiet', {
|
|
848
|
-
alias: 'q',
|
|
849
|
-
default: false,
|
|
850
|
-
description: 'Minimal output',
|
|
851
|
-
type: 'boolean',
|
|
852
|
-
})
|
|
853
|
-
.example([
|
|
854
|
-
['$0 test mocha test/*.spec.js', 'Run Mocha tests as benchmarks'],
|
|
855
|
-
[
|
|
856
|
-
'$0 test node-test test/*.test.js',
|
|
857
|
-
'Run node:test tests as benchmarks',
|
|
858
|
-
],
|
|
859
|
-
[
|
|
860
|
-
'$0 test ava test/*.js --iterations 500',
|
|
861
|
-
'Run AVA tests with 500 iterations',
|
|
862
|
-
],
|
|
863
|
-
[
|
|
864
|
-
'$0 test mocha test/unit.spec.js --json',
|
|
865
|
-
'Output results as JSON',
|
|
866
|
-
],
|
|
867
|
-
]);
|
|
868
|
-
}, async (argv) => {
|
|
869
|
-
const context = await createCliContext(argv, abortController);
|
|
870
|
-
const options = {
|
|
871
|
-
bail: argv.bail,
|
|
872
|
-
cwd: argv.cwd,
|
|
873
|
-
framework: argv.framework,
|
|
874
|
-
iterations: argv.iterations,
|
|
875
|
-
json: argv.json,
|
|
876
|
-
noColor: argv.noColor,
|
|
877
|
-
pattern: argv.files,
|
|
878
|
-
quiet: argv.quiet,
|
|
879
|
-
verbose: argv.verbose,
|
|
880
|
-
warmup: argv.warmup,
|
|
881
|
-
};
|
|
882
|
-
const exitCode = await (0, test_js_1.handleTestCommand)(context, options);
|
|
883
|
-
process.exit(exitCode);
|
|
884
|
-
})
|
|
885
|
-
.fail((msg, err, yargs) => {
|
|
886
|
-
if (err) {
|
|
887
|
-
console.error('Error:', err.message);
|
|
888
|
-
if (process.env.DEBUG) {
|
|
889
|
-
console.error(err.stack);
|
|
890
|
-
}
|
|
891
|
-
// Show help for file discovery errors (similar to usage errors)
|
|
892
|
-
if ((0, index_js_2.isModestBenchError)(err) &&
|
|
893
|
-
err.code === constants_js_1.ErrorCodes.FILE_DISCOVERY_FAILED) {
|
|
894
|
-
console.error();
|
|
895
|
-
yargs.showHelp();
|
|
896
|
-
process.exit(constants_js_1.ExitCodes.DISCOVERY_ERROR);
|
|
897
|
-
}
|
|
898
|
-
process.exit(constants_js_1.ExitCodes.RUNTIME_ERROR);
|
|
899
|
-
}
|
|
900
|
-
else {
|
|
901
|
-
// Show help for usage errors (unknown arguments, etc.)
|
|
902
|
-
console.error(msg);
|
|
903
|
-
console.error();
|
|
904
|
-
yargs.showHelp();
|
|
905
|
-
process.exit(constants_js_1.ExitCodes.CONFIG_ERROR);
|
|
906
|
-
}
|
|
907
|
-
})
|
|
908
|
-
.parse();
|
|
663
|
+
const cliBuilder = createCli(controller);
|
|
664
|
+
await cliBuilder.parseAsync(argv);
|
|
909
665
|
}
|
|
910
666
|
catch (error) {
|
|
667
|
+
// Handle bargs errors
|
|
668
|
+
if (error instanceof bargs_1.HelpError) {
|
|
669
|
+
// Help was requested or invalid args - message already printed
|
|
670
|
+
process.exit(constants_js_1.ExitCodes.CONFIG_ERROR);
|
|
671
|
+
}
|
|
672
|
+
if (error instanceof bargs_1.BargsError) {
|
|
673
|
+
console.error('Error:', error.message);
|
|
674
|
+
process.exit(constants_js_1.ExitCodes.CONFIG_ERROR);
|
|
675
|
+
}
|
|
676
|
+
// Handle bargs validation errors (thrown as plain Error, not BargsError)
|
|
677
|
+
if (error instanceof Error &&
|
|
678
|
+
(error.message.startsWith('Invalid value for --') ||
|
|
679
|
+
error.message.startsWith('Missing required'))) {
|
|
680
|
+
console.error('Error:', error.message);
|
|
681
|
+
process.exit(constants_js_1.ExitCodes.CONFIG_ERROR);
|
|
682
|
+
}
|
|
683
|
+
// Handle ModestBench errors
|
|
684
|
+
if ((0, index_js_2.isModestBenchError)(error)) {
|
|
685
|
+
console.error('Error:', error.message);
|
|
686
|
+
if (process.env.DEBUG) {
|
|
687
|
+
console.error(error.stack);
|
|
688
|
+
}
|
|
689
|
+
// Show help for file discovery errors
|
|
690
|
+
if (error.code === constants_js_1.ErrorCodes.FILE_DISCOVERY_FAILED) {
|
|
691
|
+
process.exit(constants_js_1.ExitCodes.DISCOVERY_ERROR);
|
|
692
|
+
}
|
|
693
|
+
process.exit(constants_js_1.ExitCodes.RUNTIME_ERROR);
|
|
694
|
+
}
|
|
695
|
+
// Unexpected error
|
|
911
696
|
console.error('Unexpected error:', error instanceof Error ? error.message : String(error));
|
|
912
697
|
if (process.env.DEBUG) {
|
|
913
698
|
console.error(error);
|
|
@@ -928,11 +713,11 @@ const createCliContext = async (options, abortController, engineType = constants
|
|
|
928
713
|
: new index_js_1.TinybenchEngine(dependencies);
|
|
929
714
|
// Register built-in reporters
|
|
930
715
|
engine.registerReporter(constants_js_1.Reporters.HUMAN, new index_js_3.HumanReporter({
|
|
931
|
-
color: !options
|
|
716
|
+
color: !options['no-color'],
|
|
932
717
|
verbose: options.verbose,
|
|
933
718
|
}));
|
|
934
719
|
engine.registerReporter('json', new index_js_3.JsonReporter({
|
|
935
|
-
prettyPrint:
|
|
720
|
+
prettyPrint: false,
|
|
936
721
|
}));
|
|
937
722
|
engine.registerReporter('csv', new index_js_3.CsvReporter({
|
|
938
723
|
includeHeaders: true,
|
|
@@ -942,7 +727,7 @@ const createCliContext = async (options, abortController, engineType = constants
|
|
|
942
727
|
verbose: options.verbose,
|
|
943
728
|
}));
|
|
944
729
|
engine.registerReporter('nyan', new index_js_3.NyanReporter({
|
|
945
|
-
color: !options
|
|
730
|
+
color: !options['no-color'],
|
|
946
731
|
}));
|
|
947
732
|
return {
|
|
948
733
|
abortController,
|