Skip to content
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

Server: Fix .stories.yml support #22906

Merged
merged 1 commit into from Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion code/lib/cli/src/sandbox-templates.ts
Expand Up @@ -486,7 +486,6 @@ const internalTemplates = {
builder: '@storybook/builder-webpack5',
},
isInternal: true,
inDevelopment: true,
},
// 'internal/pnp': {
// ...baseTemplates['cra/default-ts'],
Expand Down
5 changes: 4 additions & 1 deletion code/presets/server-webpack/src/index.ts
Expand Up @@ -16,7 +16,10 @@ export const webpack: StorybookConfig['webpack'] = (config) => {
test: /\.stories\.ya?ml/,
use: [
require.resolve('@storybook/preset-server-webpack/dist/loader'),
require.resolve('yaml-loader'),
{
loader: require.resolve('yaml-loader'),
options: { asJSON: true },
},
],
},
];
Expand Down
3 changes: 2 additions & 1 deletion code/presets/server-webpack/src/loader.ts
Expand Up @@ -5,7 +5,8 @@ export default (content: string) => {
const after = compileCsfModule(JSON.parse(content));
return after;
} catch (e) {
//
// for debugging
console.log(content, e);
}
return content;
};
3 changes: 2 additions & 1 deletion code/renderers/server/package.json
Expand Up @@ -61,7 +61,8 @@
"@storybook/types": "7.1.0-alpha.26",
"@types/fs-extra": "^11.0.1",
"fs-extra": "^11.1.0",
"ts-dedent": "^2.0.0"
"ts-dedent": "^2.0.0",
"yaml": "^2.3.1"
},
"devDependencies": {
"typescript": "~4.9.3"
Expand Down
11 changes: 7 additions & 4 deletions code/renderers/server/src/preset.ts
@@ -1,11 +1,14 @@
import fs from 'fs-extra';
import yaml from 'yaml';
import { toId } from '@storybook/csf';
import type { StaticMeta } from '@storybook/csf-tools';
import type { IndexerOptions, IndexedStory, StoryIndexer } from '@storybook/types';

export const storyIndexers = (indexers: StoryIndexer[] | null) => {
const jsonIndexer = async (fileName: string, opts: IndexerOptions) => {
const json = await fs.readJson(fileName, 'utf-8');
const serverIndexer = async (fileName: string, opts: IndexerOptions) => {
const json = fileName.endsWith('.json')
? await fs.readJson(fileName, 'utf-8')
: yaml.parse((await fs.readFile(fileName, 'utf-8')).toString());
const meta: StaticMeta = {
title: json.title,
};
Expand All @@ -25,8 +28,8 @@ export const storyIndexers = (indexers: StoryIndexer[] | null) => {
};
return [
{
test: /(stories|story)\.json$/,
indexer: jsonIndexer,
test: /(stories|story)\.(json|ya?ml)$/,
indexer: serverIndexer,
},
...(indexers || []),
];
Expand Down
3 changes: 2 additions & 1 deletion code/yarn.lock
Expand Up @@ -7499,6 +7499,7 @@ __metadata:
fs-extra: ^11.1.0
ts-dedent: ^2.0.0
typescript: ~4.9.3
yaml: ^2.3.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -32376,7 +32377,7 @@ __metadata:
languageName: node
linkType: hard

"yaml@npm:^2.0.0":
"yaml@npm:^2.0.0, yaml@npm:^2.3.1":
version: 2.3.1
resolution: "yaml@npm:2.3.1"
checksum: ed4c21a907fb1cd60a25177612fa46d95064a144623d269199817908475fe85bef20fb17406e3bdc175351b6488056a6f84beb7836e8c262646546a0220188e3
Expand Down