@@ -19,7 +19,7 @@ import { readConfig, writeConfig } from 'storybook/internal/csf-tools';
19
19
import { colors , logger } from 'storybook/internal/node-logger' ;
20
20
21
21
// eslint-disable-next-line depend/ban-dependencies
22
- import { $ } from 'execa' ;
22
+ import { execa } from 'execa' ;
23
23
import { findUp } from 'find-up' ;
24
24
import { dirname , extname , join , relative , resolve } from 'pathe' ;
25
25
import picocolors from 'picocolors' ;
@@ -330,41 +330,6 @@ export default async function postInstall(options: PostinstallOptions) {
330
330
`
331
331
) ;
332
332
333
- const a11yAddon = info . addons . find ( ( addon ) => addon . includes ( addonA11yName ) ) ;
334
-
335
- if ( a11yAddon ) {
336
- try {
337
- logger . plain ( `${ step } Setting up ${ addonA11yName } for @storybook/addon-vitest:` ) ;
338
- const command = [ 'storybook' , 'automigrate' , 'addonA11yAddonTest' ] ;
339
-
340
- if ( options . yes ) {
341
- command . push ( '--yes' ) ;
342
- }
343
-
344
- if ( options . packageManager ) {
345
- command . push ( '--package-manager' , options . packageManager ) ;
346
- }
347
-
348
- if ( options . configDir ) {
349
- command . push ( '--config-dir' , options . configDir ) ;
350
- }
351
-
352
- await $ ( {
353
- stdio : 'inherit' ,
354
- } ) `${ command . join ( ' ' ) } ` ;
355
- } catch ( e ) {
356
- printError (
357
- '🚨 Oh no!' ,
358
- dedent `
359
- We have detected that you have ${ addonA11yName } installed but could not automatically set it up for @storybook/addon-vitest.
360
-
361
- Please refer to the documentation to complete the setup manually:
362
- ${ picocolors . cyan ( `https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration` ) }
363
- `
364
- ) ;
365
- }
366
- }
367
-
368
333
const vitestWorkspaceFile = await findFile ( 'vitest.workspace' , [ '.ts' , '.js' , '.json' ] ) ;
369
334
const viteConfigFile = await findFile ( 'vite.config' ) ;
370
335
const vitestConfigFile = await findFile ( 'vitest.config' ) ;
@@ -505,6 +470,43 @@ export default async function postInstall(options: PostinstallOptions) {
505
470
await writeFile ( newConfigFile , formattedContent ) ;
506
471
}
507
472
473
+ const a11yAddon = info . addons . find ( ( addon ) => addon . includes ( addonA11yName ) ) ;
474
+
475
+ if ( a11yAddon ) {
476
+ try {
477
+ logger . plain ( `${ step } Setting up ${ addonA11yName } for @storybook/addon-vitest:` ) ;
478
+ const command = [ 'automigrate' , 'addonA11yAddonTest' ] ;
479
+
480
+ if ( options . yes ) {
481
+ command . push ( '--yes' ) ;
482
+ }
483
+
484
+ if ( options . packageManager ) {
485
+ command . push ( '--package-manager' , options . packageManager ) ;
486
+ }
487
+
488
+ if ( options . configDir !== '.storybook' ) {
489
+ command . push ( '--config-dir' , options . configDir ) ;
490
+ }
491
+
492
+ await execa ( 'storybook' , command , {
493
+ stdio : 'inherit' ,
494
+ } ) ;
495
+ } catch ( e : unknown ) {
496
+ printError (
497
+ '🚨 Oh no!' ,
498
+ dedent `
499
+ We have detected that you have ${ addonA11yName } installed but could not automatically set it up for @storybook/addon-vitest:
500
+
501
+ ${ e instanceof Error ? e . message : String ( e ) }
502
+
503
+ Please refer to the documentation to complete the setup manually:
504
+ ${ picocolors . cyan ( `https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration` ) }
505
+ `
506
+ ) ;
507
+ }
508
+ }
509
+
508
510
const runCommand = rootConfig ? `npx vitest --project=storybook` : `npx vitest` ;
509
511
510
512
printSuccess (
0 commit comments