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

Vite: Use posix paths for glob #21013

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions code/lib/builder-vite/src/list-stories.ts
@@ -1,4 +1,4 @@
import * as path from 'path';
import * as posixPath from 'node:path/posix'; // Glob requires forward-slashes
Copy link
Member

Choose a reason for hiding this comment

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

import { join } from 'node:path/posix';? not sure if it makes a difference in node

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you prefer the destructured version? I slightly prefer the namespaced version, just because it's clear when it's being used where it's coming from. posixPath.join() vs just join(). But I don't feel strongly about it and happy to change if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

Don't feel strongly. I think @ndelangen was making a push towards the namespaced version (but maybe only in browser code, for tree shaking?), so maybe he can comment here.

import { promise as glob } from 'glob-promise';
import { normalizeStories } from '@storybook/core-common';

Expand All @@ -11,11 +11,14 @@ export async function listStories(options: Options) {
configDir: options.configDir,
workingDir: options.configDir,
}).map(({ directory, files }) => {
const pattern = path.join(directory, files);
const pattern = posixPath.join(directory, files);

return glob(path.isAbsolute(pattern) ? pattern : path.join(options.configDir, pattern), {
follow: true,
});
return glob(
posixPath.isAbsolute(pattern) ? pattern : posixPath.join(options.configDir, pattern),
{
follow: true,
}
);
})
)
).reduce((carry, stories) => carry.concat(stories), []);
Expand Down