Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix TurboSnap support for Storybook in a subdirectory (part 2) #539

Merged
merged 3 commits into from
Mar 11, 2022

Conversation

yngvebn
Copy link
Contributor

@yngvebn yngvebn commented Feb 28, 2022

This PR fixes a bug related to situations where Chromatic (Turbosnap enabled) fails with the error "Did not find any CSF globs in preview-stats.json" (#530 and #486 - not sure if these are caused by the same error)

The error occurs if you're using Storybook 6.4 and pass in configDir as something else than '.' to Chromatic, and the reason stems from this array of predefined paths:

const storiesEntryFiles = [
    // v6 store (SB <= 6.3)
    `${storybookDir}/generated-stories-entry.js`,
    // v6 store with root as config dir (or SB 6.4)
    `generated-stories-entry.js`,
    // v6 store with .cjs extension (SB 6.5)
    'generated-stories-entry.cjs',
    // v7 store (SB >= 6.4)
    `storybook-stories.js`,
    // vite builder
    `/virtual:/@storybook/builder-vite/vite-app.js`,
];

In this case, storybookDir will be resolved as a combination of baseDir + storybookConfigDir whereas the rest are not. This fix ensures the storiesEntryFiles respects both storybookBaseDir and storybookConfigDir

@tmeasday tmeasday requested a review from ghengeveld March 4, 2022 18:26
Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

This changes makes sense to me. We should always be looking for paths relative to the project root.

Thanks @yngvebn. @ghengeveld I'll let you merge if you agree + release 👍

@ghengeveld
Copy link
Member

Thanks. This was similar to the work done in #527 but yours is actually better because it normalizes all entry file paths, making it more robust and future-proof. I ended up using a bit from both PRs and cleaning up a couple things. Nice work!

@ghengeveld ghengeveld merged commit 52e5f05 into chromaui:main Mar 11, 2022
@ghengeveld ghengeveld changed the title fix: normalize storiesEntryFiles in getDependentStoryFiles Fix TurboSnap support for Storybook in a subdirectory Mar 11, 2022
@ghengeveld ghengeveld changed the title Fix TurboSnap support for Storybook in a subdirectory Fix TurboSnap support for Storybook in a subdirectory (part 2) Mar 11, 2022
@ghengeveld
Copy link
Member

Released in 6.5.2.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants