Skip to content
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: Support valid globs #10926

Merged
merged 22 commits into from
May 29, 2020
Merged

Core: Support valid globs #10926

merged 22 commits into from
May 29, 2020

Conversation

ndelangen
Copy link
Member

Issue: #10772

What I did

The value of stories in main.js is supposed to be a valid glob. We plan to optimize storybook by moving from a regex evaluated in webpack to a glob evaluated by node.

But we made a mistake, when we wrote the original globs in our docs & CLI generators. It's actually an invalid glob, but it still works, because the glob-to-regex lib makes it work.

In the future instead of using a glob-to-regex we'll use glob solely.

I added instructions to migration.md & make the warning clearer on what's really happening.

We'll keep the invalid globs working in storybook for now, but they will break at some point in the future.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Does "at some point in the future" mean 7.0 or later?

If you want to do that optimization in a 6.x release, we should make the breaking change now. WDYT?

@ndelangen
Copy link
Member Author

7.0 or later yes

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

I'm so happy this is fixed <3

MIGRATION.md Outdated Show resolved Hide resolved
MIGRATION.md Outdated Show resolved Hide resolved
MIGRATION.md Outdated Show resolved Hide resolved
'../src/stories/components/Icon/Icon.mdx',
],
},
// DUMB GLOB
Copy link
Member

Choose a reason for hiding this comment

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

should this comment stay here? 😂

@ndelangen
Copy link
Member Author

So turns out, valid globs break webpack. I've investigating why, but it's not going well.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Looks good except for the FIXME.

Also can you provide a handful unit tests for this since it's complex and deserves a little documentation

lib/core/src/server/preview/to-require-context.js Outdated Show resolved Hide resolved
@ndelangen ndelangen requested a review from thomasbertet as a code owner May 27, 2020 18:27
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Nice! Didn't realize there were already unit tests in the other file 👍

@shilman shilman changed the title Fix/valid globs Core: Support valid globs May 27, 2020
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Couple more things

lib/core/src/server/preview/to-require-context.js Outdated Show resolved Hide resolved
lib/core/src/server/preview/to-require-context.js Outdated Show resolved Hide resolved
@ndelangen
Copy link
Member Author

So happy to have a found a solution, and a clean break on how to deal with the invalid globs in a backwards but future friendly way.

All we need to do to remove the bad behavior support is delete a few lines of code.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Two more 😅

addons/docs/docs/docspage.md Outdated Show resolved Hide resolved
lib/core/src/server/preview/to-require-context.ts Outdated Show resolved Hide resolved
@@ -57,13 +57,18 @@ export async function createPreviewEntry(options) {
if (stories && stories.length) {
entries.push(path.resolve(path.join(configDir, `generated-stories-entry.js`)));

const files = (await Promise.all(stories.map((g) => glob(g)))).reduce((a, b) => a.concat(b));
const files = (
await Promise.all(stories.map((g) => glob(path.join(configDir, g))))
Copy link
Contributor

Choose a reason for hiding this comment

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

@ndelangen Is this correct? I don't think it makes sense to join the glob with the configDir. This means that all globs before this pr won't work anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

yes this is intentional indeed.

Copy link
Member

Choose a reason for hiding this comment

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

@ndelangen if this is a breaking change do we need to document it in MIGRATION.md?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is def a breaking change that should be documented. But it seems really odd to me that your glob become .storybook/**/*.stories. IDK when I would ever want that. In reality it always must be something like .storybook/../**/*.stories.

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

Successfully merging this pull request may close these issues.

4 participants