Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
240 commits
Select commit Hold shift + click to select a range
8536401
add prompts abstraction
yannbf May 20, 2025
ad924e8
experiment with clack
yannbf May 20, 2025
a718ece
Encapsulate boxen usage in cli-storybook
yannbf May 20, 2025
745682d
cleanup
yannbf May 20, 2025
16531c5
cleanup
yannbf May 21, 2025
b7df284
fix types
yannbf May 21, 2025
7991203
use onCancel as a base option
yannbf May 22, 2025
50e1bd2
fix tests
yannbf May 22, 2025
6cee77a
try to fix test on windows
yannbf May 22, 2025
3a55010
fix
yannbf May 22, 2025
721aba0
Merge pull request #31521 from storybookjs/yann/prompts-abstraction
yannbf May 22, 2025
bd45265
detect multiple config dirs for the upgrade command
yannbf May 21, 2025
336c11f
updates
yannbf May 22, 2025
b9fe8b5
fix types
yannbf May 22, 2025
01c350d
remove unused code
yannbf May 22, 2025
6356cf3
further updates
yannbf May 22, 2025
c13b712
Core: Improve mono repo handling for JsPackageManager class and helpers
valentinpalkovic May 22, 2025
566b526
Fix Angular sandbox
valentinpalkovic May 22, 2025
4737b92
Remove unused import
valentinpalkovic May 22, 2025
6436065
Fix types
valentinpalkovic May 22, 2025
5595040
Smaller fixes
valentinpalkovic May 22, 2025
eac2647
Install at the end of automigrations
valentinpalkovic May 22, 2025
69b3764
Fix tests
valentinpalkovic May 22, 2025
ef8f4f2
Core: Use `projectRoot` consequently and limit `find-up` actions to t…
valentinpalkovic May 23, 2025
b3e5ca2
fix tests
yannbf May 23, 2025
852679e
Revert projectRoot usage to getProjectRoot
valentinpalkovic May 23, 2025
7edd821
Fix initialization in empty directory + improvements in init
valentinpalkovic May 23, 2025
034dbf6
Fix import and reference issues
valentinpalkovic May 23, 2025
4092bac
Fix tests
valentinpalkovic May 23, 2025
480594b
fix tests
yannbf May 23, 2025
7becd44
fix test init flow
yannbf May 23, 2025
1239c0f
Fix initialization in empty directory
valentinpalkovic May 23, 2025
4aa4cf1
Merge branch 'valentin/improve-monorepo-support-for-js-package-manage…
yannbf May 23, 2025
be484bf
Merge pull request #31553 from storybookjs/valentin/improve-monorepo-…
yannbf May 23, 2025
3021866
wip
yannbf May 24, 2025
59d6fb8
detect upgrade data per config dir
yannbf May 26, 2025
9059079
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic May 27, 2025
e29270b
Move helpers into util files
valentinpalkovic May 27, 2025
a4fb051
Move helpers into util files
valentinpalkovic May 27, 2025
4e3c111
Cleanup
valentinpalkovic May 27, 2025
7fe300f
Enhance compatibility checks by integrating JsPackageManager into war…
valentinpalkovic May 27, 2025
c0e1e66
Merge remote-tracking branch 'origin/next' into valentin/monorepo-enh…
valentinpalkovic May 27, 2025
70c7095
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic May 27, 2025
bb87272
Improve options interface for removing addons
valentinpalkovic May 27, 2025
142742a
Refactor upgrade function to use CollectProjectsSuccessResult type an…
valentinpalkovic May 27, 2025
4f266b2
add log methods
yannbf May 27, 2025
8b4b394
Centralize autoblockers
valentinpalkovic May 27, 2025
9d9dedf
Add error handling in upgrades
valentinpalkovic May 27, 2025
c75e93e
Fix type errors
valentinpalkovic May 27, 2025
8073cf7
Fix unit tests
valentinpalkovic May 27, 2025
37e1091
Fix init
valentinpalkovic May 27, 2025
4ce4625
Fix init
valentinpalkovic May 27, 2025
337c391
Merge pull request #31534 from storybookjs/yann/detect-multiple-confi…
yannbf May 27, 2025
dc5cde1
cleanup
yannbf May 27, 2025
88b9aac
CLI: Improve package manager execution and CLI logging
yannbf May 27, 2025
433e40f
use clack in more places
yannbf May 27, 2025
e0e28eb
Remove package.json as input for autoblockers
valentinpalkovic May 28, 2025
ebd87d1
install correct version of addon docs in automigrations
yannbf May 28, 2025
3c1c790
silence automigrations and skip doctor checks
yannbf May 28, 2025
e19ac2d
Refactor automigrations to scope their actions to a specific project
valentinpalkovic May 28, 2025
308ce03
fix test
yannbf May 28, 2025
18cab60
Merge branch 'valentin/monorepo-enhancements' into yann/silence-posti…
yannbf May 28, 2025
17d7065
fix tests
yannbf May 28, 2025
24465b6
Merge branch 'next' into valentin/monorepo-enhancements
yannbf May 28, 2025
22e9c8d
Fix tests
valentinpalkovic May 28, 2025
a0bb356
Fix tests
valentinpalkovic May 28, 2025
df54379
fix tests
yannbf May 28, 2025
aecf389
Merge pull request #31589 from storybookjs/yann/silence-postinstall-s…
yannbf May 28, 2025
fe8e0a3
remove testing limitation
yannbf May 28, 2025
bec3d72
Merge branch 'valentin/monorepo-enhancements' into yann/improve-logger
yannbf May 28, 2025
758a2da
refactor
yannbf May 28, 2025
60b23ae
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic May 30, 2025
6639cb5
Merge remote-tracking branch 'origin/next' into valentin/monorepo-enh…
valentinpalkovic May 30, 2025
ed23d23
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic May 30, 2025
1d5a99a
Centralize automigration check function run
valentinpalkovic May 30, 2025
0a4f572
Refactor autoblocker handling by centralizing logic in processAutoblo…
valentinpalkovic May 30, 2025
0456eec
add debug messages
valentinpalkovic May 30, 2025
26e13ec
add back optional prompts implementation
yannbf May 30, 2025
fc8ba49
Refactor story path handling by introducing getEvaluatedStoryPaths fu…
yannbf May 30, 2025
16ea496
Merge branch 'valentin/automigration-adjustments-for-monorepo-support…
yannbf May 30, 2025
8f9956a
Merge pull request #31588 from storybookjs/valentin/automigration-adj…
valentinpalkovic May 30, 2025
b48bd7b
improvements
yannbf May 30, 2025
cc9f393
install deps before running storybook doctor
yannbf May 30, 2025
c5da213
Merge branch 'valentin/monorepo-enhancements' into yann/improve-logger
yannbf May 30, 2025
5f2ee1d
Centralize doctor logic
valentinpalkovic May 30, 2025
170f3bf
Merge branch 'valentin/monorepo-enhancements' into yann/improve-logger
yannbf May 30, 2025
424878f
improvements
yannbf May 30, 2025
98c234a
introduce runInternalCommand function to jspackage manager
yannbf May 30, 2025
2c92b9b
make removeAddon fault tolerant
yannbf May 30, 2025
4372d63
filter out addons with invalid versions in the upgrade checks
yannbf May 30, 2025
fd6009e
optimize automigrate command (when run via sb automigrate)
yannbf May 30, 2025
69bd171
move fix
yannbf May 30, 2025
243f0aa
improve logging
yannbf May 30, 2025
d9c41cd
fix
yannbf May 30, 2025
b73a6e0
fix tests
yannbf May 30, 2025
d1a7ca9
improve logging and storybook doctor
yannbf Jun 1, 2025
9062515
add multi-upgrade telemetry
yannbf Jun 1, 2025
e460564
fix build
yannbf Jun 1, 2025
9e7dd0b
fix
yannbf Jun 1, 2025
f16af7c
remove circular dependency in prep script
yannbf Jun 1, 2025
5bed749
fix check
yannbf Jun 2, 2025
af5d58c
fix tests
yannbf Jun 2, 2025
a69535d
fix tests?
yannbf Jun 2, 2025
2f91023
Merge pull request #31583 from storybookjs/yann/improve-logger
yannbf Jun 2, 2025
3da5052
Revamp prompting and logging
yannbf Jun 2, 2025
006c107
fix tests
yannbf Jun 2, 2025
9111cd3
improve executeTasks
yannbf Jun 2, 2025
7a9ce31
Limit usage area of findup
valentinpalkovic Jun 2, 2025
b18b0cb
Don't ignore errors when installing dependencies
valentinpalkovic Jun 2, 2025
90be96a
Enhance logging capabilities with clack
valentinpalkovic Jun 2, 2025
7101d9d
Improve automigrations to support monorepos
valentinpalkovic Jun 2, 2025
a1d90bd
Improve prompting
valentinpalkovic Jun 2, 2025
494bc66
fix tests
yannbf Jun 2, 2025
864e040
Add test suite
valentinpalkovic Jun 2, 2025
aecae78
fix tests
yannbf Jun 2, 2025
f5c2ce8
Merge pull request #31641 from storybookjs/yann/logger-improvements
yannbf Jun 2, 2025
d4d13f2
Improve performance of JsPackageManagerFactory
valentinpalkovic Jun 2, 2025
2ebadd1
Merge branch 'next' into valentin/monorepo-enhancements
yannbf Jun 2, 2025
647f970
remove duplicated flag
yannbf Jun 2, 2025
c895f14
finalize telemetry changes
yannbf Jun 2, 2025
66805b6
streamline logging in node-logger
yannbf Jun 3, 2025
1e3ee7e
fix
yannbf Jun 3, 2025
da4d566
Enhance project collection by limiting concurrency and improving task…
valentinpalkovic Jun 3, 2025
d5aea37
fix
yannbf Jun 3, 2025
ab53807
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic Jun 3, 2025
0dceba4
Fix doctor after rebase
valentinpalkovic Jun 3, 2025
34091b6
remove .only
yannbf Jun 3, 2025
bbf71e3
fix types
yannbf Jun 3, 2025
6ace76c
fix types
yannbf Jun 3, 2025
959d55b
Merge branch 'valentin/monorepo-enhancements' into yann/use-logger-ev…
yannbf Jun 3, 2025
3d617f0
Truncate links and improve automigration selection logger
valentinpalkovic Jun 3, 2025
b4098ac
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic Jun 3, 2025
b4c7a96
augment tasklog and spinner to track logs
yannbf Jun 3, 2025
1478b6d
Further improvements
valentinpalkovic Jun 3, 2025
4257a54
Re-add tests
valentinpalkovic Jun 3, 2025
cb4d179
Further prompt improvements
valentinpalkovic Jun 3, 2025
58afbc6
fix
yannbf Jun 3, 2025
8c4786d
Update code/lib/cli-storybook/src/doctor/index.ts
yannbf Jun 3, 2025
2ee2478
fix eslint plugin configuration messages
yannbf Jun 3, 2025
c509d9a
Add caching to JsPackageManagerFactory
valentinpalkovic Jun 3, 2025
7d99086
respect yes flag to multi-project upgrade
yannbf Jun 3, 2025
a624504
use loglevel instead of log-level
yannbf Jun 3, 2025
995b8f3
Merge branch 'valentin/monorepo-enhancements' into yann/use-logger-ev…
valentinpalkovic Jun 3, 2025
0cb9ff4
Fix upgradeStorybookDependencies to apply changes to the right packag…
valentinpalkovic Jun 3, 2025
9640ccc
Refactor JsPackageManager to improve dependency removal logic and enh…
valentinpalkovic Jun 3, 2025
cd98778
Improve logging experience for autoblockers and additional optimizations
valentinpalkovic Jun 3, 2025
544f249
Rename id of addon-a11y-addon-test automigration
valentinpalkovic Jun 3, 2025
128c6bd
Update automigration command for addon-a11y-addon-test and enhance pa…
valentinpalkovic Jun 3, 2025
8a5431b
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic Jun 3, 2025
aa1d345
fix
yannbf Jun 3, 2025
2d3f3ca
Merge branch 'yann/use-logger-everywhere' of github.com:storybookjs/s…
yannbf Jun 3, 2025
6edb7a3
fix lint
yannbf Jun 3, 2025
3d31dd0
fixes
yannbf Jun 3, 2025
cc78198
fixes
yannbf Jun 3, 2025
cb665e2
Merge pull request #31653 from storybookjs/yann/use-logger-everywhere
yannbf Jun 4, 2025
7eb0c2a
Use glob instead of globby
valentinpalkovic Jun 4, 2025
ad3bfd5
Merge remote-tracking branch 'origin/valentin/monorepo-enhancements' …
valentinpalkovic Jun 4, 2025
a0bb0b5
unify loglevel on other cli commands too
yannbf Jun 4, 2025
9a61700
Fix tests
valentinpalkovic Jun 4, 2025
f4994f5
Fix tests
valentinpalkovic Jun 4, 2025
4d6db26
Fix tests
valentinpalkovic Jun 4, 2025
1bf6358
Merge pull request #31642 from storybookjs/valentin/improvements
valentinpalkovic Jun 4, 2025
043366b
Support cjs main.js in wrap-require automigration
valentinpalkovic Jun 4, 2025
ff4793b
make sure log files are still written when user cancels step
yannbf Jun 4, 2025
52f3162
Use standardized wrapAnsi options
valentinpalkovic Jun 4, 2025
4797ca9
Merge branch 'next' into valentin/monorepo-enhancements
yannbf Jun 4, 2025
d842a94
fix tests on windows
yannbf Jun 4, 2025
eb20aa0
fix loglevel and other things
yannbf Jun 4, 2025
996d728
Remove version ranges from automigrations
valentinpalkovic Jun 4, 2025
9b8dda7
Smaller fix
valentinpalkovic Jun 4, 2025
db963c6
Limit renaming of rnstorybook-config automigration to selected project
valentinpalkovic Jun 4, 2025
e8db0f3
Add support for terminal hyperlinks and improve text wrapping logic
valentinpalkovic Jun 4, 2025
81504ca
Refactor upgradeStorybookDependencies to avoid race condition
valentinpalkovic Jun 4, 2025
12649a8
Reduce colorization of output
valentinpalkovic Jun 4, 2025
460c6ef
Refactor import handling in automigration fixes to use config directory
valentinpalkovic Jun 4, 2025
d8065b5
Fix tests
valentinpalkovic Jun 5, 2025
156d3b8
fixes
yannbf Jun 5, 2025
07a0118
Logging improvements
valentinpalkovic Jun 5, 2025
f5d38c4
Performance improvements
valentinpalkovic Jun 5, 2025
dc6341d
Removed colors
valentinpalkovic Jun 5, 2025
a8faca8
Refactor JsPackageManager methods to static and improve command execu…
valentinpalkovic Jun 5, 2025
0a661d4
Add more specific logs
valentinpalkovic Jun 5, 2025
a6b3edf
Fix conditional check
valentinpalkovic Jun 5, 2025
7de935e
Refactor addDependencies method to support dependency types and updat…
valentinpalkovic Jun 5, 2025
7fc1842
Improve messaging
valentinpalkovic Jun 5, 2025
7cd979e
improve automigration checks error handling
yannbf Jun 5, 2025
2d37bea
Enhance automigration reporting and streamline success/failure detection
valentinpalkovic Jun 6, 2025
2557104
improvements and fixes
yannbf Jun 6, 2025
0b352d1
Fix telemetry
valentinpalkovic Jun 6, 2025
ff10eaf
fix more issues
yannbf Jun 6, 2025
58b1121
Fix multi-project tests
valentinpalkovic Jun 6, 2025
618c4cd
Fix JsPackageManager tests
valentinpalkovic Jun 6, 2025
3efcbef
fixes
yannbf Jun 6, 2025
a10ef95
fix sandboxes
yannbf Jun 6, 2025
4dcb63e
Merge branch 'next' into valentin/monorepo-enhancements
yannbf Jun 6, 2025
882b84b
fix automigration count
yannbf Jun 6, 2025
c3194b8
Fix JsPackageManager tests
valentinpalkovic Jun 6, 2025
6b8b7cf
Remove deduping during upgrade
valentinpalkovic Jun 6, 2025
609c51f
use logger.debug instead of warn
valentinpalkovic Jun 6, 2025
b801b3c
Update JsPackageManager to cache null for failed version retrieval an…
valentinpalkovic Jun 6, 2025
2069a95
Redirect messages to current tasklog
valentinpalkovic Jun 6, 2025
ea7487d
Improve logging
valentinpalkovic Jun 6, 2025
95e80f4
Run wrap-require auto migration to the end because it tends to influe…
valentinpalkovic Jun 6, 2025
1694432
Refactor logging in various modules to enhance clarity and consistenc…
valentinpalkovic Jun 6, 2025
186a3a9
Merge remote-tracking branch 'origin/next' into valentin/monorepo-enh…
valentinpalkovic Jun 6, 2025
c02c7ad
Improve blocker logging
valentinpalkovic Jun 6, 2025
1fc0b2b
Improve logging of upgrade
valentinpalkovic Jun 6, 2025
bf99e97
check for addon docs in package.json and not installations
yannbf Jun 10, 2025
a19ae9c
show automigration links at the end of upgrade
yannbf Jun 10, 2025
a8652b1
do not exit with process on blockers
yannbf Jun 10, 2025
656b7a3
more updates
yannbf Jun 10, 2025
ebb4eeb
small flake fix
yannbf Jun 10, 2025
1b1be45
Merge pull request #31717 from storybookjs/yann/more-fixes
yannbf Jun 10, 2025
7a7067f
Refactor logging in processProject function to remove timing logs for…
valentinpalkovic Jun 10, 2025
db2c2f3
Improve autoblocker logging
valentinpalkovic Jun 10, 2025
bfd7f47
Refactor and enhance logging in upgrade process, removing deprecated …
valentinpalkovic Jun 10, 2025
e318cfa
Update compatibility warning message format in getIncompatiblePackage…
valentinpalkovic Jun 10, 2025
b888361
Update diagnostic message format in getDoctorDiagnostics for improved…
valentinpalkovic Jun 10, 2025
0ef885d
Refactor automigration links logging in upgrade process for improved …
valentinpalkovic Jun 10, 2025
d80423e
Rename cli-color property
valentinpalkovic Jun 10, 2025
dfff64d
Add hyperlinks to automigrations
valentinpalkovic Jun 10, 2025
dadba8e
fix flake
yannbf Jun 10, 2025
fffaddd
fix tests
yannbf Jun 10, 2025
4516861
add dedupe step
yannbf Jun 10, 2025
931cc54
debug flake
yannbf Jun 10, 2025
130ddb9
simplify and fix version range specifier for add command
valentinpalkovic Jun 10, 2025
f8ae18d
Remove performance metrics
valentinpalkovic Jun 10, 2025
7d8b72d
fix tests
yannbf Jun 10, 2025
039331f
augment logs
yannbf Jun 10, 2025
b1eb45f
Merge branch 'valentin/monorepo-enhancements' of github.com:storybook…
yannbf Jun 10, 2025
435676b
more debugging
yannbf Jun 10, 2025
11e8f9a
Merge remote-tracking branch 'origin/next' into valentin/monorepo-enh…
valentinpalkovic Jun 10, 2025
0664aea
Fix smaller issues
valentinpalkovic Jun 10, 2025
7e132cb
skip savestory tests
yannbf Jun 10, 2025
c3d9912
Remove console.logs
valentinpalkovic Jun 10, 2025
d6f8b09
skip more tests
yannbf Jun 10, 2025
df702a3
remove obsolete snapshots
yannbf Jun 10, 2025
8ec5f60
skip other tests
yannbf Jun 10, 2025
dbd6a74
allow varags in logger functions
yannbf Jun 10, 2025
a944b96
Merge branch 'next' into valentin/monorepo-enhancements
yannbf Jun 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"mcpServers": {
"wallaby": {
"command": "node",
"args": [
"~/.wallaby/mcp/"
]
}
}
}
50 changes: 50 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Test Configuration

