You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Storybook 8 the vite-plugin-turbosnap package was ported into @storybook/builder-vite
I had previously reported an issue with vite-plugin-turbosnap as on Windows it generates files paths for name and id using the system path separators (\\) instead of posix separators (/).
With Webpack, even on Windows, name and id always use posix separators. This has been assumed to always be the case for the chromatic-cli tool.
With the current preview-stats.json file generated by builder-vite, it is incompatible with turbosnap in Chromatic.
To fix this, the normalize function in webpack-stats-plugin.ts needs to be modified to convert workingDir and filename to posix paths, using the same posix transformer as chromatic-cli.
export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): WebpackStatsPlugin {
+ // Replaces Windows-style backslash path separators with POSIX-style forward slashes, because the+ // Webpack stats use forward slashes in the `name` and `moduleName` fields. Note `changedFiles`+ // already contains forward slashes, because that's what git yields even on Windows.+ const posix = (localPath: string) => localPath.split(path.sep).filter(Boolean).join(path.posix.sep);
/**
* Convert an absolute path name to a path relative to the vite root, with a starting `./`
*/
function normalize(filename: string) {
// Do not try to resolve virtual files
if (filename.startsWith('/virtual:')) {
return filename;
}
// Otherwise, we need them in the format `./path/to/file.js`.
else {
+ const posixWorkingDir = posix(workingDir);+ const posixFilename = posix(filename);+ const relativePath = path.posix.relative(posixWorkingDir, stripQueryParams(posixFilename));- const relativePath = path.relative(workingDir, stripQueryParams(filename));
// This seems hacky, got to be a better way to add a `./` to the start of a path.
return `./${relativePath}`;
}
}
To Reproduce
Create a storybook project using builder-vite
Run storybook build --stats-json on a Window environment
Check the name and id fields in storybook-static/preview-stats.json for Windows path separators
Describe the bug
In Storybook 8 the vite-plugin-turbosnap package was ported into
@storybook/builder-vite
I had previously reported an issue with
vite-plugin-turbosnap
as on Windows it generates files paths forname
andid
using the system path separators (\\
) instead of posix separators (/
).With Webpack, even on Windows,
name
andid
always use posix separators. This has been assumed to always be the case for the chromatic-cli tool.With the current preview-stats.json file generated by builder-vite, it is incompatible with turbosnap in Chromatic.
To fix this, the
normalize
function in webpack-stats-plugin.ts needs to be modified to convertworkingDir
andfilename
to posix paths, using the same posix transformer as chromatic-cli.To Reproduce
storybook build --stats-json
on a Window environmentname
andid
fields instorybook-static/preview-stats.json
for Windows path separatorsSystem
Additional context
No response
The text was updated successfully, but these errors were encountered: