diff --git a/lib/core-server/src/build-static.ts b/lib/core-server/src/build-static.ts index 5e5d0d063b4f..5b03cb6be84d 100644 --- a/lib/core-server/src/build-static.ts +++ b/lib/core-server/src/build-static.ts @@ -101,6 +101,7 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions & await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories, { ...directories, storiesV2Compatibility: !features?.breakingChangesV7 && !features?.storyStoreV7, + storyStoreV7: features?.storyStoreV7, }); } diff --git a/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/lib/core-server/src/utils/StoryIndexGenerator.test.ts index a44a41dd91ce..35a9616887c1 100644 --- a/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -15,6 +15,7 @@ const options = { configDir: path.join(__dirname, '__mockdata__'), workingDir: path.join(__dirname, '__mockdata__'), storiesV2Compatibility: false, + storyStoreV7: true, }; describe('StoryIndexGenerator', () => { diff --git a/lib/core-server/src/utils/StoryIndexGenerator.ts b/lib/core-server/src/utils/StoryIndexGenerator.ts index b76d599c7053..80a52f1029c2 100644 --- a/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -16,19 +16,6 @@ import { logger } from '@storybook/node-logger'; import { readCsfOrMdx, getStorySortParameter } from '@storybook/csf-tools'; import { ComponentTitle } from '@storybook/csf'; -function sortExtractedStories( - stories: StoryIndex['stories'], - storySortParameter: any, - fileNameOrder: string[] -) { - const sortableStories = Object.values(stories); - sortStoriesV7(sortableStories, storySortParameter, fileNameOrder); - return sortableStories.reduce((acc, item) => { - acc[item.id] = item; - return acc; - }, {} as StoryIndex['stories']); -} - type SpecifierStoriesCache = Record; export class StoryIndexGenerator { @@ -47,6 +34,7 @@ export class StoryIndexGenerator { workingDir: Path; configDir: Path; storiesV2Compatibility: boolean; + storyStoreV7: boolean; } ) { this.storyIndexEntries = new Map(); @@ -132,8 +120,20 @@ export class StoryIndexGenerator { Object.assign(stories, subStories); }); - const storySortParameter = await this.getStorySortParameter(); - return sortExtractedStories(stories, storySortParameter, this.storyFileNames()); + const sortableStories = Object.values(stories); + + // Skip sorting if we're in v6 mode because we don't have + // all the info we need here + if (this.options.storyStoreV7) { + const storySortParameter = await this.getStorySortParameter(); + const fileNameOrder = this.storyFileNames(); + sortStoriesV7(sortableStories, storySortParameter, fileNameOrder); + } + + return sortableStories.reduce((acc, item) => { + acc[item.id] = item; + return acc; + }, {} as StoryIndex['stories']); } async getIndex() { diff --git a/lib/core-server/src/utils/stories-json.ts b/lib/core-server/src/utils/stories-json.ts index 2fbee370400d..611add9f4770 100644 --- a/lib/core-server/src/utils/stories-json.ts +++ b/lib/core-server/src/utils/stories-json.ts @@ -18,7 +18,12 @@ export const DEBOUNCE = 100; export async function extractStoriesJson( outputFile: string, normalizedStories: NormalizedStoriesSpecifier[], - options: { configDir: string; workingDir: string; storiesV2Compatibility: boolean } + options: { + configDir: string; + workingDir: string; + storiesV2Compatibility: boolean; + storyStoreV7: boolean; + } ) { const generator = new StoryIndexGenerator(normalizedStories, options); await generator.initialize(); @@ -42,6 +47,7 @@ export async function useStoriesJson( configDir: options.configDir, workingDir, storiesV2Compatibility: !features?.breakingChangesV7 && !features?.storyStoreV7, + storyStoreV7: features?.storyStoreV7, }); // Wait until someone actually requests `stories.json` before we start generating/watching.