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

Remove vite-plugin-svelte-kit when detected #19522

Merged
merged 9 commits into from
Oct 19, 2022
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ jobs:
executor:
class: medium+
name: sb_node_16_browsers
parallelism: 20
parallelism: 22
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -341,7 +341,7 @@ jobs:
executor:
class: medium+
name: sb_node_16_browsers
parallelism: 15
parallelism: 22
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -356,7 +356,7 @@ jobs:
executor:
class: medium+
name: sb_node_16_browsers
parallelism: 20
parallelism: 22
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -375,7 +375,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 18
parallelism: 20
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -390,7 +390,7 @@ jobs:
executor:
class: medium+
name: sb_node_16_browsers
parallelism: 20
parallelism: 22
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -405,7 +405,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 20
parallelism: 22
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand Down
8 changes: 6 additions & 2 deletions code/frameworks/svelte-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/builder-vite';
import { StorybookConfig, withoutVitePlugins } from '@storybook/builder-vite';
import { hasPlugin } from './utils';
import { svelteDocgen } from './plugins/svelte-docgen';

Expand All @@ -9,7 +9,7 @@ export const core: StorybookConfig['core'] = {
};

export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) => {
const { plugins = [] } = config;
let { plugins = [] } = config;
const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte');
const svelteOptions: Record<string, any> = await options.presets.apply(
'svelteOptions',
Expand All @@ -26,6 +26,10 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config, options) =
// Add docgen plugin
plugins.push(svelteDocgen(svelteConfig));

// Remove vite-plugin-svelte-kit from plugins if using SvelteKit
// see https://github.com/storybookjs/storybook/issues/19280#issuecomment-1281204341
plugins = withoutVitePlugins(plugins, ['vite-plugin-svelte-kit']);

// 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
try {
Expand Down
1 change: 1 addition & 0 deletions code/lib/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createViteServer } from './vite-server';
import { build as viteBuild } from './build';
import type { ExtendedOptions } from './types';

export { withoutVitePlugins } from './utils/without-vite-plugins';
export type { TypescriptOptions } from '@storybook/core-common';

// Storybook's Stats are optional Webpack related property
Expand Down
16 changes: 16 additions & 0 deletions code/lib/builder-vite/src/utils/without-vite-plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PluginOption } from 'vite';

// recursively remove all plugins with the given names
export const withoutVitePlugins = (
plugins: PluginOption[] = [],
namesToRemove: string[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've unintentionally helped me add another feature which I've had in mind, which is allowing users to remove plugins from their vite config by providing a list of names, similar to what Histoire allows: https://histoire.dev/guide/config.html#ignoring-plugins. Having this function will come in handy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha great. I just thought that I'd written it 3 times now that it probably deserves it's own utility.

): PluginOption[] =>
plugins.map((plugin) => {
if (Array.isArray(plugin)) {
return withoutVitePlugins(plugin, namesToRemove);
}
if (plugin && 'name' in plugin && namesToRemove.includes(plugin.name)) {
return false;
}
return plugin;
});
53 changes: 25 additions & 28 deletions code/lib/cli/src/repro-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,32 +174,30 @@ const angularCliTemplates = {
},
};

// TODO: enable this when repo has been upgraded to node@16
// SvelteKit only supports Node.js >16.x, so before generating these repros you need to switch to that version
// const svelteKitTemplates = {
// 'svelte-kit/skeleton-js': {
// name: 'Svelte Kit (JS)',
// script:
// 'yarn create svelte-with-args --name=svelte-kit/skeleton-js --directory=. --template=skeleton --types=null --no-prettier --no-eslint --no-playwright',
// cadence: ['ci', 'daily', 'weekly'],
// expected: {
// framework: '@storybook/svelte-vite',
// renderer: '@storybook/svelte',
// builder: '@storybook/builder-vite',
// },
// },
// 'svelte-kit/skeleton-ts': {
// name: 'Svelte Kit (TS)',
// script:
// 'yarn create svelte-with-args --name=svelte-kit/skeleton-ts --directory=. --template=skeleton --types=typescript --no-prettier --no-eslint --no-playwright',
// cadence: ['ci', 'daily', 'weekly'],
// expected: {
// framework: '@storybook/svelte-vite',
// renderer: '@storybook/svelte',
// builder: '@storybook/builder-vite',
// },
// },
// };
const svelteKitTemplates = {
'svelte-kit/skeleton-js': {
name: 'Svelte Kit (JS)',
script:
'yarn create svelte-with-args --name=svelte-kit/skeleton-js --directory=. --template=skeleton --types=null --no-prettier --no-eslint --no-playwright',
cadence: ['ci', 'daily', 'weekly'],
expected: {
framework: '@storybook/svelte-vite',
renderer: '@storybook/svelte',
builder: '@storybook/builder-vite',
},
},
'svelte-kit/skeleton-ts': {
name: 'Svelte Kit (TS)',
script:
'yarn create svelte-with-args --name=svelte-kit/skeleton-ts --directory=. --template=skeleton --types=typescript --no-prettier --no-eslint --no-playwright',
cadence: ['ci', 'daily', 'weekly'],
expected: {
framework: '@storybook/svelte-vite',
renderer: '@storybook/svelte',
builder: '@storybook/builder-vite',
},
},
};

const litViteTemplates = {
'lit-vite/default-js': {
Expand Down Expand Up @@ -294,8 +292,7 @@ export default {
...vue2ViteTemplates,
...vue3ViteTemplates,
...svelteViteTemplates,
// TODO: enable this when repo has been upgraded to node@16
// ...svelteKitTemplates,
...svelteKitTemplates,
...angularCliTemplates,
...litViteTemplates,
...vueCliTemplates,
Expand Down