-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Vite: Improve handling of preview annotations #28798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
a724e02
Vite: improve handling of preview annotations
tobiasdiez 74be16e
use absolute paths in tests
tobiasdiez e625e78
update comment
tobiasdiez 71c7c57
use star imports for loading previews
tobiasdiez cdfe782
Merge remote-tracking branch 'upstream/next' into previewAnno
tobiasdiez 869d9e1
Merge branch 'next' into previewAnno
tobiasdiez f33697e
move preview variable declaration
tobiasdiez 52c56a5
Merge branch 'previewAnno' of https://github.com/tobiasdiez/storybook…
tobiasdiez d873110
Merge branch 'next' into previewAnno
tobiasdiez 7d1b3f0
update lock file
tobiasdiez 1038c75
Merge branch 'next' into previewAnno
ndelangen eddb6cd
fixes
ndelangen d0c7fb5
fixes
ndelangen 1e98912
fix incorrect import
ndelangen a404e3a
Merge remote-tracking branch 'upstream/next' into previewAnno
tobiasdiez aef9463
fix imports
tobiasdiez 83c947a
linting
ndelangen 9cd753e
Merge branch 'next' into previewAnno
ndelangen be2e4c8
Merge branch 'next' into previewAnno
tobiasdiez 27153b2
Merge branch 'next' into previewAnno
tobiasdiez 941324f
Merge branch 'next' into previewAnno
tobiasdiez 9391e2a
Merge branch 'next' into previewAnno
tobiasdiez 3f4900b
Merge remote-tracking branch 'upstream/next' into previewAnno
tobiasdiez 3235249
fix tests
tobiasdiez 4ad25a5
optimze semver
tobiasdiez 300f6f4
Merge branch 'optimize-dep' into previewAnno
tobiasdiez 531b527
move slsah back to dev dep
tobiasdiez 3349a93
Merge branch 'next' into previewAnno
tobiasdiez 502248b
fix tests
tobiasdiez 5680d8d
Merge remote-tracking branch 'origin/next' into fork/tobiasdiez/previ…
kasperpeulen f5af3eb
Use inline snapshots
kasperpeulen 48f2b8d
Fix eslint
kasperpeulen d411b19
Fix timing issue
kasperpeulen d43c165
Merge remote-tracking branch 'origin/next' into fork/tobiasdiez/previ…
kasperpeulen f8fdac1
Update snapshots
kasperpeulen 90411b1
Merge branch 'next' into previewAnno
tobiasdiez cc21e5f
Fix import
tobiasdiez 00ecf1c
Merge remote-tracking branch 'upstream/next' into previewAnno
tobiasdiez 70dbdfd
Merge branch 'next' into previewAnno
tobiasdiez 7572f4c
Merge branch 'next' into previewAnno
kasperpeulen ba7be49
Merge branch 'next' into previewAnno
tobiasdiez 984cb72
Merge branch 'next' into previewAnno
shilman 55320fd
Merge remote-tracking branch 'origin/next' into fork/tobiasdiez/previ…
kasperpeulen 7fffb34
Adjust for CSF4 support
kasperpeulen 31be6af
Merge branch 'next' into previewAnno
kasperpeulen 7af3ed4
Improve CSF4 logic and add tests
kasperpeulen f728faa
Merge remote-tracking branch 'tobiasdiez/previewAnno' into fork/tobia…
kasperpeulen 0fda7fc
Fix
kasperpeulen bacd25f
Fix
kasperpeulen 70d3ce2
Update snapshots
kasperpeulen c4e4eca
Rollback bs
kasperpeulen c38f8e8
Support Nuxt workaround
kasperpeulen 78e6c4c
Add react-dom/test-utils to optimize deps
kasperpeulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
code/builders/builder-vite/src/__snapshots__/codegen-modern-iframe-script.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`generateModernIframeScriptCodeFromPreviews > handle multiple annotations 1`] = ` | ||
| "import { composeConfigs, PreviewWeb, ClientApi } from 'storybook/internal/preview-api'; | ||
| import '/virtual:/@storybook/builder-vite/setup-addons.js'; | ||
| import { importFn } from '/virtual:/@storybook/builder-vite/storybook-stories.js'; | ||
| import previewAnnotations1_2032 from "/previewAnnotations1"; | ||
| import previewAnnotations2_2033 from "/previewAnnotations2"; | ||
| const getProjectAnnotations = (hmrPreviewAnnotationModules = []) => { | ||
| const configs = [ | ||
| hmrPreviewAnnotationModules.at(0) ?? previewAnnotations1_2032, | ||
| hmrPreviewAnnotationModules.at(1) ?? previewAnnotations2_2033 | ||
| ] | ||
| return composeConfigs(configs); | ||
| } | ||
|
|
||
| window.__STORYBOOK_PREVIEW__ = window.__STORYBOOK_PREVIEW__ || new PreviewWeb(importFn, getProjectAnnotations); | ||
|
|
||
| window.__STORYBOOK_STORY_STORE__ = window.__STORYBOOK_STORY_STORE__ || window.__STORYBOOK_PREVIEW__.storyStore; | ||
|
|
||
| if (import.meta.hot) { | ||
| import.meta.hot.accept('/virtual:/@storybook/builder-vite/storybook-stories.js', (newModule) => { | ||
| // importFn has changed so we need to patch the new one in | ||
| window.__STORYBOOK_PREVIEW__.onStoriesChanged({ importFn: newModule.importFn }); | ||
| }); | ||
|
|
||
| import.meta.hot.accept(["/previewAnnotations1","/previewAnnotations2"], (previewAnnotationModules) => { | ||
| // getProjectAnnotations has changed so we need to patch the new one in | ||
| window.__STORYBOOK_PREVIEW__.onGetProjectAnnotationsChanged({ getProjectAnnotations: () => getProjectAnnotations(previewAnnotationModules) }); | ||
| }); | ||
| };" | ||
| `; | ||
|
|
||
| exports[`generateModernIframeScriptCodeFromPreviews > handle one annotation 1`] = ` | ||
| "import { composeConfigs, PreviewWeb, ClientApi } from 'storybook/internal/preview-api'; | ||
| import '/virtual:/@storybook/builder-vite/setup-addons.js'; | ||
| import { importFn } from '/virtual:/@storybook/builder-vite/storybook-stories.js'; | ||
| import previewAnnotations_1983 from "/previewAnnotations"; | ||
| const getProjectAnnotations = (hmrPreviewAnnotationModules = []) => { | ||
| const configs = [ | ||
| hmrPreviewAnnotationModules.at(0) ?? previewAnnotations_1983 | ||
| ] | ||
| return composeConfigs(configs); | ||
| } | ||
|
|
||
| window.__STORYBOOK_PREVIEW__ = window.__STORYBOOK_PREVIEW__ || new PreviewWeb(importFn, getProjectAnnotations); | ||
|
|
||
| window.__STORYBOOK_STORY_STORE__ = window.__STORYBOOK_STORY_STORE__ || window.__STORYBOOK_PREVIEW__.storyStore; | ||
|
|
||
| if (import.meta.hot) { | ||
| import.meta.hot.accept('/virtual:/@storybook/builder-vite/storybook-stories.js', (newModule) => { | ||
| // importFn has changed so we need to patch the new one in | ||
| window.__STORYBOOK_PREVIEW__.onStoriesChanged({ importFn: newModule.importFn }); | ||
| }); | ||
|
|
||
| import.meta.hot.accept(["/previewAnnotations"], (previewAnnotationModules) => { | ||
| // getProjectAnnotations has changed so we need to patch the new one in | ||
| window.__STORYBOOK_PREVIEW__.onGetProjectAnnotationsChanged({ getProjectAnnotations: () => getProjectAnnotations(previewAnnotationModules) }); | ||
| }); | ||
| };" | ||
| `; |
23 changes: 23 additions & 0 deletions
23
code/builders/builder-vite/src/codegen-modern-iframe-script.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { generateModernIframeScriptCodeFromPreviews } from './codegen-modern-iframe-script'; | ||
|
|
||
| const projectRoot = 'projectRoot'; | ||
|
|
||
| describe('generateModernIframeScriptCodeFromPreviews', () => { | ||
| it('handle one annotation', async () => { | ||
| const result = await generateModernIframeScriptCodeFromPreviews({ | ||
| previewAnnotations: ['previewAnnotations'], | ||
| projectRoot, | ||
| frameworkName: 'frameworkName', | ||
| }); | ||
| expect(result).toMatchSnapshot(); | ||
| }); | ||
| it('handle multiple annotations', async () => { | ||
| const result = await generateModernIframeScriptCodeFromPreviews({ | ||
| previewAnnotations: ['previewAnnotations1', 'previewAnnotations2'], | ||
| projectRoot, | ||
| frameworkName: 'frameworkName', | ||
| }); | ||
| expect(result).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.