@@ -18,25 +18,35 @@ export async function handler(argv: MeasureArgs): Promise<void> {
1818 [ 'flag-main' ] : flagMain2 ,
1919 ...commandOptions
2020 } = options ;
21+
22+ // Determine the actual command to profile
23+ const cmdToRun = // Case 1: Explicit 'measure' command is used.
24+ // Example: `cpu-prof measure npm -v`
25+ // Here, `commandToProfile` will be `['npm', '-v']`.
26+ (
27+ commandToProfile && commandToProfile . length > 0
28+ ? commandToProfile
29+ : // Case 2: Default command ('*') is used (i.e., 'measure' is not explicitly typed).
30+ // Example: `cpu-prof npm -v`
31+ // Here, `positionalArgs` (argv._) will be `['npm', '-v']`.
32+ positionalArgs
33+ ) as string [ ] ;
34+
2135 const nodeOptions = {
2236 ...( cpuProfDir ? { cpuProfDir } : { } ) ,
2337 ...( cpuProfInterval ? { cpuProfInterval } : { } ) ,
2438 ...( cpuProfName ? { cpuProfName } : { } ) ,
2539 ...( flagMain ? { flagMain } : { } ) ,
2640 } ;
2741
28- if (
29- ! commandToProfile ||
30- ! Array . isArray ( commandToProfile ) ||
31- commandToProfile . length === 0
32- ) {
42+ if ( ! cmdToRun || ! Array . isArray ( cmdToRun ) || cmdToRun . length === 0 ) {
3343 console . error (
34- '❌ Error: No command or script provided to profile. Usage: cpu- measure <command_or_script.js> [args...]'
44+ '❌ Error: No command or script provided to profile. Usage: measure <command_or_script.js> [args...]'
3545 ) ;
3646 process . exit ( 1 ) ;
3747 }
3848
39- const [ actualCommand , ...actualCommandArgs ] = commandToProfile ;
49+ const [ actualCommand , ...actualCommandArgs ] = cmdToRun ;
4050
4151 // Filter commandOptions to prefer kebab-case and remove duplicate camelCase keys
4252 const filteredCommandOptions = filterCliOptions ( commandOptions ) ;
0 commit comments