Skip to content

Commit 619f838

Browse files
committed
Use dynamic import of slash
1 parent 954c76c commit 619f838

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

code/builders/builder-vite/src/codegen-entries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { loadPreviewOrConfigFile } from '@storybook/core-common';
22
import type { Options } from '@storybook/types';
3-
import slash from 'slash';
43
import { listStories } from './list-stories';
54

65
const absoluteFilesToImport = async (
@@ -14,6 +13,7 @@ const absoluteFilesToImport = async (
1413

1514
export async function generateVirtualStoryEntryCode(options: Options) {
1615
const { normalizePath } = await import('vite');
16+
const slash = await import('slash');
1717
const storyEntries = await listStories(options);
1818
const resolveMap = storyEntries.reduce<Record<string, string>>(
1919
(prev, entry) => ({ ...prev, [entry]: entry.replace(slash(process.cwd()), '.') }),

code/builders/builder-vite/src/codegen-iframe-script.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export async function generateIframeScriptCode(options: Options, projectRoot: st
1212
[],
1313
options
1414
);
15-
const configEntries = [...previewAnnotations]
16-
.filter(Boolean)
17-
.map((path) => processPreviewAnnotation(path, projectRoot));
15+
const configEntries = await Promise.all(
16+
[...previewAnnotations]
17+
.filter(Boolean)
18+
.map((path) => processPreviewAnnotation(path, projectRoot))
19+
);
1820

1921
const filesToImport = (files: string[], name: string) =>
2022
files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${el}'`).join('\n');

code/builders/builder-vite/src/codegen-modern-iframe-script.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export async function generateModernIframeScriptCode(options: Options, projectRo
1313
[],
1414
options
1515
);
16-
const previewAnnotationURLs = [...previewAnnotations, previewOrConfigFile]
17-
.filter(Boolean)
18-
.map((path) => processPreviewAnnotation(path, projectRoot));
16+
const previewAnnotationURLs = await Promise.all(
17+
[...previewAnnotations, previewOrConfigFile]
18+
.filter(Boolean)
19+
.map((path) => processPreviewAnnotation(path, projectRoot))
20+
);
1921

2022
// This is pulled out to a variable because it is reused in both the initial page load
2123
// and the HMR handler. We don't use the hot.accept callback params because only the changed

code/builders/builder-vite/src/list-stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as path from 'path';
2-
import slash from 'slash';
32
import { glob } from 'glob';
43
import { normalizeStories, commonGlobOptions } from '@storybook/core-common';
54

65
import type { Options } from '@storybook/types';
76

87
export async function listStories(options: Options) {
98
const { normalizePath } = await import('vite');
9+
const slash = await import('slash');
1010

1111
return (
1212
await Promise.all(

code/builders/builder-vite/src/utils/process-preview-annotation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { PreviewAnnotation } from '@storybook/types';
22
import { resolve, isAbsolute, relative } from 'path';
3-
import slash from 'slash';
43
import { stripAbsNodeModulesPath } from '@storybook/core-common';
54

65
/**
@@ -10,7 +9,12 @@ import { stripAbsNodeModulesPath } from '@storybook/core-common';
109
* For node_modules, we want bare imports (so vite can process them),
1110
* and for files in the user's source, we want URLs absolute relative to project root.
1211
*/
13-
export function processPreviewAnnotation(path: PreviewAnnotation | undefined, projectRoot: string) {
12+
export async function processPreviewAnnotation(
13+
path: PreviewAnnotation | undefined,
14+
projectRoot: string
15+
) {
16+
const slash = await import('slash');
17+
1418
// If entry is an object, take the first, which is the
1519
// bare (non-absolute) specifier.
1620
// This is so that webpack can use an absolute path, and

0 commit comments

Comments
 (0)