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