storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.51k stars 9.3k forks source link

[Bug]: Story Indexer doesn't support `type: docs` #28803

Open tobiasdiez opened 2 months ago

tobiasdiez commented 2 months ago

Describe the bug

If a story indexer returns type: docs, then this is ignored and it is added as type: story, see https://github.com/storybookjs/storybook/blob/b94ead30bd1798648bc674bce61ba841508b6bbc/code/core/src/core-server/utils/StoryIndexGenerator.ts#L369

Reproduction link

https://github.com/tobiasdiez/storybook-vue-addon/pull/118 (see code)

Reproduction steps

No response

System

Latest storybook

Additional context

No response

greptile-apps[bot] commented 2 months ago

Disclaimer This information might be inaccurate, due to it being generated automatically To address the issue where the story indexer doesn't support type: docs, follow these steps:

  1. Update extractStories Method: Modify the extractStories method in StoryIndexGenerator.ts to correctly handle entries with type: docs.

    const entries: ((StoryIndexEntryWithExtra | DocsCacheEntry) & { tags: Tag[] })[] = indexInputs.map((input) => {
     const name = input.name ?? storyNameFromExport(input.exportName);
     const componentPath = input.rawComponentPath && this.resolveComponentPath(input.rawComponentPath, absolutePath, matchPath);
     const title = input.title ?? defaultMakeTitle();
     const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName));
     const tags = combineTags(...projectTags, ...(input.tags ?? []));
    
     return {
       type: input.type || 'story', // Ensure type is correctly set
       id,
       extra: {
         metaId: input.metaId,
         stats: input.__stats ?? {},
       },
       name,
       title,
       importPath,
       componentPath,
       tags,
     };
    });
  2. Update Tests: Ensure that the tests in StoryIndexGenerator.test.ts cover scenarios where type: docs is returned by the indexer.

    it('handles entries with type: docs correctly', async () => {
     const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry('./src/docs/*.mdx', options);
     const generator = new StoryIndexGenerator([specifier], autodocsOptions);
     await generator.initialize();
    
     const { storyIndex } = await generator.getIndexAndStats();
     expect(storyIndex.entries['docs-entry-id'].type).toBe('docs');
    });

References

/.github/DISCUSSION_TEMPLATE/help.yml /.github/DISCUSSION_TEMPLATE/ideas.yml /.github/comments/invalid-link.md /code/core/src/core-server/utils/summarizeIndex.test.ts /code/core/src/preview-errors.ts /code/addons/docs/angular /test-storybooks/ember-cli/ember-output/storybook-docgen /.github/comments /.github/DISCUSSION_TEMPLATE/rfc.yml /docs/_snippets/test-runner-with-index-json.md /code/core/src/core-server/utils/StoryIndexGenerator.test.ts /code/addons/docs/ember /docs/_snippets/test-runner-no-index-json.md /code/core/src/core-server/utils/mockdata/errors/NoMeta.stories.ts /docs/_snippets/main-config-indexers-jsonstories.md /docs/_snippets/storybook-preview-with-angular-polyfills.md /code/lib/cli-storybook/project.json /code/frameworks/ember/src/client/preview/docs /code/lib/cli/src/automigrate/fixes/mdx-gfm.ts /code/addons/docs/template/stories/docspage /code/core/src/csf-tools/CsfFile.test.ts /code/addons/storysource /code/core/src/server-errors.ts /code/addons/docs/react /code/core/src/csf-tools/ConfigFile.test.ts

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/storybookjs/storybook/next) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)
JReinhold commented 2 months ago

Unfortunately we never managed to implement that part of the indexer, which is also why it's still experimental. Thanks for opening this.