Skip to content

Commit eac0fc0

Browse files
authored
Merge pull request #20313 from mozilla/upgrade-storybook
chore(deps): Upgrade Storybook to v8
2 parents 02cc4c2 + 7fa292e commit eac0fc0

37 files changed

Lines changed: 1850 additions & 6971 deletions

File tree

.github/workflows/deploy-storybooks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ jobs:
6767
6868
- name: Build Storybooks for affected packages (PR)
6969
if: github.event_name == 'pull_request' && steps.check-affected.outputs.has_storybooks == 'true'
70-
run: npx nx affected -t build-storybook
70+
run: npx nx affected -t build-storybook --output-style=stream
7171

7272
- name: Build all Storybooks (main branch)
7373
if: github.event_name == 'push'
74-
run: npx nx run-many -t build-storybook
74+
run: npx nx run-many -t build-storybook --output-style=stream
7575

7676
- name: Organize Storybooks for deployment
7777
if: github.event_name == 'push' || steps.check-affected.outputs.has_storybooks == 'true'

_scripts/check-frozen.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
import { execSync } from 'child_process';
88

99
// Maintain List of frozen files here!
10-
const frozen: Array<{ pattern: string; reason: string }> = [
10+
const frozen: Array<{
11+
pattern: string;
12+
reason: string;
13+
exclude?: string;
14+
}> = [
1115
{
1216
pattern: 'packages/fxa-auth-server/lib/senders/email.js',
1317
reason: 'Files moved to libs/accounts/email-sender',
1418
},
1519
{
1620
pattern: 'packages/fxa-auth-server/lib/senders/(emails|renderer)/.*',
1721
reason: 'Files moved to libs/accounts/email-renderer',
22+
// storybook-email.ts is a Storybook utility that hasn't been migrated;
23+
// exempt it so the SB8 upgrade (and future storybook-only changes) can proceed.
24+
exclude: 'storybook-email\\.ts$',
1825
},
1926
{
2027
pattern: 'packages/fxa-auth-server/test/local/.*\\.(js|ts)$',
@@ -48,8 +55,9 @@ try {
4855
for (const x of frozen) {
4956
const re = new RegExp(x.pattern);
5057
const changedFiles = getChangedFiles();
58+
const excludeRe = x.exclude ? new RegExp(x.exclude) : null;
5159
for (const file of changedFiles) {
52-
if (re.test(file)) {
60+
if (re.test(file) && !excludeRe?.test(file)) {
5361
console.error(
5462
`🚫 Error: Cannot modify frozen file: ${file}\n Reason: ${x.reason}.\n`
5563
);
Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,63 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
import type { StorybookConfig } from '@storybook/html-webpack5';
5+
46
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
57
const path = require('path');
68

7-
export default {
9+
const storybookConfig: StorybookConfig = {
810
framework: {
911
name: '@storybook/html-webpack5',
1012
options: {},
1113
},
1214
stories: ['../src/**/*.stories.ts'],
1315
staticDirs: process.env.STORYBOOK_BUILD === 'true' ? undefined : ['..'],
14-
addons: [
15-
'@storybook/addon-webpack5-compiler-babel',
16-
'@storybook/addon-docs',
17-
'@storybook/addon-controls',
18-
'@storybook/addon-toolbars',
19-
],
20-
core: {
21-
builder: 'webpack5',
22-
},
23-
babel: async (options) => {
24-
const babelConfig = {
25-
...options,
26-
sourceType: 'unambiguous',
27-
presets: [
28-
[
29-
'@babel/preset-env',
30-
{
31-
targets: '> 0.25%, last 2 versions, not dead',
32-
},
33-
],
34-
'@babel/preset-typescript',
35-
],
36-
plugins: [],
37-
};
38-
console.log('babel config!');
39-
40-
return babelConfig;
41-
},
42-
43-
features: { storyStoreV7: true },
16+
addons: ['@storybook/addon-essentials'],
4417
// Added to resolve path aliases set in <projectRoot>/tsconfig.base.json
4518
// tsconfig.storybook.json is necessary to replace the *.ts extension in tsconfig.base.json
4619
// with a *.js extension. Other than that it should remain the same.
47-
async webpackFinal(config, { configType }) {
20+
async webpackFinal(config) {
21+
config.resolve = config.resolve || {};
4822
config.resolve.plugins = [
4923
new TsconfigPathsPlugin({
5024
configFile: path.resolve(__dirname, './tsconfig.storybook.json'),
5125
}),
5226
];
5327

54-
config.resolve.fallback = {
55-
// fs: false, // Keep this as it's the standard Storybook approach.
56-
// // This is often needed when using internal Node libs in the browser:
57-
// path: false,
58-
// os: false,
59-
// "http": require.resolve("stream-http"),
60-
// "https": require.resolve("https-browserify"),
61-
// // **Potential fix for fs** - by adding 'process' which is another common Node dependency
62-
// process: require.resolve('process/browser'),
63-
};
28+
config.resolve.fallback = {};
29+
30+
// Storybook v8 no longer injects a TS loader for html-webpack5 framework.
31+
// Wrap all rules in oneOf so this explicit TS rule takes priority.
32+
config.module = config.module || {};
33+
const existingRules = (config.module.rules || []).filter(
34+
(r): r is object => typeof r === 'object' && r !== null
35+
);
36+
config.module.rules = [
37+
{
38+
oneOf: [
39+
{
40+
test: /\.(ts|tsx)$/,
41+
loader: require.resolve('babel-loader'),
42+
options: {
43+
sourceType: 'unambiguous',
44+
presets: [
45+
[
46+
'@babel/preset-env',
47+
{ targets: '> 0.25%, last 2 versions, not dead' },
48+
],
49+
'@babel/preset-typescript',
50+
],
51+
plugins: [],
52+
},
53+
},
54+
...existingRules,
55+
],
56+
},
57+
];
58+
6459
return config;
6560
},
6661
};
62+
63+
export default storybookConfig;

libs/accounts/email-renderer/.storybook/preview.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
// @ts-expect-error — no CSS module declarations in this tsconfig
56
import '../src/storybook.css';
67

7-
export const parameters = {
8-
actions: { argTypesRegex: '^on[A-Z].*' },
9-
};
10-
118
export const globalTypes = {
129
direction: {
1310
name: 'Text directionality',

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,17 @@
205205
"@nx/webpack": "21.2.4",
206206
"@nx/workspace": "21.2.4",
207207
"@opentelemetry/semantic-conventions": "^1.32.0",
208-
"@storybook/addon-essentials": "7.6.17",
209-
"@storybook/addon-styling": "1.3.7",
210-
"@storybook/core-common": "7.6.20",
211-
"@storybook/core-server": "7.6.20",
212-
"@storybook/html-webpack5": "7.6.20",
213-
"@storybook/nextjs": "7.6.20",
214-
"@storybook/react-webpack5": "7.6.20",
208+
"@storybook/addon-actions": "^8.0.0",
209+
"@storybook/addon-essentials": "^8.0.0",
210+
"@storybook/addon-interactions": "^8.0.0",
211+
"@storybook/addon-links": "^8.0.0",
212+
"@storybook/blocks": "^8.0.0",
213+
"@storybook/core-common": "^8.0.0",
214+
"@storybook/core-server": "^8.0.0",
215+
"@storybook/html-webpack5": "^8.0.0",
216+
"@storybook/manager-api": "^8.0.0",
217+
"@storybook/react": "^8.0.0",
218+
"@storybook/react-webpack5": "^8.0.0",
215219
"@swc-node/register": "1.10.9",
216220
"@swc/cli": "0.6.0",
217221
"@swc/core": "1.11.11",
@@ -280,6 +284,8 @@
280284
"react-test-renderer": "^18.3.1",
281285
"reflect-metadata": "^0.2.1",
282286
"server-only": "^0.0.1",
287+
"storybook": "^8.0.0",
288+
"storybook-addon-mock": "^5.0.0",
283289
"stylelint": "^16.14.1",
284290
"stylelint-config-prettier": "^9.0.3",
285291
"stylelint-config-recommended-scss": "^14.0.0",

packages/fxa-auth-server/.storybook/main.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@ module.exports = {
1010
'../lib/senders/emails/**/*.stories.ts',
1111
],
1212
staticDirs: process.env.STORYBOOK_BUILD !== 'true' ? ['..'] : undefined,
13-
addons: [
14-
'@storybook/addon-docs',
15-
'@storybook/addon-controls',
16-
'@storybook/addon-toolbars',
17-
],
18-
core: {
19-
builder: 'webpack5',
20-
},
13+
addons: ['@storybook/addon-essentials'],
2114
framework: {
2215
name: '@storybook/html-webpack5',
2316
options: {},
2417
},
25-
features: { storyStoreV7: false },
2618
// Added to resolve path aliases set in <projectRoot>/tsconfig.base.json
2719
// tsconfig.storybook.json is necessary to replace the *.ts extension in tsconfig.base.json
2820
// with a *.js extension. Other than that it should remain the same.

packages/fxa-auth-server/.storybook/preview.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
import '../lib/senders/emails/storybook.css';
66

7-
export const parameters = {
8-
actions: { argTypesRegex: '^on[A-Z].*' },
9-
};
7+
export const parameters = {};
108

119
export const globalTypes = {
1210
direction: {

packages/fxa-auth-server/lib/senders/emails/storybook-email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// instead of NodeJS for DOM typings support
77
/* eslint-env browser */
88

9-
import { Story } from '@storybook/html';
9+
import { StoryFn as Story } from '@storybook/html';
1010
import Renderer from '../renderer';
1111
import { BrowserRendererBindings } from '../renderer/bindings-browser';
1212
import { ComponentTarget } from '../renderer/bindings';

packages/fxa-auth-server/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"subscription-reminders": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/subscription-reminders.ts",
5252
"audit-orphaned-stripe-accounts": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/audit-orphaned-customers.ts",
5353
"remove-unverified-accounts": "CONFIG_FILES='config/secrets.json' node -r esbuild-register ./scripts/remove-unverified-accounts.ts",
54-
"storybook": "NODE_OPTIONS=--openssl-legacy-provider storybook dev -p 6010 --no-version-updates ./",
54+
"storybook": "storybook dev -p 6010 --no-version-updates ./",
5555
"merge-ftl": "nx l10n-merge",
5656
"merge-ftl-test": "nx l10n-merge",
5757
"watch-ftl": "nx l10n-watch"
@@ -125,11 +125,6 @@
125125
"web-push": "3.4.4"
126126
},
127127
"devDependencies": {
128-
"@storybook/addon-controls": "7.4.6",
129-
"@storybook/addon-docs": "7.6.12",
130-
"@storybook/addon-toolbars": "7.0.23",
131-
"@storybook/html": "7.6.17",
132-
"@storybook/html-webpack5": "7.5.3",
133128
"@types/async-retry": "^1",
134129
"@types/chai": "^4.3.17",
135130
"@types/chai-as-promised": "^7",
@@ -193,7 +188,7 @@
193188
"sass": "^1.80.4",
194189
"simplesmtp": "0.3.35",
195190
"sinon": "^9.0.3",
196-
"storybook": "^7.6.21",
191+
"storybook": "^8.0.0",
197192
"through": "2.3.8",
198193
"ts-jest": "^29.1.2",
199194
"tsc-alias": "^1.8.8",

packages/fxa-payments-server/.storybook/addons.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)