Skip to content

TestBuild: Fix indexer bug#24890

Merged
ndelangen merged 8 commits into
nextfrom
norbert/improve-mdx-filtering
Nov 17, 2023
Merged

TestBuild: Fix indexer bug#24890
ndelangen merged 8 commits into
nextfrom
norbert/improve-mdx-filtering

Conversation

@ndelangen
Copy link
Copy Markdown
Member

@ndelangen ndelangen commented Nov 17, 2023

What I did

enable the --test flag internally when building our storybook

I discovered that the titlePrefix and directory fiels are super-important for a correct creation of the index.json.
... by flattening all the files without taking these into account, the conflicting stories-ids problem could occur, and the hierarchy of the index.json would be completely incorrect. (which would cause removed/renamed stories!).

I also am setting a different default_files_patterns now based on the disableMDXEntries setting, which should yield fewer individual pattern globs.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make 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/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>

@ndelangen ndelangen added bug feature request ci:normal Run our default set of CI jobs (choose this for most PRs). labels Nov 17, 2023
@ndelangen ndelangen self-assigned this Nov 17, 2023
if (filteredEntries.length < expanded.files.length) {
items = filteredEntries.map((k) => ({
...expanded,
files: `**/${k}`,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part I'm not really happy about... But it was the only solution I could really find without digging into this:

export function globToRegexp(glob: string) {
const regex = pico.makeRe(glob, {
fastpaths: false,
noglobstar: false,
bash: false,
});
if (!regex.source.startsWith('^')) {
throw new Error(`Invalid glob: >> ${glob} >> ${regex}`);
}
if (!glob.startsWith('./')) {
return regex;
}
// makeRe is sort of funny. If you pass it a directory starting with `./` it
// creates a matcher that expects files with no prefix (e.g. `src/file.js`)
// but if you pass it a directory that starts with `../` it expects files that
// start with `../`. Let's make it consistent.
// Globs starting `**` require special treatment due to the regex they
// produce, specifically a negative look-ahead
return new RegExp(
['^\\.', glob.startsWith('./**') ? '' : '[\\\\/]', regex.source.substring(1)].join('')
);
}

... and it really do not want to go digging into that code, right now.

I'm thinking this is "close enough" for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +57 to +61
build: {
test: {
disableBlocks: false,
},
},
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed because of:

(Story, { loaded: { docsContext } }) =>
docsContext ? (
<DocsContext.Provider value={docsContext}>
<Story />
</DocsContext.Provider>
) : (
<Story />
),
/**
* This decorator adds wrappers that contains global styles for stories to be targeted by.
* Activated with parameters.docsStyles = true
*/ (Story, { parameters: { docsStyles } }) =>
docsStyles ? (
<DocsPageWrapper>
<Story />
</DocsPageWrapper>
) : (
<Story />
),

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.

Comment thread code/package.json Outdated
@ndelangen ndelangen changed the title TestBuild: Fix indexer bug & Enable it internally TestBuild: Fix indexer bug Nov 17, 2023
Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one comment

};
})
)
).flatMap((expanded, i) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't using a flatMap a lot simpler?

@ndelangen ndelangen merged commit d11044a into next Nov 17, 2023
@ndelangen ndelangen deleted the norbert/improve-mdx-filtering branch November 17, 2023 15:56
@github-actions github-actions Bot mentioned this pull request Nov 17, 2023
36 tasks
export const normalizeStoriesEntry = (
entry: StoriesEntry,
{ configDir, workingDir }: NormalizeOptions
{ configDir, workingDir, default_files_pattern = DEFAULT_FILES_PATTERN }: NormalizeOptions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why snake case when the other options are camel case?

if (filteredEntries.length < expanded.files.length) {
items = filteredEntries.map((k) => ({
...expanded,
files: `**/${k}`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants