Skip to content

Commit 9a77a4e

Browse files
authored
Merge pull request #32902 from storybookjs/version-non-patch-from-10.1.0-alpha.1
Release: Prerelease 10.1.0-alpha.2
2 parents 83906d0 + cbc00d5 commit 9a77a4e

File tree

46 files changed

+3129
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3129
-101
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ code/core/report
6565
node_modules/.svelte2tsx-language-server-files
6666

6767
*storybook.log
68+
69+
.junie

CHANGELOG.prerelease.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 10.1.0-alpha.2
2+
3+
- A11y: Add aria-selected attribute to tab buttons - [#32656](https://github.com/storybookjs/storybook/pull/32656), thanks @Nischit-Ekbote!
4+
- React: Experimental code examples - [#32813](https://github.com/storybookjs/storybook/pull/32813), thanks @kasperpeulen!
5+
- React: Implement manifests/component.json for React - [#32751](https://github.com/storybookjs/storybook/pull/32751), thanks @kasperpeulen!
6+
- React: Improve error handling of component manifest generation - [#32855](https://github.com/storybookjs/storybook/pull/32855), thanks @kasperpeulen!
7+
18
## 10.1.0-alpha.1
29

310
- CLI: Fix glob string formatting in csf-factories codemod - [#32880](https://github.com/storybookjs/storybook/pull/32880), thanks @yannbf!

code/.storybook/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const config = defineMain({
137137
features: {
138138
developmentModeForBuild: true,
139139
experimentalTestSyntax: true,
140+
experimentalComponentsManifest: true,
141+
experimentalCodeExamples: true,
140142
},
141143
staticDirs: [{ from: './bench/bundle-analyzer', to: '/bundle-analyzer' }],
142144
viteFinal: async (viteConfig, { configType }) => {

code/addons/docs/src/preset.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
33

44
import { logger } from 'storybook/internal/node-logger';
55
import type { Options, PresetProperty, StorybookConfigRaw } from 'storybook/internal/types';
6+
import { type CsfEnricher } from 'storybook/internal/types';
67

78
import type { CsfPluginOptions } from '@storybook/csf-plugin';
89

@@ -41,6 +42,8 @@ async function webpack(
4142

4243
const { csfPluginOptions = {}, mdxPluginOptions = {} } = options;
4344

45+
const enrichCsf = await options.presets.apply('experimental_enrichCsf');
46+
4447
const rehypeSlug = (await import('rehype-slug')).default;
4548
const rehypeExternalLinks = (await import('rehype-external-links')).default;
4649

@@ -100,7 +103,12 @@ async function webpack(
100103
...(webpackConfig.plugins || []),
101104

102105
...(csfPluginOptions
103-
? [(await import('@storybook/csf-plugin')).webpack(csfPluginOptions)]
106+
? [
107+
(await import('@storybook/csf-plugin')).webpack({
108+
...csfPluginOptions,
109+
enrichCsf,
110+
}),
111+
]
104112
: []),
105113
],
106114
resolve: {

code/builders/builder-vite/src/plugins/csf-plugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export async function csfPlugin(config: Options): Promise<Plugin> {
1212
// @ts-expect-error - not sure what type to use here
1313
addons.find((a) => [a, a.name].includes('@storybook/addon-docs'))?.options ?? {};
1414

15+
const enrichCsf = await presets.apply('experimental_enrichCsf');
16+
1517
// TODO: looks like unplugin can return an array of plugins
16-
return vite(docsOptions?.csfPluginOptions) as Plugin;
18+
return vite({
19+
...docsOptions?.csfPluginOptions,
20+
enrichCsf,
21+
}) as Plugin;
1722
}

code/core/src/common/presets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getInterpretedFile } from './utils/interpret-files';
2020
import { stripAbsNodeModulesPath } from './utils/strip-abs-node-modules-path';
2121
import { validateConfigurationFiles } from './utils/validate-configuration-files';
2222

23-
type InterPresetOptions = Omit<
23+
export type InterPresetOptions = Omit<
2424
CLIOptions &
2525
LoadOptions &
2626
BuilderOptions & { isCritical?: boolean; build?: StorybookConfigRaw['build'] },
@@ -321,7 +321,7 @@ export async function getPresets(
321321
const loadedPresets: LoadedPreset[] = await loadPresets(presets, 0, storybookOptions);
322322

323323
return {
324-
apply: async (extension: string, config: any, args = {}) =>
324+
apply: async (extension: string, config?: any, args = {}) =>
325325
applyPresets(loadedPresets, extension, config, args, storybookOptions),
326326
};
327327
}

code/core/src/common/utils/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
async function getPrettier() {
1+
export async function getPrettier() {
22
return import('prettier').catch((e) => ({
33
resolveConfig: async () => null,
44
format: (content: string) => content,

code/core/src/components/components/tabs/tabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export const Tabs: FC<TabsProps> = memo(
227227
actions.onSelect(id);
228228
}}
229229
role="tab"
230+
aria-selected={active}
230231
>
231232
{typeof title === 'function' ? <title /> : title}
232233
</TabButton>

code/core/src/core-server/build-static.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cp, mkdir } from 'node:fs/promises';
1+
import { cp, mkdir, writeFile } from 'node:fs/promises';
22
import { rm } from 'node:fs/promises';
33

44
import {
@@ -11,6 +11,7 @@ import {
1111
import { logger } from 'storybook/internal/node-logger';
1212
import { getPrecedingUpgrade, telemetry } from 'storybook/internal/telemetry';
1313
import type { BuilderOptions, CLIOptions, LoadOptions, Options } from 'storybook/internal/types';
14+
import { type ComponentManifestGenerator } from 'storybook/internal/types';
1415

1516
import { global } from '@storybook/global';
1617

@@ -163,6 +164,28 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
163164
initializedStoryIndexGenerator as Promise<StoryIndexGenerator>
164165
)
165166
);
167+
168+
if (features?.experimentalComponentsManifest) {
169+
const componentManifestGenerator: ComponentManifestGenerator = await presets.apply(
170+
'experimental_componentManifestGenerator'
171+
);
172+
const indexGenerator = await initializedStoryIndexGenerator;
173+
if (componentManifestGenerator && indexGenerator) {
174+
try {
175+
const manifests = await componentManifestGenerator(
176+
indexGenerator as unknown as import('storybook/internal/core-server').StoryIndexGenerator
177+
);
178+
await mkdir(join(options.outputDir, 'manifests'), { recursive: true });
179+
await writeFile(
180+
join(options.outputDir, 'manifests', 'components.json'),
181+
JSON.stringify(manifests)
182+
);
183+
} catch (e) {
184+
logger.error('Failed to generate manifests/components.json');
185+
logger.error(e instanceof Error ? e : String(e));
186+
}
187+
}
188+
}
166189
}
167190

168191
if (!core?.disableProjectJson) {

code/core/src/core-server/dev-server.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { logConfig } from 'storybook/internal/common';
22
import { logger } from 'storybook/internal/node-logger';
33
import { MissingBuilderError } from 'storybook/internal/server-errors';
44
import type { Options } from 'storybook/internal/types';
5+
import { type ComponentManifestGenerator } from 'storybook/internal/types';
56

67
import compression from '@polka/compression';
78
import polka from 'polka';
89
import invariant from 'tiny-invariant';
910

1011
import { telemetry } from '../telemetry';
11-
import type { StoryIndexGenerator } from './utils/StoryIndexGenerator';
12+
import { type StoryIndexGenerator } from './utils/StoryIndexGenerator';
1213
import { doTelemetry } from './utils/doTelemetry';
1314
import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders';
1415
import { getCachingMiddleware } from './utils/get-caching-middleware';
@@ -138,8 +139,35 @@ export async function storybookDevServer(options: Options) {
138139
throw indexError;
139140
}
140141

142+
const features = await options.presets.apply('features');
143+
if (features?.experimentalComponentsManifest) {
144+
app.use('/manifests/components.json', async (req, res) => {
145+
try {
146+
const componentManifestGenerator: ComponentManifestGenerator = await options.presets.apply(
147+
'experimental_componentManifestGenerator'
148+
);
149+
const indexGenerator = await initializedStoryIndexGenerator;
150+
if (componentManifestGenerator && indexGenerator) {
151+
const manifest = await componentManifestGenerator(
152+
indexGenerator as unknown as import('storybook/internal/core-server').StoryIndexGenerator
153+
);
154+
res.setHeader('Content-Type', 'application/json');
155+
res.end(JSON.stringify(manifest));
156+
return;
157+
}
158+
res.statusCode = 400;
159+
res.end('No component manifest generator configured.');
160+
return;
161+
} catch (e) {
162+
logger.error(e instanceof Error ? e : String(e));
163+
res.statusCode = 500;
164+
res.end(e instanceof Error ? e.toString() : String(e));
165+
return;
166+
}
167+
});
168+
}
141169
// Now the preview has successfully started, we can count this as a 'dev' event.
142-
doTelemetry(app, core, initializedStoryIndexGenerator, options);
170+
doTelemetry(app, core, initializedStoryIndexGenerator as Promise<StoryIndexGenerator>, options);
143171

144172
async function cancelTelemetry() {
145173
const payload = { eventType: 'dev' };

0 commit comments

Comments
 (0)