Skip to content

Commit 5dbc106

Browse files
author
Taylor
committed
[heft] update storybook to be compatible with v9
Also adds support for serve mode detection when using the heft-rspack-plugin
1 parent 98d7c1a commit 5dbc106

File tree

16 files changed

+1490
-5347
lines changed

16 files changed

+1490
-5347
lines changed

build-tests-samples/heft-storybook-react-tutorial-storykit/package.json

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,24 @@
1212
},
1313
"devDependencies": {
1414
"@babel/core": "~7.20.0",
15-
"@storybook/addon-actions": "~6.4.18",
16-
"@storybook/addon-essentials": "~6.4.18",
17-
"@storybook/addon-links": "~6.4.18",
18-
"@storybook/cli": "~6.4.18",
19-
"@storybook/components": "~6.4.18",
20-
"@storybook/core-events": "~6.4.18",
21-
"@storybook/react": "~6.4.18",
22-
"@storybook/theming": "~6.4.18",
15+
"@storybook/cli": "~9.1.6",
16+
"@storybook/react": "~9.1.6",
17+
"@storybook/react-webpack5": "~9.1.6",
2318
"@types/heft-jest": "1.0.1",
2419
"@types/node": "20.17.19",
25-
"@types/react-dom": "17.0.25",
26-
"@types/react": "17.0.74",
20+
"@types/react-dom": "~19.2.3",
21+
"@types/react": "~19.2.7",
2722
"@types/webpack-env": "1.18.8",
2823
"babel-loader": "~8.2.3",
2924
"css-loader": "~5.2.7",
3025
"jest": "~29.3.1",
31-
"react-dom": "~17.0.2",
32-
"react": "~17.0.2",
26+
"react-dom": "~19.2.1",
27+
"react": "~19.2.1",
3328
"style-loader": "~2.0.0",
3429
"terser-webpack-plugin": "~3.0.8",
3530
"typescript": "~5.8.2",
36-
"webpack": "~4.47.0"
31+
"webpack": "~5.98.0",
32+
"storybook": "~9.1.6",
33+
"@testing-library/dom": "~7.21.4"
3734
}
3835
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const path = require('path');
2+
13
module.exports = {
24
stories: ['../lib/**/*.stories.js'],
3-
addons: ['@storybook/addon-links', '@storybook/addon-essentials']
5+
// naively referencing the name of the package causes storybook to fail to resolve it
6+
framework: path.resolve(require.resolve('@storybook/react-webpack5/preset'), '..')
47
};

build-tests-samples/heft-storybook-react-tutorial/config/heft.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"webpack": {
2525
"taskDependencies": ["typescript"],
2626
"taskPlugin": {
27-
"pluginPackage": "@rushstack/heft-webpack4-plugin"
27+
"pluginPackage": "@rushstack/heft-webpack5-plugin"
2828
}
2929
},
3030
"storybook": {
@@ -33,8 +33,8 @@
3333
"pluginPackage": "@rushstack/heft-storybook-plugin",
3434
"options": {
3535
"storykitPackageName": "heft-storybook-react-tutorial-storykit",
36-
"cliPackageName": "@storybook/react",
37-
"cliCallingConvention": "storybook6",
36+
"cliPackageName": "storybook",
37+
"cliCallingConvention": "storybook9",
3838
"staticBuildOutputFolder": "dist-storybook"
3939
}
4040
}

build-tests-samples/heft-storybook-react-tutorial/package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"_phase:test": "heft run --only test -- --clean"
1313
},
1414
"dependencies": {
15-
"react-dom": "~17.0.2",
16-
"react": "~17.0.2",
15+
"react-dom": "~19.2.1",
16+
"react": "~19.2.1",
1717
"tslib": "~2.8.1"
1818
},
1919
"devDependencies": {
@@ -23,13 +23,14 @@
2323
"@rushstack/heft-lint-plugin": "workspace:*",
2424
"@rushstack/heft-storybook-plugin": "workspace:*",
2525
"@rushstack/heft-typescript-plugin": "workspace:*",
26-
"@rushstack/heft-webpack4-plugin": "workspace:*",
27-
"@rushstack/webpack4-module-minifier-plugin": "workspace:*",
28-
"@storybook/react": "~6.4.18",
26+
"@rushstack/heft-webpack5-plugin": "workspace:*",
27+
"@rushstack/webpack5-module-minifier-plugin": "workspace:*",
28+
"@storybook/react-webpack5": "~9.1.6",
29+
"@storybook/react": "~9.1.6",
2930
"@types/heft-jest": "1.0.1",
3031
"@types/node": "20.17.19",
31-
"@types/react": "17.0.74",
32-
"@types/react-dom": "17.0.25",
32+
"@types/react": "~19.2.7",
33+
"@types/react-dom": "~19.2.3",
3334
"@types/webpack-env": "1.18.8",
3435
"css-loader": "~5.2.7",
3536
"eslint": "~9.37.0",
@@ -39,6 +40,9 @@
3940
"source-map-loader": "~1.1.3",
4041
"style-loader": "~2.0.0",
4142
"typescript": "~5.8.2",
42-
"webpack": "~4.47.0"
43+
"webpack": "~5.98.0",
44+
"storybook": "~9.1.6",
45+
"@testing-library/dom": "~7.21.4",
46+
"@rushstack/module-minifier": "workspace:*"
4347
}
4448
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as React from 'react';
5-
import type { ComponentStory, ComponentMeta } from 'heft-storybook-react-tutorial-storykit';
4+
import type { Meta, StoryObj } from 'heft-storybook-react-tutorial-storykit';
65

