@@ -119,24 +119,78 @@ function isSentryCliPackageSpec(token: string): boolean {
119119 return lower === "@sentry/cli" || lower . startsWith ( "@sentry/cli@" ) ;
120120}
121121
122+ function isSentryWizardPackageSpec ( token : string ) : boolean {
123+ const lower = token . toLowerCase ( ) ;
124+ return lower === "@sentry/wizard" || lower . startsWith ( "@sentry/wizard@" ) ;
125+ }
126+
122127function isExecutablePackageSpec ( executable : string , name : string ) : boolean {
123128 return executable === name || executable . startsWith ( `${ name } @` ) ;
124129}
125130
126- function isRecursiveSentrySetup ( tokens : string [ ] ) : boolean {
127- if ( tokens . some ( ( token ) => token . toLowerCase ( ) . includes ( "@sentry/wizard" ) ) ) {
128- return true ;
131+ function findFirstNonOptionIndex (
132+ tokens : string [ ] ,
133+ startIndex : number
134+ ) : number | undefined {
135+ for ( let index = startIndex ; index < tokens . length ; index += 1 ) {
136+ const token = tokens [ index ] ;
137+ if ( ! token ) {
138+ continue ;
139+ }
140+ if ( token === "--" ) {
141+ return index + 1 < tokens . length ? index + 1 : undefined ;
142+ }
143+ if ( token . startsWith ( "-" ) ) {
144+ continue ;
145+ }
146+ return index ;
129147 }
130148
149+ return ;
150+ }
151+
152+ function findPackageExecutionTokenIndex ( tokens : string [ ] ) : number | undefined {
153+ const firstExecutable = normalizeExecutableName ( tokens [ 0 ] ?? "" ) ;
154+ if (
155+ isExecutablePackageSpec ( firstExecutable , "npx" ) ||
156+ isExecutablePackageSpec ( firstExecutable , "bunx" )
157+ ) {
158+ return findFirstNonOptionIndex ( tokens , 1 ) ;
159+ }
160+
161+ const subcommandIndex = findFirstNonOptionIndex ( tokens , 1 ) ;
162+ if ( subcommandIndex === undefined ) {
163+ return ;
164+ }
165+
166+ const subcommand = normalizeExecutableName ( tokens [ subcommandIndex ] ?? "" ) ;
167+ if ( subcommand !== "exec" && subcommand !== "dlx" ) {
168+ return ;
169+ }
170+
171+ return findFirstNonOptionIndex ( tokens , subcommandIndex + 1 ) ;
172+ }
173+
174+ function canExecuteToken ( tokens : string [ ] , index : number ) : boolean {
175+ return index === 0 || index === findPackageExecutionTokenIndex ( tokens ) ;
176+ }
177+
178+ function isRecursiveSentrySetup ( tokens : string [ ] ) : boolean {
131179 return tokens . some ( ( token , index ) => {
132- if ( isSentryCliPackageSpec ( token ) ) {
133- return hasInitArgAfter ( tokens , index ) ;
180+ if ( ! canExecuteToken ( tokens , index ) ) {
181+ return false ;
134182 }
135183
136184 const executable = normalizeExecutableName ( token ) ;
137- if ( isExecutablePackageSpec ( executable , "sentry-wizard" ) ) {
185+ if (
186+ isSentryWizardPackageSpec ( token ) ||
187+ isExecutablePackageSpec ( executable , "sentry-wizard" )
188+ ) {
138189 return true ;
139190 }
191+ if ( isSentryCliPackageSpec ( token ) ) {
192+ return hasInitArgAfter ( tokens , index ) ;
193+ }
140194 if (
141195 ! (
142196 isExecutablePackageSpec ( executable , "sentry" ) ||
0 commit comments