diff --git a/code/addons/docs/template/stories/docspage/basic.stories.ts b/code/addons/docs/template/stories/docspage/basic.stories.ts index 46d78074ecf8..58a24a2eb472 100644 --- a/code/addons/docs/template/stories/docspage/basic.stories.ts +++ b/code/addons/docs/template/stories/docspage/basic.stories.ts @@ -7,15 +7,24 @@ export default { parameters: { chromatic: { disable: true } }, }; +/** + * A basic button + */ export const Basic = { args: { label: 'Basic' }, }; +/** + * Won't show up in DocsPage + */ export const Disabled = { args: { label: 'Disabled in DocsPage' }, parameters: { docs: { disable: true } }, }; +/** + * Another button, just to show multiple stories + */ export const Another = { args: { label: 'Another' }, }; diff --git a/code/lib/csf-plugin/src/index.ts b/code/lib/csf-plugin/src/index.ts index a69492ea13d8..037f156abf4b 100644 --- a/code/lib/csf-plugin/src/index.ts +++ b/code/lib/csf-plugin/src/index.ts @@ -1,21 +1,23 @@ import { createUnplugin } from 'unplugin'; +import fs from 'fs/promises'; import { loadCsf, enrichCsf, formatCsf } from '@storybook/csf-tools'; +import type { EnrichCsfOptions } from '@storybook/csf-tools'; -export interface CsfPluginOptions { - source?: boolean; -} +export type CsfPluginOptions = EnrichCsfOptions; const STORIES_REGEX = /\.(story|stories)\.[tj]sx?$/; const logger = console; -export const unplugin = createUnplugin((options: CsfPluginOptions) => { +export const unplugin = createUnplugin((options) => { return { name: 'unplugin-csf', - transformInclude(id) { + enforce: 'pre', + loadInclude(id) { return STORIES_REGEX.test(id); }, - transform(code) { + async load(fname) { + const code = await fs.readFile(fname, 'utf-8'); try { const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse(); enrichCsf(csf); diff --git a/code/lib/csf-tools/package.json b/code/lib/csf-tools/package.json index a27688c6b75d..77c7862f08a7 100644 --- a/code/lib/csf-tools/package.json +++ b/code/lib/csf-tools/package.json @@ -51,7 +51,6 @@ "devDependencies": { "@babel/generator": "^7.12.11", "@babel/parser": "^7.12.11", - "@babel/template": "^7.12.11", "@babel/traverse": "^7.12.11", "@types/fs-extra": "^9.0.6", "js-yaml": "^3.14.1", diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index 458713ea0d41..af2ff4365d0f 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -156,6 +156,8 @@ export class CsfFile { _storyExports: Record = {}; + _storyStatements: Record = {}; + _storyAnnotations: Record> = {}; _templates: Record = {}; @@ -283,6 +285,7 @@ export class CsfFile { return; } self._storyExports[exportName] = decl; + self._storyStatements[exportName] = node; let name = storyNameFromExport(exportName); if (self._storyAnnotations[exportName]) { logger.warn( diff --git a/code/lib/csf-tools/src/enrichCsf.test.ts b/code/lib/csf-tools/src/enrichCsf.test.ts index f2e7988f9453..a0bb3af2db25 100644 --- a/code/lib/csf-tools/src/enrichCsf.test.ts +++ b/code/lib/csf-tools/src/enrichCsf.test.ts @@ -4,17 +4,18 @@ import { dedent } from 'ts-dedent'; import { loadCsf, formatCsf } from './CsfFile'; import { enrichCsf, extractSource } from './enrichCsf'; +import type { EnrichCsfOptions } from './enrichCsf'; expect.addSnapshotSerializer({ print: (val: any) => val, test: (val) => true, }); -const enrich = (code: string) => { +const enrich = (code: string, options?: EnrichCsfOptions) => { // we don't actually care about the title const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse(); - enrichCsf(csf); + enrichCsf(csf, options); return formatCsf(csf); }; @@ -34,10 +35,11 @@ describe('enrichCsf', () => { }; export const Basic = () =>