This Storybook repository uses Vitest as the test runner. Here are the key commands and configuration:

### Test Scripts

- `yarn test` - Run all tests (from root directory, delegates to `cd code; yarn test`)
- `yarn test <test-name>` - Run focused tests matching the pattern
- `yarn test:watch` - Run tests in watch mode
- `yarn test:watch <test-name>` - Run focused tests in watch mode

### Test Directory Structure

- Tests are located in the `code/` directory
- Vitest configuration is in `code/vitest.workspace.ts`
- Test files typically follow the pattern `*.test.ts`, `*.test.tsx`, `*.spec.ts`, or `*.spec.tsx`

### Running Tests in Cursor

1. Use Cmd+Shift+P (or Ctrl+Shift+P) and search for "Tasks: Run Task"
2. Select from the available test tasks:
- "Run All Tests" - Runs all tests
- "Run Test (Watch Mode)" - Runs tests in watch mode
- "Run Focused Test" - Prompts for test name/pattern to run specific tests
- "Run Focused Test (Watch Mode)" - Runs specific tests in watch mode

### Vitest Configuration

- Workspace configuration: `./code/vitest.workspace.ts`
- Command line: `yarn --cwd code test`
- Root directory for tests: `./code/`

### Test Execution Context

- Tests run from the `code/` directory
- Use `NODE_OPTIONS=--max_old_space_size=4096` for memory optimization
- Supports both watch mode and single-run execution