76
import { ToggleSwitch } from './ToggleSwitch';
87

@@ -13,14 +12,15 @@ export default {
1312
leftColor: { control: 'color' },
1413
rightColor: { control: 'color' }
1514
}
16-
} as ComponentMeta<typeof ToggleSwitch>;
15+
} as Meta<typeof ToggleSwitch>;
1716

18-
const Template: ComponentStory<typeof ToggleSwitch> = (args) => <ToggleSwitch {...args} />;
19-
20-
// eslint-disable-next-line
21-
export const Primary: any = Template.bind({});
22-
Primary.args = {};
17+
export const Primary: StoryObj<typeof ToggleSwitch> = {
18+
args: {
19+
leftColor: '#880000',
20+
rightColor: '#008000'
21+
}
22+
};
2323

24-
// eslint-disable-next-line
25-
export const Secondary: any = Template.bind({});
26-
Secondary.args = {};
24+
export const Secondary: StoryObj<typeof ToggleSwitch> = {
25+
args: {}
26+
};

build-tests-samples/heft-storybook-react-tutorial/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// See LICENSE in the project root for license information.
33

44
import * as React from 'react';
5-
import * as ReactDOM from 'react-dom';
5+
import { createRoot } from 'react-dom/client';
66

77
import { ExampleApp } from './ExampleApp';
88

99
import './index.css';
1010

1111
const rootDiv: HTMLElement = document.getElementById('root') as HTMLElement;
12-
ReactDOM.render(<ExampleApp />, rootDiv);
12+
createRoot(rootDiv).render(<ExampleApp />);

build-tests-samples/heft-storybook-react-tutorial/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
"module": "esnext",
2525
"moduleResolution": "node",
26-
"target": "es5",
27-
"lib": ["es5", "scripthost", "es2015.collection", "es2015.promise", "es2015.iterable", "dom"]
26+
"target": "es2020",
27+
"lib": ["es2020", "scripthost", "dom"],
28+
"skipLibCheck": true
2829
},
2930
"include": ["src/**/*.ts", "src/**/*.tsx"],
3031
"exclude": ["node_modules", "lib"]

build-tests-samples/heft-storybook-react-tutorial/webpack.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const path = require('path');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
5-
const { ModuleMinifierPlugin, WorkerPoolMinifier } = require('@rushstack/webpack4-module-minifier-plugin');
5+
const { ModuleMinifierPlugin } = require('@rushstack/webpack5-module-minifier-plugin');
6+
const { WorkerPoolMinifier } = require('@rushstack/module-minifier');
67

78
/**
89
* If the "--production" command-line parameter is specified when invoking Heft, then the
@@ -57,7 +58,13 @@ function createWebpackConfig({ production }) {
5758
optimization: {
5859
minimizer: [
5960
new ModuleMinifierPlugin({
60-
minifier: new WorkerPoolMinifier(),
61+
minifier: new WorkerPoolMinifier({
62+
terserOptions: {
63+
ecma: 2020,
64+
mangle: true
65+
},
66+
verbose: true
67+
}),
6168
useSourceMap: true
6269
})
6370
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-storybook-plugin",
5+
"comment": "support storybook v9",
6+
"type": "minor"
7+
},
8+
{
9+
"packageName": "@rushstack/heft-storybook-plugin",
10+
"comment": "support serve mode with rspack",
11+
"type": "minor"
12+
}
13+
],
14+
"packageName": "@rushstack/heft-storybook-plugin"
15+
}

common/config/rush/browser-approved-packages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
"name": "@rushstack/rush-vscode-command-webview",
5151
"allowedCategories": [ "vscode-extensions" ]
5252
},
53+
{
54+
"name": "@storybook/react-webpack5",
55+
"allowedCategories": [ "libraries", "tests" ]
56+
},
57+
{
58+
"name": "@testing-library/dom",
59+
"allowedCategories": [ "tests" ]
60+
},
5361
{
5462
"name": "@ungap/structured-clone",
5563
"allowedCategories": [ "libraries" ]
@@ -98,6 +106,10 @@
98106
"name": "scheduler",
99107
"allowedCategories": [ "vscode-extensions" ]
100108
},
109+
{
110+
"name": "storybook",
111+
"allowedCategories": [ "tests" ]
112+
},
101113
{
102114
"name": "tslib",
103115
"allowedCategories": [ "libraries", "tests", "vscode-extensions" ]

0 commit comments

Comments
 (0)