Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts"
},
"dependencies": {
"@storybook/source-loader": "workspace:*",
"estraverse": "^5.2.0",
"tiny-invariant": "^1.3.1"
},
Expand All @@ -57,6 +56,7 @@
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/router": "workspace:*",
"@storybook/source-loader": "workspace:*",
"@storybook/theming": "workspace:*",
"@types/react": "^16.14.34",
"@types/react-syntax-highlighter": "11.0.5",
Expand Down
15 changes: 6 additions & 9 deletions code/lib/csf-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ const logger = console;
export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
return {
name: 'unplugin-csf',
transformInclude(id) {
enforce: 'pre',
loadInclude(id) {
return STORIES_REGEX.test(id);
},
async transform(code, id) {
const sourceCode = await fs.readFile(id, 'utf-8');
async load(fname) {
const code = await fs.readFile(fname, 'utf-8');
try {
const makeTitle = (userTitle: string) => userTitle || 'default';
const csf = loadCsf(code, { makeTitle }).parse();
const csfSource = loadCsf(sourceCode, {
makeTitle,
}).parse();
enrichCsf(csf, csfSource, options);
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse();
enrichCsf(csf, options);
return formatCsf(csf, { sourceMaps: true });
} catch (err: any) {
// This can be called on legacy storiesOf files, so just ignore
Expand Down
Loading