-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-docs: Replace source-loader with csf-plugin #19680
Merged
Merged
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2aff120
CSF-tools: Add source extraction WIP
shilman 45a8482
Clean up tests
shilman ff964c0
Reorder tests to avoid confusoin
shilman f7edd49
Add csf-plugin to replace source-loader
shilman 52fab18
Merge branch 'next' into shilman/csf-plugin
shilman f088942
Merge branch 'next' into shilman/csf-plugin
shilman a1ca59d
Fix linting errors
shilman 0e93478
Update code/lib/csf-plugin/README.md
shilman 96ca5a9
Merge branch 'shilman/csf-plugin' of github.com:storybookjs/storybook…
shilman 924e4df
Delete index.test.ts
shilman 4a9fc91
CSF plugin: Turn story comments into docs desciptions
shilman 2c4c25d
Added some testcases
shilman 87b2781
Turn this into a loader
shilman 6bbe7f3
Preserve indentation & cleanup
shilman a7cb5c2
Merge branch 'next' into shilman/csf-plugin
shilman 7d740f9
Provide migration instructions for source-loader
shilman d0cddf5
Fix csf-plugin to load "pre" & async for perf
shilman ec5dc1c
CSF-tools: Fix parameters merge for enrichCsf
shilman ffc9553
CsfPlugin: Fix options handling, add tests
shilman 789a21b
Fix typo [ci skip]
shilman 5954bd8
Fix comment [ci skip]
shilman 75f1cb6
Merge pull request #19684 from storybookjs/shilman/csf-plugin-docgen-…
shilman 498aa5f
Fix deepscan [ci skip]
shilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# CSF Plugin | ||
|
||
The CSF plugin reads CSF files and enriches their content via static analysis. | ||
It supports Webpack, Vite, and other bundlers using [unplugin](https://github.com/unjs/unplugin). | ||
|
||
## Source snippets | ||
|
||
CSF plugin can add static source snippets to each story. For example: | ||
|
||
```js | ||
export const Basic = () => <Button />; | ||
``` | ||
|
||
Would be transformed to: | ||
|
||
```js | ||
export const Basic = () => <Button />; | ||
Basic.parameers = { | ||
shilman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
storySource: { | ||
source: '() => <Button />', | ||
}, | ||
...Basic.parameters, | ||
}; | ||
``` | ||
|
||
This allows `@storybook/addon-docs` to display the static source snippet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "@storybook/csf-plugin", | ||
"version": "7.0.0-alpha.46", | ||
"description": "Enrich CSF files via static analysis", | ||
"keywords": [ | ||
"storybook" | ||
], | ||
"homepage": "https://github.com/storybookjs/storybook/tree/main/lib/csf-plugin", | ||
"bugs": { | ||
"url": "https://github.com/storybookjs/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybookjs/storybook.git", | ||
"directory": "lib/csf-plugin" | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/storybook" | ||
}, | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/esm/index.mjs", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"files": [ | ||
"dist/**/*", | ||
"README.md", | ||
"*.js", | ||
"*.d.ts" | ||
], | ||
"scripts": { | ||
"check": "../../../scripts/node_modules/.bin/tsc --noEmit", | ||
"prep": "node ../../../scripts/prepare.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shilman was there a reason not to use tsup for bundling this? |
||
}, | ||
"dependencies": { | ||
"@storybook/csf-tools": "7.0.0-alpha.46", | ||
"unplugin": "^0.10.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "~4.6.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"bundler": { | ||
"entries": [ | ||
"./src/index.ts" | ||
] | ||
}, | ||
"gitHead": "3ef14366115c56c1d45c0359ff681cc47ed50532" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createUnplugin } from 'unplugin'; | ||
import { loadCsf, enrichCsf, formatCsf } from '@storybook/csf-tools'; | ||
|
||
export interface CsfPluginOptions { | ||
source?: boolean; | ||
} | ||
|
||
const STORIES_REGEX = /\.(story|stories)\.[tj]sx?$/; | ||
|
||
const logger = console; | ||
|
||
export const unplugin = createUnplugin((options: CsfPluginOptions) => { | ||
return { | ||
name: 'unplugin-csf', | ||
transformInclude(id) { | ||
return STORIES_REGEX.test(id); | ||
}, | ||
transform(code) { | ||
try { | ||
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse(); | ||
enrichCsf(csf); | ||
return formatCsf(csf); | ||
} catch (err: any) { | ||
logger.warn(err.message); | ||
return code; | ||
} | ||
}, | ||
}; | ||
}); | ||
|
||
export const { vite, rollup, webpack, esbuild } = unplugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"strict": true | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": [ | ||
"src/**/*.test.*", | ||
"src/**/tests/**/*", | ||
"src/**/__tests__/**/*", | ||
"src/**/*.stories.*", | ||
"src/**/*.mockdata.*", | ||
"src/**/__testfixtures__/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to still accept this property with the purpose of warning users/throwing an error and directing them to the migration docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! 💯