-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Normalize paths exposed to vite-builder's storybook-stories.js
file
#22327
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.
Thanks for a very thorough PR description, and great detective work!
I've looked through #22171 and it doesn't look like that upgrade could cause issues anywhere else - but I can understand why it would cause this issue.
Please give me some time to review this, as I have to set up Windows emulation on my MacBook first.
return glob(slash(absolutePattern), { follow: true }); | ||
}) | ||
) | ||
).reduce((carry, stories) => carry.concat(stories), []); | ||
).reduce((carry, stories) => carry.concat(stories.map(normalizePath)), []); |
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.
Looking at the glob
documentation, it looks like there's a { posix: true }
option that might also solve this problem instead of normalizePath
from Vite. Could you try that out?
To be honest with you, I can't figure out which solution would be the most correct, so maybe it doesn't matter too much
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.
Hey Jeppe! Thanks for looking into this! No worries: I don't think this is urgent, I guess this just needs to be addressed before a full 7.1 release! I've just tried the posix
option, here's the output:
As stated in the glob
documentation:
- all paths are indeed converted back to forward slashes
- but they're also prefixed with
//?/
Here's a summary:
1/ Current stories
output:
['H:\\Tests\\vite-storybook-windows\\.storybook\\docs\\useAnything.docs.mdx']
2/ stories
output using { posix: true }
(*):
['//?/H:/Tests/vite-storybook-windows/.storybook/docs/useAnything.docs.mdx']
(*) This eventually raises an error:
importers[path] is not a function
(since path does not include the above prefix)
3/ Expected stories
output (ensured by this PR)
['H:/Tests/vite-storybook-windows/.storybook/docs/useAnything.docs.mdx']
My 2 cents
It seems like both my current implementation and using the { posix: true }
require us to map through the stories
array. Performance-wise this should be pretty similar but:
- running
normalizePath
is probably slightly heavier than just simply getting rid of the//?/
prefix - but in the mean time, it looks clearer/more self-explanatory because let's be honest, UNC paths do not feel quite natural.
- edit: also, despite
normalizePath
being possibly a bit heavier, relying on it might still be more flexible since it's tested on Vite's side and it could potentially support Vite-specific edge cases? (and we're in thebuilder-vite
package). I'm not sure this argument is relevant, though :D)
Still open to go either way if needed :-)
P.S.: I re-requested a review just in case, please let me know if I should avoid doing that in the future! 😬
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.
Thanks for taking the time to try it out! It definitely looks to me like we shouldn't use { posix: true }
, as we'd still need normalizePath
anyway.
@JReinhold does this need to be patched? the glob upgrade was not patched back to |
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.
Great work! 💪 After spending many hours, I finally managed to get a development setup on Windows working, and can confirm this PR fixes the issue.
Thanks for your patience! 😅
What I did
Context
I've finally found some time to upgrade from the 7.0 alpha. Because I am
ahead of my timean impatient and curious lad, I did not target the latest stable release, but instead went directly for the latest pre-release.The issue
Starting from
7.1.0-alpha.11
, one of my Storybooks stopped working and raised the following errors:Browser:
Vite server:
Where does it come from?
Notice how the above error displays non-normalized paths (
path\to\file
): this eventually causes errors since those single backslashes are interpreted as escaping characters.Basically, here's where the breaking difference seems to be coming from:
7.1.0-alpha.10
(glob@8.x
) returns['H:/Tests/vite-storybook-windows/.storybook/docs/useAnything.docs.mdx']
7.1.0-alpha.11
(glob@10.x
) returns['H:\\Tests\\vite-storybook-windows\\.storybook\\docs\\useAnything.docs.mdx']
I've came up with this quickfix, but:
glob
)glob
within Storybook's codebase because there might still remain undetected related issues?Checklist
MIGRATION.MD