TestBuild: Fix indexer bug#24890
Conversation
| if (filteredEntries.length < expanded.files.length) { | ||
| items = filteredEntries.map((k) => ({ | ||
| ...expanded, | ||
| files: `**/${k}`, |
There was a problem hiding this comment.
This is the part I'm not really happy about... But it was the only solution I could really find without digging into this:
storybook/code/lib/core-common/src/utils/glob-to-regexp.ts
Lines 3 to 27 in ff6b28e
... and it really do not want to go digging into that code, right now.
I'm thinking this is "close enough" for now.
There was a problem hiding this comment.
It would be a lot easier to understand what this code was doing if we had a test for it.
I am assuming it turns something like:
[{ directory: 'foo', files: '**/*.(mdx|stories.js)' }]
Into something like:
[
{ directory: 'foo', files: '**/first-story.stories.js' },
{ directory: 'foo', files: '**/second-story.stories.js' },
//..
]
Where that list can be very long? That seems like it would have a pretty detritmental impact on build times if that list was really long, but I guess we would have to test it it out to know for sure.
I wonder if there's a way to hit the most common cases and just drop the mdx| bit from the regexp, if we see a common pattern like '**/*.@(mdx|stories.@(js|jsx|mjs|ts|tsx))';
Also, what if the expanded list is empty?
| build: { | ||
| test: { | ||
| disableBlocks: false, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Needed because of:
storybook/code/ui/.storybook/preview.tsx
Lines 141 to 159 in ab7fd6d
This breaks at runtime, because if blocks is replaced as a module by an empty object, that object (obviously) does not contain what is needed here.
…when --test flag is set
| }; | ||
| }) | ||
| ) | ||
| ).flatMap((expanded, i) => { |
There was a problem hiding this comment.
Isn't using a flatMap a lot simpler?
| export const normalizeStoriesEntry = ( | ||
| entry: StoriesEntry, | ||
| { configDir, workingDir }: NormalizeOptions | ||
| { configDir, workingDir, default_files_pattern = DEFAULT_FILES_PATTERN }: NormalizeOptions |
There was a problem hiding this comment.
Why snake case when the other options are camel case?
| if (filteredEntries.length < expanded.files.length) { | ||
| items = filteredEntries.map((k) => ({ | ||
| ...expanded, | ||
| files: `**/${k}`, |
There was a problem hiding this comment.
It would be a lot easier to understand what this code was doing if we had a test for it.
I am assuming it turns something like:
[{ directory: 'foo', files: '**/*.(mdx|stories.js)' }]
Into something like:
[
{ directory: 'foo', files: '**/first-story.stories.js' },
{ directory: 'foo', files: '**/second-story.stories.js' },
//..
]
Where that list can be very long? That seems like it would have a pretty detritmental impact on build times if that list was really long, but I guess we would have to test it it out to know for sure.
I wonder if there's a way to hit the most common cases and just drop the mdx| bit from the regexp, if we see a common pattern like '**/*.@(mdx|stories.@(js|jsx|mjs|ts|tsx))';
Also, what if the expanded list is empty?
What I did
enable the --test flag internally when building our storybook
I discovered that the
titlePrefixanddirectoryfiels are super-important for a correct creation of theindex.json.... by flattening all the files without taking these into account, the conflicting stories-ids problem could occur, and the hierarchy of the
index.jsonwould be completely incorrect. (which would cause removed/renamed stories!).I also am setting a different default_files_patterns now based on the
disableMDXEntriessetting, which should yield fewer individual pattern globs.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 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/coreteam 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>