From 762cc663e579544dc6315ac06f5221b40a3a2c74 Mon Sep 17 00:00:00 2001 From: j3rem1e Date: Sat, 2 Sep 2023 10:00:29 +0200 Subject: [PATCH] [Bug] titlePrefix in advanced story specifiers causes the story to crash with "Didn't find 'xyz' in CSF file" --- .storybook/main.ts | 8 +++++--- src/parser/extract-stories.ts | 4 ---- src/preset/indexer.ts | 7 ++++--- stories/button.stories.svelte | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.storybook/main.ts b/.storybook/main.ts index b485723..43fb3c1 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -2,9 +2,11 @@ import type { StorybookConfig } from '@storybook/svelte-vite'; const config: StorybookConfig = { framework: '@storybook/svelte-vite', - stories: [ - '../stories/**/*.stories.svelte', - ], + stories: [{ + directory: '../stories', + files:'**/*.stories.svelte', + titlePrefix:'Demo' + }], addons: [ '../dist/preset/index.js', '@storybook/addon-essentials', diff --git a/src/parser/extract-stories.ts b/src/parser/extract-stories.ts index 9f7c57f..e72e479 100644 --- a/src/parser/extract-stories.ts +++ b/src/parser/extract-stories.ts @@ -1,13 +1,10 @@ import * as svelte from 'svelte/compiler'; import type { Node } from 'estree'; -import { storyNameFromExport, toId } from '@storybook/csf'; - import dedent from 'dedent'; import { extractId } from './extract-id.js'; interface StoryDef { - storyId: string; name: string; template: boolean; source: string; @@ -131,7 +128,6 @@ export function extractStories(component: string): StoriesDef { source = dedent`${component.substr(start, end - start)}`; } stories[isTemplate ? `tpl:${id}` : id] = { - storyId: toId(meta.id || meta.title || id, storyNameFromExport(id)), name, template: isTemplate, source, diff --git a/src/preset/indexer.ts b/src/preset/indexer.ts index 4dcdc4b..57beb16 100644 --- a/src/preset/indexer.ts +++ b/src/preset/indexer.ts @@ -3,6 +3,7 @@ import * as svelte from 'svelte/compiler'; import { extractStories } from '../parser/extract-stories.js'; import fs from 'fs-extra'; import { loadSvelteConfig } from '../config-loader.js'; +import { storyNameFromExport, toId } from '@storybook/csf'; export async function svelteIndexer(fileName, { makeTitle }) { let code = (await fs.readFile(fileName, 'utf-8')).toString(); @@ -13,13 +14,13 @@ export async function svelteIndexer(fileName, { makeTitle }) { } const defs = extractStories(code); - + const meta = { ...defs.meta, title: makeTitle(defs.meta.title) }; return { - meta: { title: makeTitle(defs.meta.title) }, + meta, stories: Object.entries(defs.stories) .filter(([id, story]) => !story.template) .map(([id, story]) => ({ - id: story.storyId, + id: toId(meta.id || meta.title || id, storyNameFromExport(id)), name: story.name, })), }; diff --git a/stories/button.stories.svelte b/stories/button.stories.svelte index bf204bd..8c5cbdc 100644 --- a/stories/button.stories.svelte +++ b/stories/button.stories.svelte @@ -9,7 +9,7 @@ } - +