Skip to content
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

Vite: Export storybook utilities from frameworks for better pnpm support #19216

Merged
merged 4 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions code/frameworks/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
"dependencies": {
"@joshwooding/vite-plugin-react-docgen-typescript": "^0.0.5",
"@rollup/pluginutils": "^4.2.0",
"@storybook/addons": "7.0.0-alpha.33",
"@storybook/builder-vite": "7.0.0-alpha.33",
"@storybook/channel-postmessage": "7.0.0-alpha.33",
"@storybook/channel-websocket": "7.0.0-alpha.33",
"@storybook/client-api": "7.0.0-alpha.33",
"@storybook/preview-web": "7.0.0-alpha.33",
"@storybook/react": "7.0.0-alpha.33",
"@vitejs/plugin-react": "^2.0.1",
"ast-types": "^0.14.2",
Expand Down
7 changes: 7 additions & 0 deletions code/frameworks/react-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// exports for builder-vite
export { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage';
export { createChannel as createWebSocketChannel } from '@storybook/channel-websocket';
export { addons } from '@storybook/addons';
export { composeConfigs, PreviewWeb } from '@storybook/preview-web';
export { ClientApi } from '@storybook/client-api';

export * from '@storybook/react';
export type { StorybookConfig } from '@storybook/builder-vite';
5 changes: 5 additions & 0 deletions code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
},
"dependencies": {
"@storybook/addon-svelte-csf": "^2.0.0",
"@storybook/addons": "7.0.0-alpha.33",
"@storybook/builder-vite": "7.0.0-alpha.33",
"@storybook/channel-postmessage": "7.0.0-alpha.33",
"@storybook/channel-websocket": "7.0.0-alpha.33",
"@storybook/client-api": "7.0.0-alpha.33",
"@storybook/node-logger": "7.0.0-alpha.33",
"@storybook/preview-web": "7.0.0-alpha.33",
"@storybook/svelte": "7.0.0-alpha.33",
"@sveltejs/vite-plugin-svelte": "^1.0.0",
"magic-string": "^0.26.1",
Expand Down
7 changes: 7 additions & 0 deletions code/frameworks/svelte-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// exports for builder-vite
export { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage';
export { createChannel as createWebSocketChannel } from '@storybook/channel-websocket';
export { addons } from '@storybook/addons';
export { composeConfigs, PreviewWeb } from '@storybook/preview-web';
export { ClientApi } from '@storybook/client-api';

export * from '@storybook/svelte';
export type { StorybookConfig } from '@storybook/builder-vite';
5 changes: 5 additions & 0 deletions code/frameworks/vue3-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/addons": "7.0.0-alpha.33",
"@storybook/builder-vite": "7.0.0-alpha.33",
"@storybook/channel-postmessage": "7.0.0-alpha.33",
"@storybook/channel-websocket": "7.0.0-alpha.33",
"@storybook/client-api": "7.0.0-alpha.33",
"@storybook/core-server": "7.0.0-alpha.33",
"@storybook/preview-web": "7.0.0-alpha.33",
"@storybook/vue3": "7.0.0-alpha.33",
"@vitejs/plugin-vue": "^3.0.3",
"magic-string": "^0.26.1",
Expand Down
7 changes: 7 additions & 0 deletions code/frameworks/vue3-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// exports for builder-vite
export { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage';
export { createChannel as createWebSocketChannel } from '@storybook/channel-websocket';
export { addons } from '@storybook/addons';
export { composeConfigs, PreviewWeb } from '@storybook/preview-web';
export { ClientApi } from '@storybook/client-api';

export * from '@storybook/vue3';
export type { StorybookConfig } from '@storybook/builder-vite';
3 changes: 0 additions & 3 deletions code/lib/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
},
"dependencies": {
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
"@storybook/addons": "7.0.0-alpha.33",
"@storybook/channel-postmessage": "7.0.0-alpha.33",
"@storybook/channel-websocket": "7.0.0-alpha.33",
"@storybook/client-api": "7.0.0-alpha.33",
"@storybook/client-logger": "7.0.0-alpha.33",
"@storybook/core-common": "7.0.0-alpha.33",
Expand Down
4 changes: 2 additions & 2 deletions code/lib/builder-vite/src/codegen-modern-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export async function generateModernIframeScriptCode(options: ExtendedOptions) {
* @todo Inline variable and remove `noinspection`
*/
const code = `
import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
import { ClientApi } from '@storybook/client-api';
import { ClientApi, composeConfigs, PreviewWeb } from '${frameworkName}';

import '${virtualAddonSetupFile}';
import { importFn } from '${virtualStoriesFile}';

Expand Down
12 changes: 8 additions & 4 deletions code/lib/builder-vite/src/codegen-set-addon-channel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export function generateAddonSetupCode() {
import { getFrameworkName } from '@storybook/core-common';

import type { ExtendedOptions } from './types';

export async function generateAddonSetupCode(options: ExtendedOptions) {
const framework = await getFrameworkName(options);

return `
import { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage';
import { createChannel as createWebSocketChannel } from '@storybook/channel-websocket';
import { addons } from '@storybook/addons';
import { createPostMessageChannel, createWebSocketChannel, addons } from '${framework}';

const channel = createPostMessageChannel({ page: 'preview' });
addons.setChannel(channel);
Expand Down
2 changes: 1 addition & 1 deletion code/lib/builder-vite/src/plugins/code-generator-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
}

if (id === virtualAddonSetupFile) {
return generateAddonSetupCode();
return generateAddonSetupCode(options);
}

if (id === virtualPreviewFile && !storyStoreV7) {
Expand Down
18 changes: 15 additions & 3 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7657,9 +7657,6 @@ __metadata:
resolution: "@storybook/builder-vite@workspace:lib/builder-vite"
dependencies:
"@joshwooding/vite-plugin-react-docgen-typescript": 0.0.5
"@storybook/addons": 7.0.0-alpha.33
"@storybook/channel-postmessage": 7.0.0-alpha.33
"@storybook/channel-websocket": 7.0.0-alpha.33
"@storybook/client-api": 7.0.0-alpha.33
"@storybook/client-logger": 7.0.0-alpha.33
"@storybook/core-common": 7.0.0-alpha.33
Expand Down Expand Up @@ -8828,7 +8825,12 @@ __metadata:
dependencies:
"@joshwooding/vite-plugin-react-docgen-typescript": ^0.0.5
"@rollup/pluginutils": ^4.2.0
"@storybook/addons": 7.0.0-alpha.33
"@storybook/builder-vite": 7.0.0-alpha.33
"@storybook/channel-postmessage": 7.0.0-alpha.33
"@storybook/channel-websocket": 7.0.0-alpha.33
"@storybook/client-api": 7.0.0-alpha.33
"@storybook/preview-web": 7.0.0-alpha.33
"@storybook/react": 7.0.0-alpha.33
"@types/node": ^14.14.20 || ^16.0.0
"@vitejs/plugin-react": ^2.0.1
Expand Down Expand Up @@ -9303,8 +9305,13 @@ __metadata:
resolution: "@storybook/svelte-vite@workspace:frameworks/svelte-vite"
dependencies:
"@storybook/addon-svelte-csf": ^2.0.0
"@storybook/addons": 7.0.0-alpha.33
"@storybook/builder-vite": 7.0.0-alpha.33
"@storybook/channel-postmessage": 7.0.0-alpha.33
"@storybook/channel-websocket": 7.0.0-alpha.33
"@storybook/client-api": 7.0.0-alpha.33
"@storybook/node-logger": 7.0.0-alpha.33
"@storybook/preview-web": 7.0.0-alpha.33
"@storybook/svelte": 7.0.0-alpha.33
"@sveltejs/vite-plugin-svelte": ^1.0.0
"@types/node": ^14.14.20 || ^16.0.0
Expand Down Expand Up @@ -9499,8 +9506,13 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/vue3-vite@workspace:frameworks/vue3-vite"
dependencies:
"@storybook/addons": 7.0.0-alpha.33
"@storybook/builder-vite": 7.0.0-alpha.33
"@storybook/channel-postmessage": 7.0.0-alpha.33
"@storybook/channel-websocket": 7.0.0-alpha.33
"@storybook/client-api": 7.0.0-alpha.33
"@storybook/core-server": 7.0.0-alpha.33
"@storybook/preview-web": 7.0.0-alpha.33
"@storybook/vue3": 7.0.0-alpha.33
"@types/node": ^14.14.20 || ^16.0.0
"@vitejs/plugin-vue": ^3.0.3
Expand Down