Skip to content

Commit

Permalink
Merge pull request #27098 from storybookjs/sihlman/fix-missing-defaul…
Browse files Browse the repository at this point in the history
…t-tags

Tags: Fix missing default tags if no `preview.js`
  • Loading branch information
shilman committed May 12, 2024
2 parents 5557550 + 256a6ee commit d9322ac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions code/lib/core-server/src/utils/StoryIndexGenerator.ts
Expand Up @@ -159,7 +159,7 @@ export class StoryIndexGenerator {
);

const previewCode = await this.getPreviewCode();
const projectTags = previewCode ? this.getProjectTags(previewCode) : [];
const projectTags = this.getProjectTags(previewCode);

// Extract stories for each file
await this.ensureExtracted({ projectTags });
Expand Down Expand Up @@ -556,7 +556,7 @@ export class StoryIndexGenerator {
if (this.lastError) throw this.lastError;

const previewCode = await this.getPreviewCode();
const projectTags = previewCode ? this.getProjectTags(previewCode) : [];
const projectTags = this.getProjectTags(previewCode);

// Extract any entries that are currently missing
// Pull out each file's stories into a list of stories, to be composed and sorted
Expand Down Expand Up @@ -665,11 +665,14 @@ export class StoryIndexGenerator {
return previewFile && (await fs.readFile(previewFile, 'utf-8')).toString();
}

getProjectTags(previewCode: string) {
const projectAnnotations = loadConfig(previewCode).parse();
getProjectTags(previewCode?: string) {
let projectTags = [];
const defaultTags = ['dev', 'test'];
const extraTags = this.options.docs.autodocs === true ? [AUTODOCS_TAG] : [];
const projectTags = projectAnnotations.getFieldValue(['tags']) ?? [];
if (previewCode) {
const projectAnnotations = loadConfig(previewCode).parse();
projectTags = projectAnnotations.getFieldValue(['tags']) ?? [];
}
return [...defaultTags, ...projectTags, ...extraTags];
}

Expand Down

0 comments on commit d9322ac

Please sign in to comment.