mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 20:21:07 +08:00
svelte-vite error on sveltekit instead of warn
This commit is contained in:
parent
e97b81f4f2
commit
ad2232c26b
@ -8,7 +8,7 @@ export const core: StorybookConfig['core'] = {
|
||||
};
|
||||
|
||||
export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (config, options) => {
|
||||
let { plugins = [] } = config;
|
||||
const { plugins = [] } = config;
|
||||
const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte');
|
||||
const svelteOptions: Record<string, any> = await options.presets.apply(
|
||||
'svelteOptions',
|
||||
@ -25,8 +25,7 @@ export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (confi
|
||||
// Add docgen plugin
|
||||
plugins.push(svelteDocgen(svelteConfig));
|
||||
|
||||
// temporarily support SvelteKit
|
||||
plugins = await handleSvelteKit(plugins, options);
|
||||
await handleSvelteKit(plugins, options);
|
||||
|
||||
// TODO: temporary until/unless https://github.com/storybookjs/addon-svelte-csf/issues/64 is fixed
|
||||
// Wrapping in try-catch in case `@storybook/addon-svelte-csf is not installed
|
||||
|
@ -1,6 +1,4 @@
|
||||
import type { PluginOption } from 'vite';
|
||||
import { deprecate } from '@storybook/node-logger';
|
||||
import { withoutVitePlugins } from '@storybook/builder-vite';
|
||||
import type { Options } from '@storybook/types';
|
||||
|
||||
function checkName(plugin: PluginOption, name: string) {
|
||||
@ -23,32 +21,24 @@ export function hasPlugin(plugins: PluginOption[], name: string) {
|
||||
* but warns the user that they should use the sveltekit framework instead.
|
||||
* Should be removed when we decide to remove support completely for SvelteKit in svelte-vite
|
||||
*/
|
||||
export async function handleSvelteKit(
|
||||
plugins: PluginOption[],
|
||||
options: Options
|
||||
): Promise<PluginOption[]> {
|
||||
if (!hasPlugin(plugins, 'vite-plugin-svelte-kit')) {
|
||||
// this is not a SvelteKit project ✅
|
||||
return plugins;
|
||||
}
|
||||
|
||||
export async function handleSvelteKit(plugins: PluginOption[], options: Options) {
|
||||
/*
|
||||
the sveltekit framework uses this svelte-vite framework under the hood
|
||||
so we have to take extra care of only warning when the user is actually using
|
||||
so we have to take extra care of only throwing when the user is actually using
|
||||
svelte-vite directly and not just through sveltekit
|
||||
*/
|
||||
|
||||
const frameworkPreset = await options.presets.apply('framework', {}, options);
|
||||
const framework = typeof frameworkPreset === 'string' ? frameworkPreset : frameworkPreset.name;
|
||||
|
||||
if (framework === '@storybook/sveltekit') {
|
||||
// this uses @storybook/sveltekit, so everything is fine ✅
|
||||
return plugins;
|
||||
}
|
||||
if (hasPlugin(plugins, 'vite-plugin-svelte-kit') && framework !== '@storybook/sveltekit') {
|
||||
throw new Error(`
|
||||
We've detected a SvelteKit project using the @storybook/svelte-vite framework, which is not supported in Storybook 7.0
|
||||
Please use the @storybook/sveltekit framework instead.
|
||||
You can migrate automatically by running
|
||||
|
||||
npx sb@next automigrate sveltekitFramework
|
||||
|
||||
// this is a SvelteKit project but doesn't use @storybook/sveltekit, warn user about this and remove vite-plugin-svelte-kit ❌
|
||||
deprecate(
|
||||
'SvelteKit support in @storybook/svelte-vite is deprecated in Storybook 7.0, use @storybook/sveltekit instead.'
|
||||
);
|
||||
return withoutVitePlugins(plugins, ['vite-plugin-svelte-kit']);
|
||||
See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#sveltekit-needs-the-storybooksveltekit-framework
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user