From 50991a69eb9431e537622df8f56d000594d97241 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 18 Jul 2022 10:52:26 -0700 Subject: [PATCH] don't make webpack users specify preprocess option --- app/svelte/package.json | 1 + app/svelte/src/server/svelte-docgen-loader.ts | 8 +++++++- yarn.lock | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/svelte/package.json b/app/svelte/package.json index 2ddf73de058f..73bdb13b2a5d 100644 --- a/app/svelte/package.json +++ b/app/svelte/package.json @@ -54,6 +54,7 @@ "@storybook/docs-tools": "6.5.0-rc.1", "@storybook/node-logger": "6.5.0-rc.1", "@storybook/store": "6.5.0-rc.1", + "@types/node": "^14.14.20 || ^16.0.0", "core-js": "^3.8.2", "global": "^4.4.0", "loader-utils": "^2.0.0", diff --git a/app/svelte/src/server/svelte-docgen-loader.ts b/app/svelte/src/server/svelte-docgen-loader.ts index 8206c87cbf9f..01a6c2395a2d 100644 --- a/app/svelte/src/server/svelte-docgen-loader.ts +++ b/app/svelte/src/server/svelte-docgen-loader.ts @@ -46,7 +46,13 @@ export default async function svelteDocgen(source: string) { const { resource } = this._module; const svelteOptions: any = { ...getOptions(this) }; - const { preprocess: preprocessOptions, logDocgen = false } = svelteOptions; + let configPath = path.join(process.cwd(), './svelte.config.js'); + if (!fs.existsSync(configPath)) configPath = path.join(process.cwd(), './svelte.config.mjs'); + if (!fs.existsSync(configPath)) configPath = path.join(process.cwd(), './svelte.config.cjs'); + if (!fs.existsSync(configPath)) throw new Error('Could not locate Svelte config file'); + const config = (await import(configPath)).default; + + const { preprocess: preprocessOptions = config.preprocess, logDocgen = false } = svelteOptions; let docOptions; if (preprocessOptions) { diff --git a/yarn.lock b/yarn.lock index 54bf378d328e..a232bda6dbe5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8932,6 +8932,7 @@ __metadata: "@storybook/node-logger": 6.5.0-rc.1 "@storybook/store": 6.5.0-rc.1 "@types/loader-utils": ^2.0.0 + "@types/node": ^14.14.20 || ^16.0.0 "@types/webpack-env": ^1.16.0 core-js: ^3.8.2 global: ^4.4.0