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
Core, Server, Addon-docs: Replace story indexers with new API #23660
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I have some questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! One suggestion though
import type { Indexer, NormalizedStoriesSpecifier, StoryIndexEntry } from '@storybook/types'; | ||
import { loadCsf, getStorySortParameter } from '@storybook/csf-tools'; | ||
import type { NormalizedStoriesSpecifier, StoryIndexEntry } from '@storybook/types'; | ||
// import * as csfTools from '@storybook/csf-tools'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// import * as csfTools from '@storybook/csf-tools'; |
const csf = (await readCsf(fileName, options)).parse(); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
return Object.entries(csf._stories).map(([exportName, story]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this to a getter on CsfFile
? The code seems to be duplicated all over the place and that would make this PR a lot more DRY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CsfFile.indexEntries
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've been thinking something similar, I'll experiment with a getter for indexInputs
and stories with exportName
so you don't need the funky use of _stories
.
Works on #23457
What I did
This PR does multiple things (shame on me. Sorry.)
1. Replaces all the internal story indexes with the new API:
2. Handle
docsOnly
mode in Stories MDXThe new indexer handler now automatically removes story entries that are
docsOnly
*, as defined by having the"docsOnly"
tag. So the Stories MDX indexer now adds that tag when it seesparameters.docsOnly
, which is actually set byCsfFile.parse()
🥵.*
docsOnly
is a feature exclusive to Stories MDX, and happens whenever anystories.mdx
files don't render any stories - so only Docs needs to appear in the sidebar. I assume this handling can be removed when we finally remove Stories MDX completely.3. Minor improvements to the
server
rendererstories
glob when initing aserver
project now includesyaml
andyml
extensions along with the existingjson
extensions. The indexer already handled this, it just wasn't in the globsTwo aspects of autodocs that are broken in the server renderer:
Are these two points enough that I should remove it again, or is this better than nothing @shilman ?
How to test
?path=/docs/addons-docs-stories-mdx-unattached--docs
. It should be a lonelyunattached
Docs entry with no stories, because it'sdocsOnly
.internal/server-webpack5
sandbox.Checklist
MIGRATION.MD
Maintainers
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
["cleanup", "BREAKING CHANGE", "feature request", "bug", "build", "documentation", "maintenance", "dependencies", "other"]
🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>