Skip to content

Commit 0251c05

Browse files
authored
Merge pull request #29292 from storybookjs/version-non-patch-from-8.4.0-alpha.4
Release: Prerelease 8.4.0-alpha.5
2 parents 127c43a + 6e32f1c commit 0251c05

File tree

100 files changed

+626
-342
lines changed

Some content is hidden

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

100 files changed

+626
-342
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 8.3.5
2+
3+
- CLI: Update the React Native init to include v8 dependencies - [#29273](https://github.com/storybookjs/storybook/pull/29273), thanks @dannyhw!
4+
- Vitest plugin: Fix renamed export stories - [#29250](https://github.com/storybookjs/storybook/pull/29250), thanks @shilman!
5+
16
## 8.3.4
27

38
- Addon Test: Support story name as test description - [#29147](https://github.com/storybookjs/storybook/pull/29147), thanks @InfiniteXyy!

CHANGELOG.prerelease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 8.4.0-alpha.5
2+
3+
- Core: Migrate from `express` to `polka` - [#29230](https://github.com/storybookjs/storybook/pull/29230), thanks @43081j!
4+
- Core: Remove dependence on `file-system-cache` - [#29256](https://github.com/storybookjs/storybook/pull/29256), thanks @ndelangen!
5+
16
## 8.4.0-alpha.4
27

38
- Blocks: Prebundle `es-toolkit` - [#29259](https://github.com/storybookjs/storybook/pull/29259), thanks @JReinhold!

code/__mocks__/fs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const realpathSync = vi.fn();
1919
export const readdir = vi.fn();
2020
export const readdirSync = vi.fn();
2121
export const readlinkSync = vi.fn();
22+
export const mkdirSync = vi.fn();
2223

2324
export default {
2425
__setMockFiles,
@@ -29,4 +30,5 @@ export default {
2930
readdir,
3031
readdirSync,
3132
readlinkSync,
33+
mkdirSync,
3234
};

code/builders/builder-vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
"@types/find-cache-dir": "^3.2.1",
4848
"browser-assert": "^1.2.1",
4949
"es-module-lexer": "^1.5.0",
50-
"express": "^4.19.2",
5150
"find-cache-dir": "^3.0.0",
5251
"magic-string": "^0.30.0",
5352
"ts-dedent": "^2.0.0"
5453
},
5554
"devDependencies": {
56-
"@types/express": "^4.17.21",
5755
"@types/node": "^22.0.0",
5856
"glob": "^10.0.0",
57+
"polka": "^1.0.0-next.28",
58+
"sirv": "^2.0.4",
5959
"slash": "^5.0.0",
6060
"typescript": "^5.3.2",
6161
"vite": "^4.0.4"

code/builders/builder-vite/src/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { cp, readFile } from 'node:fs/promises';
33
import { join, parse } from 'node:path';
44

55
import { NoStatsForViteDevError } from 'storybook/internal/server-errors';
6-
import type { Options } from 'storybook/internal/types';
6+
import type { Middleware, Options } from 'storybook/internal/types';
77

8-
import type { RequestHandler } from 'express';
9-
import express from 'express';
8+
import sirv from 'sirv';
109
import { corePath } from 'storybook/core-path';
1110
import type { ViteDevServer } from 'vite';
1211

@@ -20,16 +19,18 @@ export { hasVitePlugins } from './utils/has-vite-plugins';
2019

2120
export * from './types';
2221

23-
function iframeMiddleware(options: Options, server: ViteDevServer): RequestHandler {
22+
function iframeMiddleware(options: Options, server: ViteDevServer): Middleware {
2423
return async (req, res, next) => {
25-
if (!req.url.match(/^\/iframe\.html($|\?)/)) {
24+
if (!req.url || !req.url.match(/^\/iframe\.html($|\?)/)) {
2625
next();
2726
return;
2827
}
28+
// the base isn't used for anything, but it's required by the URL constructor
29+
const url = new URL(req.url, 'http://localhost:6006');
2930

3031
// We need to handle `html-proxy` params for style tag HMR https://github.com/storybookjs/builder-vite/issues/266#issuecomment-1055677865
3132
// e.g. /iframe.html?html-proxy&index=0.css
32-
if (req.query['html-proxy'] !== undefined) {
33+
if (url.searchParams.has('html-proxy')) {
3334
next();
3435
return;
3536
}
@@ -40,7 +41,9 @@ function iframeMiddleware(options: Options, server: ViteDevServer): RequestHandl
4041
const generated = await transformIframeHtml(indexHtml, options);
4142
const transformed = await server.transformIndexHtml('/iframe.html', generated);
4243
res.setHeader('Content-Type', 'text/html');
43-
res.status(200).send(transformed);
44+
res.statusCode = 200;
45+
res.write(transformed);
46+
res.end();
4447
};
4548
}
4649

@@ -59,10 +62,14 @@ export const start: ViteBuilder['start'] = async ({
5962
server = await createViteServer(options as Options, devServer);
6063

6164
const previewResolvedDir = join(corePath, 'dist/preview');
62-
const previewDirOrigin = previewResolvedDir;
63-
64-
router.use(`/sb-preview`, express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));
65-
65+
router.use(
66+
'/sb-preview',
67+
sirv(previewResolvedDir, {
68+
maxAge: 300000,
69+
dev: true,
70+
immutable: true,
71+
})
72+
);
6673
router.use(iframeMiddleware(options as Options, server));
6774
router.use(server.middlewares);
6875

@@ -81,10 +88,8 @@ export const build: ViteBuilder['build'] = async ({ options }) => {
8188
const viteCompilation = viteBuild(options as Options);
8289

8390
const previewResolvedDir = join(corePath, 'dist/preview');
84-
const previewDirOrigin = previewResolvedDir;
8591
const previewDirTarget = join(options.outputDir || '', `sb-preview`);
86-
87-
const previewFiles = cp(previewDirOrigin, previewDirTarget, {
92+
const previewFiles = cp(previewResolvedDir, previewDirTarget, {
8893
filter: (src) => {
8994
const { ext } = parse(src);
9095
if (ext) {

code/builders/builder-vite/src/list-stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isAbsolute, join } from 'node:path';
33
import { commonGlobOptions, normalizeStories } from 'storybook/internal/common';
44
import type { Options } from 'storybook/internal/types';
55

6+
// eslint-disable-next-line depend/ban-dependencies
67
import { glob } from 'glob';
78
import slash from 'slash';
89

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function codeGeneratorPlugin(options: Options): Plugin {
5050
},
5151
config(config, { command }) {
5252
// If we are building the static distribution, add iframe.html as an entry.
53-
// In development mode, it's not an entry - instead, we use an express middleware
53+
// In development mode, it's not an entry - instead, we use a middleware
5454
// to serve iframe.html. The reason is that Vite's dev server (at the time of writing)
5555
// does not support virtual files as entry points.
5656
if (command === 'build') {

code/builders/builder-webpack5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"constants-browserify": "^1.0.0",
7373
"css-loader": "^6.7.1",
7474
"es-module-lexer": "^1.5.0",
75-
"express": "^4.19.2",
7675
"fork-ts-checker-webpack-plugin": "^8.0.0",
7776
"html-webpack-plugin": "^5.5.0",
7877
"magic-string": "^0.30.5",
@@ -95,6 +94,7 @@
9594
"@types/terser-webpack-plugin": "^5.2.0",
9695
"@types/webpack-hot-middleware": "^2.25.6",
9796
"pretty-hrtime": "^1.0.3",
97+
"sirv": "^2.0.4",
9898
"slash": "^5.0.0",
9999
"typescript": "^5.3.2"
100100
},

code/builders/builder-webpack5/src/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type { Builder, Options } from 'storybook/internal/types';
1212

1313
import { checkWebpackVersion } from '@storybook/core-webpack';
1414

15-
import express from 'express';
1615
import prettyTime from 'pretty-hrtime';
16+
import sirv from 'sirv';
1717
import { corePath } from 'storybook/core-path';
1818
import type { Configuration, Stats, StatsOptions } from 'webpack';
1919
import webpack, { ProgressPlugin } from 'webpack';
@@ -137,7 +137,7 @@ const starter: StarterFunction = async function* starterGeneratorFn({
137137
}
138138

139139
yield;
140-
const modulesCount = (await options.cache?.get('modulesCount').catch(() => {})) || 1000;
140+
const modulesCount = await options.cache?.get('modulesCount', 1000);
141141
let totalModules: number;
142142
let value = 0;
143143

@@ -147,7 +147,7 @@ const starter: StarterFunction = async function* starterGeneratorFn({
147147
const progress = { value, message: message.charAt(0).toUpperCase() + message.slice(1) };
148148
if (message === 'building') {
149149
// arg3 undefined in webpack5
150-
const counts = (arg3 && arg3.match(/(\d+)\/(\d+)/)) || [];
150+
const counts = (arg3 && arg3.match(/entries (\d+)\/(\d+)/)) || [];
151151
const complete = parseInt(counts[1], 10);
152152
const total = parseInt(counts[2], 10);
153153
if (!Number.isNaN(complete) && !Number.isNaN(total)) {
@@ -180,10 +180,14 @@ const starter: StarterFunction = async function* starterGeneratorFn({
180180
compilation = webpackDevMiddleware(compiler, middlewareOptions);
181181

182182
const previewResolvedDir = join(corePath, 'dist/preview');
183-
const previewDirOrigin = previewResolvedDir;
184-
185-
router.use(`/sb-preview`, express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));
186-
183+
router.use(
184+
'/sb-preview',
185+
sirv(previewResolvedDir, {
186+
maxAge: 300000,
187+
dev: true,
188+
immutable: true,
189+
})
190+
);
187191
router.use(compilation);
188192
router.use(webpackHotMiddleware(compiler, { log: false }));
189193

@@ -289,10 +293,8 @@ const builder: BuilderFunction = async function* builderGeneratorFn({ startTime,
289293
});
290294

291295
const previewResolvedDir = join(corePath, 'dist/preview');
292-
const previewDirOrigin = previewResolvedDir;
293296
const previewDirTarget = join(options.outputDir || '', `sb-preview`);
294-
295-
const previewFiles = cp(previewDirOrigin, previewDirTarget, {
297+
const previewFiles = cp(previewResolvedDir, previewDirTarget, {
296298
filter: (src) => {
297299
const { ext } = parse(src);
298300
if (ext) {

code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default async (
7272
docsOptions,
7373
entries,
7474
nonNormalizedStories,
75-
modulesCount = 1000,
75+
modulesCount,
7676
build,
7777
tagsOptions,
7878
] = await Promise.all([
@@ -86,7 +86,7 @@ export default async (
8686
presets.apply('docs'),
8787
presets.apply<string[]>('entries', []),
8888
presets.apply('stories', []),
89-
options.cache?.get('modulesCount').catch(() => {}),
89+
options.cache?.get('modulesCount', 1000),
9090
options.presets.apply('build'),
9191
presets.apply('tags', {}),
9292
]);

0 commit comments

Comments
 (0)