From b781dc974b8f87db25c7315fc6d31106d4f36089 Mon Sep 17 00:00:00 2001 From: JustinEloffBBD <108668610+JustinEloffBBD@users.noreply.github.com> Date: Wed, 1 Mar 2023 22:01:40 +0200 Subject: [PATCH 1/3] Set svelteConfig to empty object by default. The svelteDocgen plugin crashes Storybook if you have no svelte config file defined. It tries to destructure the options, but with no config file, this value is null, causing a crash. Setting an empty object as a fallback looks like it solved the issue. --- code/frameworks/svelte-vite/src/preset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/frameworks/svelte-vite/src/preset.ts b/code/frameworks/svelte-vite/src/preset.ts index bf7a7f742511..cec2cd6d7d66 100644 --- a/code/frameworks/svelte-vite/src/preset.ts +++ b/code/frameworks/svelte-vite/src/preset.ts @@ -14,7 +14,7 @@ export const viteFinal: NonNullable = async (confi // TODO: set up eslint import to use typescript resolver // eslint-disable-next-line import/no-unresolved const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte'); - const svelteConfig = await loadSvelteConfig(); + const svelteConfig = await loadSvelteConfig() || {}; // Add svelte plugin if the user does not have a Vite config of their own if (!(await hasVitePlugins(plugins, ['vite-plugin-svelte']))) { From 198e6f01f20e8dd0a7cab531385186c54cae7324 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Thu, 2 Mar 2023 07:23:48 +0800 Subject: [PATCH 2/3] Fix linting --- code/frameworks/svelte-vite/src/preset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/frameworks/svelte-vite/src/preset.ts b/code/frameworks/svelte-vite/src/preset.ts index cec2cd6d7d66..0bca7efd1cde 100644 --- a/code/frameworks/svelte-vite/src/preset.ts +++ b/code/frameworks/svelte-vite/src/preset.ts @@ -14,7 +14,7 @@ export const viteFinal: NonNullable = async (confi // TODO: set up eslint import to use typescript resolver // eslint-disable-next-line import/no-unresolved const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte'); - const svelteConfig = await loadSvelteConfig() || {}; + const svelteConfig = (await loadSvelteConfig()) || {}; // Add svelte plugin if the user does not have a Vite config of their own if (!(await hasVitePlugins(plugins, ['vite-plugin-svelte']))) { From 5f214d0b0b00be26b860640e8ae17f1f25695fbb Mon Sep 17 00:00:00 2001 From: "justin.eloff" Date: Thu, 2 Mar 2023 14:53:13 +0100 Subject: [PATCH 3/3] Move the default value into the svelte-docgen plugin. --- code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts | 2 +- code/frameworks/svelte-vite/src/preset.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts b/code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts index 55fd98811af4..b9e8ac5fa762 100644 --- a/code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts +++ b/code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts @@ -42,7 +42,7 @@ function getNameFromFilename(filename: string) { return base[0].toUpperCase() + base.slice(1); } -export function svelteDocgen(svelteOptions: Record): PluginOption { +export function svelteDocgen(svelteOptions: Record = {}): PluginOption { const cwd = process.cwd(); const { preprocess: preprocessOptions, logDocgen = false } = svelteOptions; const include = /\.(svelte)$/; diff --git a/code/frameworks/svelte-vite/src/preset.ts b/code/frameworks/svelte-vite/src/preset.ts index 0bca7efd1cde..bf7a7f742511 100644 --- a/code/frameworks/svelte-vite/src/preset.ts +++ b/code/frameworks/svelte-vite/src/preset.ts @@ -14,7 +14,7 @@ export const viteFinal: NonNullable = async (confi // TODO: set up eslint import to use typescript resolver // eslint-disable-next-line import/no-unresolved const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte'); - const svelteConfig = (await loadSvelteConfig()) || {}; + const svelteConfig = await loadSvelteConfig(); // Add svelte plugin if the user does not have a Vite config of their own if (!(await hasVitePlugins(plugins, ['vite-plugin-svelte']))) {