Skip to content

Commit 3e7b21d

Browse files
authored
Migrate storybook to typescript (#2747)
1 parent af29b85 commit 3e7b21d

27 files changed

+2240
-1505
lines changed

.storybook/main.js .storybook/main.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
import type { StorybookConfig } from "@storybook/react-webpack5";
2+
13
/* globals __dirname:false */
24
const path = require("path");
35
const glob = require("glob");
46
const ROOT = path.resolve(__dirname, "..");
57
const PKGS = path.resolve(ROOT, "packages");
68
const STORIES = path.resolve(ROOT, "stories");
79

8-
const wrapForPnp = (packageName) => path.dirname(require.resolve(path.join(packageName, 'package.json')));
10+
const wrapForPnp = (packageName) =>
11+
path.dirname(require.resolve(path.join(packageName, "package.json")));
912

10-
module.exports = {
13+
const config: StorybookConfig = {
1114
webpackFinal: async (config) => {
1215
// Read all the victory packages and alias.
13-
glob
14-
.sync(path.join(PKGS, "victory*/package.json"))
15-
.forEach((pkgPath) => {
16-
const key = path.dirname(path.relative(PKGS, pkgPath));
16+
glob.sync(path.join(PKGS, "victory*/package.json")).forEach((pkgPath) => {
17+
const key = path.dirname(path.relative(PKGS, pkgPath));
18+
if (config?.resolve?.alias) {
1719
config.resolve.alias[key] = path.resolve(path.dirname(pkgPath));
18-
});
20+
}
21+
});
1922

2023
return config;
2124
},
2225

2326
addons: [
24-
"@storybook/addon-options/register",
27+
"@storybook/addon-essentials",
2528
{
2629
name: "@storybook/addon-storysource",
2730
options: {
@@ -49,4 +52,18 @@ module.exports = {
4952
},
5053
},
5154
},
55+
56+
typescript: {
57+
// typescript compilation check is disabled until we upgrade the babel version
58+
// which is required for the latest version of storybook to do typechecking
59+
// https://github.com/FormidableLabs/victory/issues/2746
60+
check: false,
61+
checkOptions: {
62+
typescript: {
63+
configFile: path.join(__dirname, "../tsconfig.base.json"),
64+
},
65+
},
66+
},
5267
};
68+
69+
export default config;

package.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@
4545
"@babel/preset-react": "7.18.6",
4646
"@babel/preset-typescript": "^7.17.12",
4747
"@changesets/cli": "^2.24.1",
48-
"@storybook/addon-actions": "^7.6.7",
49-
"@storybook/addon-options": "^5.3.21",
50-
"@storybook/addon-storysource": "^7.6.7",
48+
"@storybook/addon-storysource": "^7.6.10",
49+
"@storybook/addon-essentials": "^7.6.10",
5150
"@storybook/react": "^7.6.7",
5251
"@storybook/react-webpack5": "^7.6.7",
5352
"@svitejs/changesets-changelog-github-compact": "^0.1.1",
@@ -354,11 +353,10 @@
354353
]
355354
},
356355
"lint:root": {
357-
"command": "nps \"lint:base *.js .storybook scripts config demo stories test\"",
356+
"command": "nps \"lint:base *.js scripts config demo stories test\"",
358357
"files": [
359358
".eslintrc.js",
360359
"*.js",
361-
".storybook",
362360
"scripts",
363361
"config",
364362
"demo",
@@ -372,11 +370,10 @@
372370
]
373371
},
374372
"lint:root:fix": {
375-
"command": "pnpm run lint:root || nps \"lint:base --fix *.js .storybook scripts config demo stories test\"",
373+
"command": "pnpm run lint:root || nps \"lint:base --fix *.js scripts config demo stories test\"",
376374
"files": [
377375
".eslintrc.js",
378376
"*.js",
379-
".storybook",
380377
"scripts",
381378
"config",
382379
"demo",

0 commit comments

Comments
 (0)