Skip to content

Commit 3d2a071

Browse files
committed
updated generate-stories-script
1 parent 041ba12 commit 3d2a071

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

packages/storybook-builder/src/generate-stories-script.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
// based on https://github.com/storybookjs/storybook/blob/v8.5.0/code/builders/builder-vite/src/codegen-importfn-script.ts
22

33
import { normalizePath } from '@rollup/pluginutils';
4-
import { logger } from '@storybook/node-logger';
54
import type { Options } from '@storybook/types';
6-
import { extname, relative } from 'node:path';
7-
import { listStories } from './list-stories.js';
5+
import { relative } from 'node:path';
6+
import { listStories } from './list-stories';
87

9-
/**
10-
* This file is largely based on https://github.com/storybookjs/storybook/blob/d1195cbd0c61687f1720fefdb772e2f490a46584/lib/core-common/src/utils/to-importFn.ts
11-
*/
12-
13-
export async function generateStoriesScript(options: Options) {
8+
export async function generateStoriesScript(options: Options): Promise<string> {
149
// First we need to get an array of stories and their absolute paths.
1510
const stories = await listStories(options);
1611

1712
// We can then call toImportFn to create a function that can be used to load each story dynamically.
18-
return (await toImportFn(stories)).trim();
13+
return await toImportFn(stories);
1914
}
2015

2116
/**
2217
* This function takes an array of stories and creates a mapping between the stories' relative paths
23-
* to the working directory and their dynamic imports. The import is done in an asynchronous function
24-
* to delay loading. It then creates a function, `importFn(path)`, which resolves a path to an import
25-
* function and this is called by Storybook to fetch a story dynamically when needed.
18+
* to the working directory and their dynamic imports. The import is done in an asynchronous
19+
* function to delay loading and to allow rollup to split the code into smaller chunks. It then
20+
* creates a function, `importFn(path)`, which resolves a path to an import function and this is
21+
* called by Storybook to fetch a story dynamically when needed.
22+
*
2623
* @param stories An array of absolute story paths.
2724
*/
2825
async function toImportFn(stories: string[]) {
2926
const objectEntries = stories.map(file => {
30-
const ext = extname(file);
3127
const relativePath = normalizePath(relative(process.cwd(), file));
32-
if (!['.js', '.jsx', '.ts', '.tsx', '.mdx', '.svelte', '.vue'].includes(ext)) {
33-
logger.warn(`Cannot process ${ext} file with storyStoreV7: ${relativePath}`);
34-
}
35-
3628
const importPath = toImportPath(relativePath);
3729
let actualPath = file;
3830
if (actualPath.endsWith('.mdx')) {

0 commit comments

Comments
 (0)