From fd20e3b482056350f2eca48445b0863678387354 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Thu, 5 Oct 2023 11:48:42 -0700 Subject: [PATCH 1/7] CsfFile: Automatically extract componentPath --- code/lib/csf-tools/src/CsfFile.test.ts | 112 +++++++++++++++++++++++++ code/lib/csf-tools/src/CsfFile.ts | 16 ++++ 2 files changed, 128 insertions(+) diff --git a/code/lib/csf-tools/src/CsfFile.test.ts b/code/lib/csf-tools/src/CsfFile.test.ts index c57859e3fee5..95a98ab43ecb 100644 --- a/code/lib/csf-tools/src/CsfFile.test.ts +++ b/code/lib/csf-tools/src/CsfFile.test.ts @@ -1195,4 +1195,116 @@ describe('CsfFile', () => { `); }); }); + + describe('componenent paths', () => { + it('no component', () => { + const { indexInputs } = loadCsf( + dedent` + import { Component } from '../src/Component.js'; + export default { + title: 'custom foo title', + }; + + export const A = { + render: () => {}, + }; + `, + { makeTitle, fileName: 'foo/bar.stories.js' } + ).parse(); + + expect(indexInputs).toMatchInlineSnapshot(` + - type: story + importPath: foo/bar.stories.js + exportName: A + name: A + title: custom foo title + tags: [] + __id: custom-foo-title--a + `); + }); + + it('local component', () => { + const { indexInputs } = loadCsf( + dedent` + const Component = (props) =>
hello
; + + export default { + title: 'custom foo title', + component: Component, + }; + + export const A = { + render: () => {}, + }; + `, + { makeTitle, fileName: 'foo/bar.stories.js' } + ).parse(); + + expect(indexInputs).toMatchInlineSnapshot(` + - type: story + importPath: foo/bar.stories.js + exportName: A + name: A + title: custom foo title + tags: [] + __id: custom-foo-title--a + `); + }); + + it('imported component from file', () => { + const { indexInputs } = loadCsf( + dedent` + import { Component } from '../src/Component.js'; + export default { + title: 'custom foo title', + component: Component, + }; + + export const A = { + render: () => {}, + }; + `, + { makeTitle, fileName: 'foo/bar.stories.js' } + ).parse(); + + expect(indexInputs).toMatchInlineSnapshot(` + - type: story + importPath: foo/bar.stories.js + componentPath: ../src/Component.js + exportName: A + name: A + title: custom foo title + tags: [] + __id: custom-foo-title--a + `); + }); + + it('imported component from library', () => { + const { indexInputs } = loadCsf( + dedent` + import { Component } from 'some-library'; + export default { + title: 'custom foo title', + component: Component, + }; + + export const A = { + render: () => {}, + }; + `, + { makeTitle, fileName: 'foo/bar.stories.js' } + ).parse(); + + expect(indexInputs).toMatchInlineSnapshot(` + - type: story + importPath: foo/bar.stories.js + componentPath: some-library + exportName: A + name: A + title: custom foo title + tags: [] + __id: custom-foo-title--a + `); + }); + }); }); diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index 15ab39abdc45..4bf828236ad5 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -140,6 +140,8 @@ export class CsfFile { _fileName: string; + _componentPath?: string; + _makeTitle: (title: string) => string; _meta?: StaticMeta; @@ -200,6 +202,19 @@ export class CsfFile { } else if (['includeStories', 'excludeStories'].includes(p.key.name)) { (meta as any)[p.key.name] = parseIncludeExclude(p.value); } else if (p.key.name === 'component') { + let n = p.value; + if (t.isIdentifier(n)) { + const id = n.name; + const importStmt = program.body.find((stmt) => ( + t.isImportDeclaration(stmt) && stmt.specifiers.find((spec) => spec.local.name === id) + )) as t.ImportDeclaration; + if (importStmt) { + const { source } = importStmt; + if (t.isStringLiteral(source)) { + this._componentPath = source.value; + } + } + } const { code } = recast.print(p.value, {}); meta.component = code; } else if (p.key.name === 'tags') { @@ -567,6 +582,7 @@ export class CsfFile { return { type: 'story', importPath: this._fileName, + componentPath: this._componentPath, exportName, name: story.name, title: this.meta?.title, From 8c78f835a89b16fccc7dc80b7299bd4fa5558b9a Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Wed, 11 Oct 2023 11:15:52 +0800 Subject: [PATCH 2/7] Indexer: Add componentPath to to the indexer --- .../StoryIndexGenerator.deprecated.test.ts | 107 ++++++++++++- .../src/utils/StoryIndexGenerator.test.ts | 147 +++++++++++++++++- .../src/utils/StoryIndexGenerator.ts | 26 +++- .../src/componentPath/component.js | 1 + .../src/componentPath/extension.stories.js | 7 + .../src/componentPath/noExtension.stories.js | 7 + .../src/componentPath/package.stories.js | 7 + code/lib/csf-tools/src/CsfFile.ts | 16 +- code/lib/types/src/modules/indexer.ts | 2 + 9 files changed, 304 insertions(+), 16 deletions(-) create mode 100644 code/lib/core-server/src/utils/__mockdata__/src/componentPath/component.js create mode 100644 code/lib/core-server/src/utils/__mockdata__/src/componentPath/extension.stories.js create mode 100644 code/lib/core-server/src/utils/__mockdata__/src/componentPath/noExtension.stories.js create mode 100644 code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts index 60d700bad62e..6d7a7667efcb 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts @@ -119,6 +119,36 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { expect(await generator.getIndex()).toMatchInlineSnapshot(` Object { "entries": Object { + "componentpath-extension--story-one": Object { + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "nested-button--story-one": Object { "id": "nested-button--story-one", "importPath": "./src/nested/Button.stories.ts", @@ -182,6 +212,36 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { "title": "B", "type": "story", }, + "componentpath-extension--story-one": Object { + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "d--story-one": Object { "id": "d--story-one", "importPath": "./src/D.stories.jsx", @@ -339,6 +399,36 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { "title": "B", "type": "story", }, + "componentpath-extension--story-one": Object { + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "d--docs": Object { "id": "d--docs", "importPath": "./src/D.stories.jsx", @@ -448,6 +538,12 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { "d--story-one", "h--docs", "h--story-one", + "componentpath-extension--docs", + "componentpath-extension--story-one", + "componentpath-noextension--docs", + "componentpath-noextension--story-one", + "componentpath-package--docs", + "componentpath-package--story-one", "first-nested-deeply-f--docs", "first-nested-deeply-f--story-one", "nested-button--docs", @@ -1228,6 +1324,9 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { "componentreference--docs", "notitle--docs", "h--story-one", + "componentpath-extension--story-one", + "componentpath-noextension--story-one", + "componentpath-package--story-one", "first-nested-deeply-f--story-one", ] `); @@ -1246,7 +1345,7 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(loadCsfMock).toHaveBeenCalledTimes(7); + expect(loadCsfMock).toHaveBeenCalledTimes(10); loadCsfMock.mockClear(); await generator.getIndex(); @@ -1303,7 +1402,7 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(loadCsfMock).toHaveBeenCalledTimes(7); + expect(loadCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', false); @@ -1388,7 +1487,7 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(loadCsfMock).toHaveBeenCalledTimes(7); + expect(loadCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', true); @@ -1427,7 +1526,7 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(loadCsfMock).toHaveBeenCalledTimes(7); + expect(loadCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', true); diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts index fad7090789fe..dc3fc8321288 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -82,6 +82,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -113,6 +114,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "f--story-one": Object { + "componentPath": undefined, "id": "f--story-one", "importPath": "./src/F.story.ts", "name": "Story One", @@ -143,6 +145,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "stories--story-one": Object { + "componentPath": undefined, "id": "stories--story-one", "importPath": "./src/stories.ts", "name": "Story One", @@ -172,7 +175,41 @@ describe('StoryIndexGenerator', () => { expect(await generator.getIndex()).toMatchInlineSnapshot(` Object { "entries": Object { + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "nested-button--story-one": Object { + "componentPath": undefined, "id": "nested-button--story-one", "importPath": "./src/nested/Button.stories.ts", "name": "Story One", @@ -184,6 +221,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "second-nested-g--story-one": Object { + "componentPath": undefined, "id": "second-nested-g--story-one", "importPath": "./src/second-nested/G.stories.ts", "name": "Story One", @@ -213,6 +251,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -225,6 +264,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "b--story-one": Object { + "componentPath": undefined, "id": "b--story-one", "importPath": "./src/B.stories.ts", "name": "Story One", @@ -235,7 +275,41 @@ describe('StoryIndexGenerator', () => { "title": "B", "type": "story", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "d--story-one": Object { + "componentPath": undefined, "id": "d--story-one", "importPath": "./src/D.stories.jsx", "name": "Story One", @@ -247,6 +321,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "first-nested-deeply-f--story-one": Object { + "componentPath": undefined, "id": "first-nested-deeply-f--story-one", "importPath": "./src/first-nested/deeply/F.stories.js", "name": "Story One", @@ -257,6 +332,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "h--story-one": Object { + "componentPath": undefined, "id": "h--story-one", "importPath": "./src/H.stories.mjs", "name": "Story One", @@ -268,6 +344,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "nested-button--story-one": Object { + "componentPath": undefined, "id": "nested-button--story-one", "importPath": "./src/nested/Button.stories.ts", "name": "Story One", @@ -279,6 +356,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "second-nested-g--story-one": Object { + "componentPath": undefined, "id": "second-nested-g--story-one", "importPath": "./src/second-nested/G.stories.ts", "name": "Story One", @@ -323,6 +401,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "page--story-one": Object { + "componentPath": undefined, "id": "page--story-one", "importPath": "./src/nested/Page.stories.mdx", "name": "StoryOne", @@ -358,6 +437,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -382,6 +462,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "b--story-one": Object { + "componentPath": undefined, "id": "b--story-one", "importPath": "./src/B.stories.ts", "name": "Story One", @@ -392,6 +473,39 @@ describe('StoryIndexGenerator', () => { "title": "B", "type": "story", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "d--docs": Object { "id": "d--docs", "importPath": "./src/D.stories.jsx", @@ -405,6 +519,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "d--story-one": Object { + "componentPath": undefined, "id": "d--story-one", "importPath": "./src/D.stories.jsx", "name": "Story One", @@ -416,6 +531,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "first-nested-deeply-f--story-one": Object { + "componentPath": undefined, "id": "first-nested-deeply-f--story-one", "importPath": "./src/first-nested/deeply/F.stories.js", "name": "Story One", @@ -438,6 +554,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "h--story-one": Object { + "componentPath": undefined, "id": "h--story-one", "importPath": "./src/H.stories.mjs", "name": "Story One", @@ -449,6 +566,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "nested-button--story-one": Object { + "componentPath": undefined, "id": "nested-button--story-one", "importPath": "./src/nested/Button.stories.ts", "name": "Story One", @@ -460,6 +578,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "second-nested-g--story-one": Object { + "componentPath": undefined, "id": "second-nested-g--story-one", "importPath": "./src/second-nested/G.stories.ts", "name": "Story One", @@ -501,6 +620,12 @@ describe('StoryIndexGenerator', () => { "d--story-one", "h--docs", "h--story-one", + "componentpath-extension--docs", + "componentpath-extension--story-one", + "componentpath-noextension--docs", + "componentpath-noextension--story-one", + "componentpath-package--docs", + "componentpath-package--story-one", "first-nested-deeply-f--docs", "first-nested-deeply-f--story-one", "nested-button--docs", @@ -608,6 +733,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "b--story-one": Object { + "componentPath": undefined, "id": "b--story-one", "importPath": "./src/B.stories.ts", "name": "Story One", @@ -667,6 +793,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "b--story-one": Object { + "componentPath": undefined, "id": "b--story-one", "importPath": "./src/B.stories.ts", "name": "Story One", @@ -718,6 +845,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -762,6 +890,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "duplicate-a--story-one": Object { + "componentPath": undefined, "id": "duplicate-a--story-one", "importPath": "./duplicate/A.stories.js", "name": "Story One", @@ -773,6 +902,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "duplicate-a--story-two": Object { + "componentPath": undefined, "id": "duplicate-a--story-two", "importPath": "./duplicate/SecondA.stories.js", "name": "Story Two", @@ -832,6 +962,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "my-component-a--story-one": Object { + "componentPath": undefined, "id": "my-component-a--story-one", "importPath": "./docs-id-generation/A.stories.jsx", "name": "Story One", @@ -886,6 +1017,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -1009,6 +1141,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -1076,6 +1209,7 @@ describe('StoryIndexGenerator', () => { Object { "entries": Object { "a--story-one": Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "name": "Story One", @@ -1088,6 +1222,7 @@ describe('StoryIndexGenerator', () => { "type": "story", }, "b--story-one": Object { + "componentPath": undefined, "id": "b--story-one", "importPath": "./src/B.stories.ts", "name": "Story One", @@ -1151,6 +1286,7 @@ describe('StoryIndexGenerator', () => { "type": "docs", }, "my-component-b--story-one": Object { + "componentPath": undefined, "id": "my-component-b--story-one", "importPath": "./docs-id-generation/B.stories.jsx", "name": "Story One", @@ -1334,6 +1470,9 @@ describe('StoryIndexGenerator', () => { "componentreference--docs", "notitle--docs", "h--story-one", + "componentpath-extension--story-one", + "componentpath-noextension--story-one", + "componentpath-package--story-one", "first-nested-deeply-f--story-one", ] `); @@ -1352,7 +1491,7 @@ describe('StoryIndexGenerator', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(readCsfMock).toHaveBeenCalledTimes(7); + expect(readCsfMock).toHaveBeenCalledTimes(10); readCsfMock.mockClear(); await generator.getIndex(); @@ -1409,7 +1548,7 @@ describe('StoryIndexGenerator', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(readCsfMock).toHaveBeenCalledTimes(7); + expect(readCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', false); @@ -1494,7 +1633,7 @@ describe('StoryIndexGenerator', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(readCsfMock).toHaveBeenCalledTimes(7); + expect(readCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', true); @@ -1533,7 +1672,7 @@ describe('StoryIndexGenerator', () => { const generator = new StoryIndexGenerator([specifier], options); await generator.initialize(); await generator.getIndex(); - expect(readCsfMock).toHaveBeenCalledTimes(7); + expect(readCsfMock).toHaveBeenCalledTimes(10); generator.invalidate(specifier, './src/B.stories.ts', true); diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index 0f847b8917a1..3687ae6d281d 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -270,6 +270,27 @@ export class StoryIndexGenerator { ); } + /** + * Try to find the component path from a raw import string and return it in + * the same format as `importPath`. + * + * If no such file exists, assume that the import is from a package and + * return the raw path. + */ + resolveComponentPath(rawComponentPath: Path, absolutePath: Path) { + const absoluteComponentPath = path.resolve(path.dirname(absolutePath), rawComponentPath); + const candidates = ['', '.js', '.ts', '.jsx', '.tsx'].map( + (ext) => `${absoluteComponentPath}${ext}` + ); + const existing = candidates.find((candidate) => fs.existsSync(candidate)); + if (existing) { + const relativePath = path.relative(this.options.workingDir, existing); + return slash(normalizeStoryPath(relativePath)); + } + + return rawComponentPath; + } + async extractStories( specifier: NormalizedStoriesSpecifier, absolutePath: Path @@ -309,8 +330,10 @@ export class StoryIndexGenerator { const entries: ((StoryIndexEntryWithMetaId | DocsCacheEntry) & { tags: Tag[] })[] = indexInputs.map((input) => { const name = input.name ?? storyNameFromExport(input.exportName); + const componentPath = + input.rawComponentPath && this.resolveComponentPath(input.rawComponentPath, absolutePath); const title = input.title ?? defaultMakeTitle(); - // eslint-disable-next-line no-underscore-dangle + const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName)); const tags = (input.tags || []).concat('story'); @@ -321,6 +344,7 @@ export class StoryIndexGenerator { name, title, importPath, + componentPath, tags, }; }); diff --git a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/component.js b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/component.js new file mode 100644 index 000000000000..ff8b4c56321a --- /dev/null +++ b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/component.js @@ -0,0 +1 @@ +export default {}; diff --git a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/extension.stories.js b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/extension.stories.js new file mode 100644 index 000000000000..8a2b7cff9b7e --- /dev/null +++ b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/extension.stories.js @@ -0,0 +1,7 @@ +import component from './component.js'; + +export default { + component, +}; + +export const StoryOne = {}; diff --git a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/noExtension.stories.js b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/noExtension.stories.js new file mode 100644 index 000000000000..4bb5febc075f --- /dev/null +++ b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/noExtension.stories.js @@ -0,0 +1,7 @@ +import component from './component'; + +export default { + component, +}; + +export const StoryOne = {}; diff --git a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js new file mode 100644 index 000000000000..b218fc26b970 --- /dev/null +++ b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js @@ -0,0 +1,7 @@ +import component from 'component-package'; + +export default { + component, +}; + +export const StoryOne = {}; diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index 4bf828236ad5..7bb453a43a21 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -140,7 +140,7 @@ export class CsfFile { _fileName: string; - _componentPath?: string; + _rawComponentPath?: string; _makeTitle: (title: string) => string; @@ -202,16 +202,18 @@ export class CsfFile { } else if (['includeStories', 'excludeStories'].includes(p.key.name)) { (meta as any)[p.key.name] = parseIncludeExclude(p.value); } else if (p.key.name === 'component') { - let n = p.value; + const n = p.value; if (t.isIdentifier(n)) { const id = n.name; - const importStmt = program.body.find((stmt) => ( - t.isImportDeclaration(stmt) && stmt.specifiers.find((spec) => spec.local.name === id) - )) as t.ImportDeclaration; + const importStmt = program.body.find( + (stmt) => + t.isImportDeclaration(stmt) && + stmt.specifiers.find((spec) => spec.local.name === id) + ) as t.ImportDeclaration; if (importStmt) { const { source } = importStmt; if (t.isStringLiteral(source)) { - this._componentPath = source.value; + this._rawComponentPath = source.value; } } } @@ -582,7 +584,7 @@ export class CsfFile { return { type: 'story', importPath: this._fileName, - componentPath: this._componentPath, + rawComponentPath: this._rawComponentPath, exportName, name: story.name, title: this.meta?.title, diff --git a/code/lib/types/src/modules/indexer.ts b/code/lib/types/src/modules/indexer.ts index 4f0838bba05e..7a63a3c4dc41 100644 --- a/code/lib/types/src/modules/indexer.ts +++ b/code/lib/types/src/modules/indexer.ts @@ -107,6 +107,8 @@ export type IndexEntry = StoryIndexEntry | DocsIndexEntry; export type BaseIndexInput = { /** The file to import from e.g. the story file. */ importPath: Path; + /** The raw path/package to the file that provides meta.component, if one exists */ + rawComponentPath?: Path; /** The name of the export to import. */ exportName: ExportName; /** The name of the entry, auto-generated from {@link exportName} if unspecified. */ From 746914e5a075390df406b27b31eaa9b8dd2c8a94 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Wed, 11 Oct 2023 11:18:58 +0800 Subject: [PATCH 3/7] Clean up and add mjs/mts support --- code/lib/core-server/src/utils/StoryIndexGenerator.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index 3687ae6d281d..83fe289bcc64 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -279,10 +279,9 @@ export class StoryIndexGenerator { */ resolveComponentPath(rawComponentPath: Path, absolutePath: Path) { const absoluteComponentPath = path.resolve(path.dirname(absolutePath), rawComponentPath); - const candidates = ['', '.js', '.ts', '.jsx', '.tsx'].map( - (ext) => `${absoluteComponentPath}${ext}` - ); - const existing = candidates.find((candidate) => fs.existsSync(candidate)); + const existing = ['', '.js', '.ts', '.jsx', '.tsx', '.mjs', '.mts'] + .map((ext) => `${absoluteComponentPath}${ext}`) + .find((candidate) => fs.existsSync(candidate)); if (existing) { const relativePath = path.relative(this.options.workingDir, existing); return slash(normalizeStoryPath(relativePath)); From 51edf4aaa939c885aa74a748d2489aa856fc6952 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Wed, 11 Oct 2023 11:51:41 +0800 Subject: [PATCH 4/7] Fix CI --- .../src/utils/StoryIndexGenerator.ts | 1 + .../src/componentPath/package.stories.js | 1 + .../utils/__tests__/index-extraction.test.ts | 13 ++ .../src/utils/stories-json.test.ts | 186 ++++++++++++++++++ 4 files changed, 201 insertions(+) diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index 83fe289bcc64..eb00150157db 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -333,6 +333,7 @@ export class StoryIndexGenerator { input.rawComponentPath && this.resolveComponentPath(input.rawComponentPath, absolutePath); const title = input.title ?? defaultMakeTitle(); + // eslint-disable-next-line no-underscore-dangle const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName)); const tags = (input.tags || []).concat('story'); diff --git a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js index b218fc26b970..20509edcf2be 100644 --- a/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js +++ b/code/lib/core-server/src/utils/__mockdata__/src/componentPath/package.stories.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line import/no-unresolved import component from 'component-package'; export default { diff --git a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts index 39820b3e2c17..599105fcf59d 100644 --- a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts +++ b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts @@ -68,6 +68,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": "a", @@ -80,6 +81,7 @@ describe('story extraction', () => { "type": "story", }, Object { + "componentPath": undefined, "id": "some-fully-custom-id", "importPath": "./src/A.stories.js", "metaId": "custom-id", @@ -124,6 +126,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "f--story-one", "importPath": "./src/first-nested/deeply/F.stories.js", "metaId": undefined, @@ -171,6 +174,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/first-nested/deeply/F.stories.js", "metaId": "a", @@ -219,6 +223,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": "a", @@ -285,6 +290,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -297,6 +303,7 @@ describe('story extraction', () => { "type": "story", }, Object { + "componentPath": undefined, "id": "custom-title--story-two", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -309,6 +316,7 @@ describe('story extraction', () => { "type": "story", }, Object { + "componentPath": undefined, "id": "custom-meta-id--story-three", "importPath": "./src/A.stories.js", "metaId": "custom-meta-id", @@ -354,6 +362,7 @@ describe('story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -417,6 +426,7 @@ describe('docs entries from story extraction', () => { "type": "docs", }, Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -478,6 +488,7 @@ describe('docs entries from story extraction', () => { "type": "docs", }, Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -527,6 +538,7 @@ describe('docs entries from story extraction', () => { "dependents": Array [], "entries": Array [ Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, @@ -589,6 +601,7 @@ describe('docs entries from story extraction', () => { "type": "docs", }, Object { + "componentPath": undefined, "id": "a--story-one", "importPath": "./src/A.stories.js", "metaId": undefined, diff --git a/code/lib/core-server/src/utils/stories-json.test.ts b/code/lib/core-server/src/utils/stories-json.test.ts index e1f0b1f6d613..9d1047741bab 100644 --- a/code/lib/core-server/src/utils/stories-json.test.ts +++ b/code/lib/core-server/src/utils/stories-json.test.ts @@ -158,6 +158,39 @@ describe('useStoriesJson', () => { "title": "B", "type": "story", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + "type": "story", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + "type": "story", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "name": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + "type": "story", + }, "d--story-one": Object { "id": "d--story-one", "importPath": "./src/D.stories.jsx", @@ -370,6 +403,57 @@ describe('useStoriesJson', () => { ], "title": "B", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "kind": "componentPath/extension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-extension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/extension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "kind": "componentPath/noExtension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-noextension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/noExtension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "kind": "componentPath/package", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-package--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/package.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + }, "d--story-one": Object { "id": "d--story-one", "importPath": "./src/D.stories.jsx", @@ -604,6 +688,57 @@ describe('useStoriesJson', () => { ], "title": "B", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "kind": "componentPath/extension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-extension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/extension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "kind": "componentPath/noExtension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-noextension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/noExtension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "kind": "componentPath/package", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-package--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/package.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + }, "d--story-one": Object { "id": "d--story-one", "importPath": "./src/D.stories.jsx", @@ -796,6 +931,57 @@ describe('useStoriesJson', () => { ], "title": "B", }, + "componentpath-extension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-extension--story-one", + "importPath": "./src/componentPath/extension.stories.js", + "kind": "componentPath/extension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-extension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/extension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/extension", + }, + "componentpath-noextension--story-one": Object { + "componentPath": "./src/componentPath/component.js", + "id": "componentpath-noextension--story-one", + "importPath": "./src/componentPath/noExtension.stories.js", + "kind": "componentPath/noExtension", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-noextension--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/noExtension.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/noExtension", + }, + "componentpath-package--story-one": Object { + "componentPath": "component-package", + "id": "componentpath-package--story-one", + "importPath": "./src/componentPath/package.stories.js", + "kind": "componentPath/package", + "name": "Story One", + "parameters": Object { + "__id": "componentpath-package--story-one", + "docsOnly": false, + "fileName": "./src/componentPath/package.stories.js", + }, + "story": "Story One", + "tags": Array [ + "story", + ], + "title": "componentPath/package", + }, "d--story-one": Object { "id": "d--story-one", "importPath": "./src/D.stories.jsx", From d61652d24bf850626150a510fd3dab3c87b95759 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 17 Nov 2023 18:53:15 +0800 Subject: [PATCH 5/7] Update snapshot --- code/lib/csf-tools/src/CsfFile.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/lib/csf-tools/src/CsfFile.test.ts b/code/lib/csf-tools/src/CsfFile.test.ts index 95a98ab43ecb..6f5622097257 100644 --- a/code/lib/csf-tools/src/CsfFile.test.ts +++ b/code/lib/csf-tools/src/CsfFile.test.ts @@ -1270,7 +1270,7 @@ describe('CsfFile', () => { expect(indexInputs).toMatchInlineSnapshot(` - type: story importPath: foo/bar.stories.js - componentPath: ../src/Component.js + rawComponentPath: ../src/Component.js exportName: A name: A title: custom foo title @@ -1298,7 +1298,7 @@ describe('CsfFile', () => { expect(indexInputs).toMatchInlineSnapshot(` - type: story importPath: foo/bar.stories.js - componentPath: some-library + rawComponentPath: some-library exportName: A name: A title: custom foo title From c69d5366f23cf230bfad45840f9aa999ded3a127 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sat, 8 Jun 2024 11:37:30 +0800 Subject: [PATCH 6/7] Support tsconfig paths --- code/lib/core-server/package.json | 1 + .../src/utils/StoryIndexGenerator.ts | 30 ++++++++++++++++--- code/yarn.lock | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/code/lib/core-server/package.json b/code/lib/core-server/package.json index 9f832722a45a..a9c5033a1866 100644 --- a/code/lib/core-server/package.json +++ b/code/lib/core-server/package.json @@ -96,6 +96,7 @@ "telejson": "^7.2.0", "tiny-invariant": "^1.3.1", "ts-dedent": "^2.0.0", + "tsconfig-paths": "^4.2.0", "util": "^0.12.4", "util-deprecate": "^1.0.2", "watchpack": "^2.2.0", diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index f75713dd9698..fd1eb40c9496 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -3,6 +3,8 @@ import chalk from 'chalk'; import fs from 'fs-extra'; import slash from 'slash'; import invariant from 'tiny-invariant'; +import * as TsconfigPaths from 'tsconfig-paths'; +import findUp from 'find-up'; import type { IndexEntry, @@ -280,13 +282,22 @@ export class StoryIndexGenerator { /** * Try to find the component path from a raw import string and return it in - * the same format as `importPath`. + * the same format as `importPath`. Respect tsconfig paths if available. * * If no such file exists, assume that the import is from a package and * return the raw path. */ - resolveComponentPath(rawComponentPath: Path, absolutePath: Path) { - const absoluteComponentPath = path.resolve(path.dirname(absolutePath), rawComponentPath); + resolveComponentPath( + rawComponentPath: Path, + absolutePath: Path, + matchPath: TsconfigPaths.MatchPath | undefined + ) { + let rawPath = rawComponentPath; + if (matchPath) { + rawPath = matchPath(rawPath) ?? rawPath; + } + + const absoluteComponentPath = path.resolve(path.dirname(absolutePath), rawPath); const existing = ['', '.js', '.ts', '.jsx', '.tsx', '.mjs', '.mts'] .map((ext) => `${absoluteComponentPath}${ext}`) .find((candidate) => fs.existsSync(candidate)); @@ -319,12 +330,23 @@ export class StoryIndexGenerator { invariant(indexer, `No matching indexer found for ${absolutePath}`); const indexInputs = await indexer.createIndex(absolutePath, { makeTitle: defaultMakeTitle }); + const tsconfigPath = await findUp('tsconfig.json', { cwd: this.options.workingDir }); + const tsconfig = TsconfigPaths.loadConfig(tsconfigPath); + let matchPath: TsconfigPaths.MatchPath | undefined; + if (tsconfig.resultType === 'success') { + matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [ + 'browser', + 'module', + 'main', + ]); + } const entries: ((StoryIndexEntryWithMetaId | DocsCacheEntry) & { tags: Tag[] })[] = indexInputs.map((input) => { const name = input.name ?? storyNameFromExport(input.exportName); const componentPath = - input.rawComponentPath && this.resolveComponentPath(input.rawComponentPath, absolutePath); + input.rawComponentPath && + this.resolveComponentPath(input.rawComponentPath, absolutePath, matchPath); const title = input.title ?? defaultMakeTitle(); // eslint-disable-next-line no-underscore-dangle diff --git a/code/yarn.lock b/code/yarn.lock index 0d2f161d0f94..b1ddfe6b5077 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6002,6 +6002,7 @@ __metadata: telejson: "npm:^7.2.0" tiny-invariant: "npm:^1.3.1" ts-dedent: "npm:^2.0.0" + tsconfig-paths: "npm:^4.2.0" typescript: "npm:^5.3.2" util: "npm:^0.12.4" util-deprecate: "npm:^1.0.2" From a57e45c10d508af24f01c14b08786d5d99c5fb19 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 9 Jun 2024 18:43:23 +0800 Subject: [PATCH 7/7] Add indexer API docs --- code/lib/types/src/modules/indexer.ts | 2 +- docs/api/main-config-indexers.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/code/lib/types/src/modules/indexer.ts b/code/lib/types/src/modules/indexer.ts index b01c0fb697b6..a34a2422766c 100644 --- a/code/lib/types/src/modules/indexer.ts +++ b/code/lib/types/src/modules/indexer.ts @@ -93,7 +93,7 @@ export type IndexEntry = StoryIndexEntry | DocsIndexEntry; export type BaseIndexInput = { /** The file to import from e.g. the story file. */ importPath: Path; - /** The raw path/package to the file that provides meta.component, if one exists */ + /** The raw path/package of the file that provides meta.component, if one exists */ rawComponentPath?: Path; /** The name of the export to import. */ exportName: ExportName; diff --git a/docs/api/main-config-indexers.md b/docs/api/main-config-indexers.md index 79e7fa2f2651..a2b17648ed40 100644 --- a/docs/api/main-config-indexers.md +++ b/docs/api/main-config-indexers.md @@ -97,6 +97,7 @@ Type: exportName: string; importPath: string; type: 'story'; + rawComponentPath?: string; metaId?: string; name?: string; tags?: string[]; @@ -133,6 +134,12 @@ Type: `'story'` The type of entry. +##### `rawComponentPath` + +Type: `string` + +The raw path/package of the file that provides `meta.component`, if one exists. + ##### `metaId` Type: `string`