### Focused Test Patterns

When running focused tests, you can use:

- File names: `Button.test.ts`
- Test descriptions: `"should render correctly"`
- Directory patterns: `components/`
- Vitest patterns: `-t "pattern"` for test name matching

### Test Mocking Rules

Follow the spy mocking rules defined in `.cursor/rules/spy-mocking.mdc` for consistent mocking patterns with Vitest.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"typescript.preferences.quoteStyle": "single",
"typescript.preferGoToSourceDefinition": true,
"typescript.tsdk": "./code/node_modules/typescript/lib",
"vitest.workspaceConfig": "./code/vitest.workspace.ts"
"vitest.workspaceConfig": "./code/vitest.workspace.ts",
"vitest.rootConfig": "./code/vitest.workspace.ts",
}
5 changes: 5 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [Vitest Addon (former @storybook/experimental-addon-test): Vitest 2.0 support is dropped](#vitest-addon-former-storybookexperimental-addon-test-vitest-20-support-is-dropped)
- [Viewport/Backgrounds Addon synchronized configuration and `globals` usage](#viewportbackgrounds-addon-synchronized-configuration-and-globals-usage)
- [Storysource Addon removed](#storysource-addon-removed)
- [Mdx-gfm Addon removed](#mdx-gfm-addon-removed)
- [API and Component Changes](#api-and-component-changes)
- [Button Component API Changes](#button-component-api-changes)
- [Icon System Updates](#icon-system-updates)
Expand Down Expand Up @@ -726,6 +727,10 @@ See here for the ways you have to configure addon viewports & backgrounds:

The `@storybook/addon-storysource` addon and the `@storybook/source-loader` package are removed in Storybook 9.0. Instead, Storybook now provides a Code Panel via `@storybook/addon-docs` that offers similar functionality with improved integration and performance.

#### Mdx-gfm Addon removed

The `@storybook/addon-mdx-gfm` addon is removed in Storybook 9.0 since it is no longer needed.

**Migration Steps:**

1. Remove the old addon
Expand Down
5 changes: 4 additions & 1 deletion code/addons/a11y/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const $ = execa({
});

export default async function postinstall(options: PostinstallOptions) {
const command = ['storybook', 'automigrate', 'addonA11yAddonTest'];
const command = ['storybook', 'automigrate', 'addon-a11y-addon-test'];

command.push('--loglevel', 'silent');
command.push('--skip-doctor');

if (options.yes) {
command.push('--yes');
Expand Down
13 changes: 8 additions & 5 deletions code/addons/vitest/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
WorkspaceProject,
} from 'vitest/node';

import { resolvePathInStorybookCache } from 'storybook/internal/common';
import { getProjectRoot, resolvePathInStorybookCache } from 'storybook/internal/common';
import type { StoryId, StoryIndex, StoryIndexEntry } from 'storybook/internal/types';

import { findUp } from 'find-up';
Expand Down Expand Up @@ -65,10 +65,13 @@ export class VitestManager {
: { enabled: false }
) as CoverageOptions;

const vitestWorkspaceConfig = await findUp([
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`),
]);
const vitestWorkspaceConfig = await findUp(
[
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`),
],
{ stopAt: getProjectRoot() }
);

const projectName = 'storybook:' + process.env.STORYBOOK_CONFIG_DIR;

Expand Down
6 changes: 3 additions & 3 deletions code/addons/vitest/src/postinstall-logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { colors, logger } from 'storybook/internal/node-logger';

import boxen, { type Options } from 'boxen';

const fancy =
process.platform !== 'win32' || process.env.CI || process.env.TERM === 'xterm-256color';

Expand All @@ -11,14 +9,16 @@ export const success = colors.green(fancy ? '✔' : '√');
export const warning = colors.orange(fancy ? '⚠' : '‼');
export const error = colors.red(fancy ? '✖' : '×');

type Options = Parameters<typeof logger.logBox>[1];

const baseOptions: Options = {
borderStyle: 'round',
padding: 1,
};

export const print = (message: string, options: Options) => {
logger.line(1);
logger.plain(boxen(message, { ...baseOptions, ...options }));
logger.logBox(message, { ...baseOptions, ...options });
};

export const printInfo = (title: string, message: string, options?: Options) =>
Expand Down
53 changes: 23 additions & 30 deletions code/addons/vitest/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
JsPackageManagerFactory,
extractProperFrameworkName,
formatFileContent,
getProjectRoot,
loadAllPresets,
loadMainConfig,
scanAndTransformFiles,
Expand Down Expand Up @@ -39,7 +40,10 @@ const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.cts', '.mts', '.cjs', '.mjs'
const addonA11yName = '@storybook/addon-a11y';

const findFile = async (basename: string, extensions = EXTENSIONS) =>
findUp(extensions.map((ext) => basename + ext));
findUp(
extensions.map((ext) => basename + ext),
{ stopAt: getProjectRoot() }
);

export default async function postInstall(options: PostinstallOptions) {
printSuccess(
Expand All @@ -56,13 +60,11 @@ export default async function postInstall(options: PostinstallOptions) {
});

const info = await getStorybookInfo(options);
const allDeps = await packageManager.getAllDependencies();
const allDeps = packageManager.getAllDependencies();
// only install these dependencies if they are not already installed
const dependencies = ['vitest', '@vitest/browser', 'playwright'].filter((p) => !allDeps[p]);
const vitestVersionSpecifier = await packageManager.getInstalledVersion('vitest');
const coercedVitestVersion = vitestVersionSpecifier ? coerce(vitestVersionSpecifier) : null;
// if Vitest is installed, we use the same version to keep consistency across Vitest packages
const vitestVersionToInstall = vitestVersionSpecifier ?? 'latest';

const mainJsPath = serverResolve(resolve(options.configDir, 'main')) as string;
const config = await readConfig(mainJsPath);
Expand All @@ -88,16 +90,11 @@ export default async function postInstall(options: PostinstallOptions) {
});

if (out.migrateToNextjsVite) {
await packageManager.addDependencies(
{
installAsDevDependencies: true,
skipInstall: options.skipInstall,
packageJson: await packageManager.readPackageJson(),
},
[`@storybook/nextjs-vite@${versions['@storybook/nextjs-vite']}`]
);
await packageManager.addDependencies({ type: 'devDependencies', skipInstall: true }, [
'@storybook/nextjs-vite',
]);

await packageManager.removeDependencies({}, ['@storybook/nextjs']);
await packageManager.removeDependencies(['@storybook/nextjs']);

traverse(config._ast, {
StringLiteral(path) {
Expand Down Expand Up @@ -260,27 +257,24 @@ export default async function postInstall(options: PostinstallOptions) {

const versionedDependencies = dependencies.map((p) => {
if (p.includes('vitest')) {
return `${p}@${vitestVersionToInstall ?? 'latest'}`;
return vitestVersionSpecifier ? `${p}@${vitestVersionSpecifier}` : p;
}

return p;
});

if (versionedDependencies.length > 0) {
logger.line(1);
logger.plain(`${step} Installing dependencies:`);
logger.plain(colors.gray(' ' + versionedDependencies.join(', ')));

await packageManager.addDependencies(
{
installAsDevDependencies: true,
skipInstall: options.skipInstall,
packageJson: await packageManager.readPackageJson(),
},
{ type: 'devDependencies', skipInstall: true },
versionedDependencies
);
logger.line(1);
logger.plain(`${step} Installing dependencies:`);
logger.plain(colors.gray(' ' + versionedDependencies.join(', ')));
}

await packageManager.installDependencies();

logger.line(1);

if (options.skipInstall) {
Expand Down Expand Up @@ -489,11 +483,10 @@ export default async function postInstall(options: PostinstallOptions) {
if (a11yAddon) {
try {
logger.plain(`${step} Setting up ${addonA11yName} for @storybook/addon-vitest:`);
const command = ['automigrate', 'addonA11yAddonTest'];
const command = ['automigrate', 'addon-a11y-addon-test'];

if (options.yes) {
command.push('--yes');
}
command.push('--loglevel', 'silent');
command.push('--yes', '--skip-doctor');

if (options.packageManager) {
command.push('--package-manager', options.packageManager);
Expand Down Expand Up @@ -544,8 +537,8 @@ export default async function postInstall(options: PostinstallOptions) {
}

async function getStorybookInfo({ configDir, packageManager: pkgMgr }: PostinstallOptions) {
const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr });
const packageJson = await packageManager.retrievePackageJson();
const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr, configDir });
const { packageJson } = packageManager.primaryPackageJson;

const config = await loadMainConfig({ configDir, noCache: true });
const { framework } = config;
Expand All @@ -559,8 +552,8 @@ async function getStorybookInfo({ configDir, packageManager: pkgMgr }: Postinsta
overridePresets: [
require.resolve('storybook/internal/core-server/presets/common-override-preset'),
],
configDir,
packageJson,
configDir,
isCritical: true,
});

Expand Down
21 changes: 13 additions & 8 deletions code/addons/vitest/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ const getStoryGlobsAndFiles = async (
directories: { configDir: string; workingDir: string }
) => {
const stories = await presets.apply('stories', []);
const docs = await presets.apply('docs', {});
const indexers = await presets.apply('experimental_indexers', []);
const generator = new StoryIndexGenerator(normalizeStories(stories, directories), {
...directories,
indexers,
docs,

const normalizedStories = normalizeStories(stories, {
configDir: directories.configDir,
workingDir: directories.workingDir,
});
await generator.initialize();

const matchingStoryFiles = await StoryIndexGenerator.findMatchingFilesForSpecifiers(
normalizedStories,
directories.workingDir
);

return {
storiesGlobs: stories,
storiesFiles: generator.storyFileNames(),
storiesFiles: StoryIndexGenerator.storyFileNames(
new Map(matchingStoryFiles.map(([specifier, cache]) => [specifier, cache]))
),
};
};

Expand Down
6 changes: 4 additions & 2 deletions code/addons/vitest/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
globals: {
sb_theme: 'light',
},
tags: ['!vitest'],
};

export const Validation = {
Expand Down Expand Up @@ -45,8 +46,9 @@ export const Step = {
};

export const TypeAndClear = {
play: async ({ canvasElement, userEvent }) => {
const canvas = within(canvasElement);
play: async ({ canvas, userEvent }) => {
await userEvent.clear(canvas.getByTestId('value'));

await userEvent.type(canvas.getByTestId('value'), 'initial value');
await userEvent.clear(canvas.getByTestId('value'));
await userEvent.type(canvas.getByTestId('value'), 'final value');
Expand Down
1 change: 1 addition & 0 deletions code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@
"@babel/parser": "^7.26.9",
"@babel/traverse": "^7.26.9",
"@babel/types": "^7.26.8",
"@clack/prompts": "^1.0.0-alpha.0",
"@devtools-ds/object-inspector": "^1.1.2",
"@discoveryjs/json-ext": "^0.5.3",
"@emotion/cache": "^11.14.0",
Expand Down
33 changes: 31 additions & 2 deletions code/core/scripts/helpers/sourcefiles.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import { existsSync } from 'node:fs';
import { readdir, writeFile } from 'node:fs/promises';
import { mkdirSync } from 'node:fs';
import { readdir, realpath, writeFile } from 'node:fs/promises';
import os from 'node:os';
import { join } from 'node:path';

import { GlobalRegistrator } from '@happy-dom/global-registrator';
import { isNotNil } from 'es-toolkit';
import uniqueString from 'unique-string';

import { dedent, esbuild, getWorkspace, prettier } from '../../../../scripts/prepare/tools';
import { temporaryFile } from '../../src/common/utils/cli';
import {
BROWSER_TARGETS,
SUPPORTED_FEATURES,
} from '../../src/shared/constants/environments-support';

GlobalRegistrator.register({ url: 'http://localhost:3000', width: 1920, height: 1080 });

const tempDir = () => realpath(os.tmpdir());
const getPath = async (prefix = '') => join(await tempDir(), prefix + uniqueString());

export async function temporaryDirectory({ prefix = '' } = {}) {
const directory = await getPath(prefix);
mkdirSync(directory);
return directory;
}
export async function temporaryFile({
name,
extension,
}: { name?: string; extension?: string } = {}) {
if (name) {
if (extension !== undefined && extension !== null) {
// eslint-disable-next-line local-rules/no-uncategorized-errors
throw new Error('The `name` and `extension` options are mutually exclusive');
}

return join(await temporaryDirectory(), name);
}

return (
(await getPath()) +
(extension === undefined || extension === null ? '' : '.' + extension.replace(/^\./, ''))
);
}

// read code/frameworks subfolders and generate a list of available frameworks
// save this list into ./code/core/src/types/frameworks.ts and export it as a union type.
// The name of the type is `SupportedFrameworks`. Add additionally 'qwik' and `solid` to that list.
Expand Down
7 changes: 3 additions & 4 deletions code/core/src/cli/NpmOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export type NpmOptions = {
skipInstall?: boolean;
installAsDevDependencies?: boolean;
};
import type { JsPackageManager } from '../common/js-package-manager/JsPackageManager';

export type NpmOptions = Parameters<JsPackageManager['addDependencies']>[0];
Loading
Loading