Skip to content

Commit

Permalink
Migrate storybook to typescript (#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonrobot authored Jan 29, 2024
1 parent af29b85 commit 3e7b21d
Show file tree
Hide file tree
Showing 27 changed files with 2,240 additions and 1,505 deletions.
33 changes: 25 additions & 8 deletions .storybook/main.js → .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import type { StorybookConfig } from "@storybook/react-webpack5";

/* globals __dirname:false */
const path = require("path");
const glob = require("glob");
const ROOT = path.resolve(__dirname, "..");
const PKGS = path.resolve(ROOT, "packages");
const STORIES = path.resolve(ROOT, "stories");

const wrapForPnp = (packageName) => path.dirname(require.resolve(path.join(packageName, 'package.json')));
const wrapForPnp = (packageName) =>
path.dirname(require.resolve(path.join(packageName, "package.json")));

module.exports = {
const config: StorybookConfig = {
webpackFinal: async (config) => {
// Read all the victory packages and alias.
glob
.sync(path.join(PKGS, "victory*/package.json"))
.forEach((pkgPath) => {
const key = path.dirname(path.relative(PKGS, pkgPath));
glob.sync(path.join(PKGS, "victory*/package.json")).forEach((pkgPath) => {
const key = path.dirname(path.relative(PKGS, pkgPath));
if (config?.resolve?.alias) {
config.resolve.alias[key] = path.resolve(path.dirname(pkgPath));
});
}
});

return config;
},

addons: [
"@storybook/addon-options/register",
"@storybook/addon-essentials",
{
name: "@storybook/addon-storysource",
options: {
Expand Down Expand Up @@ -49,4 +52,18 @@ module.exports = {
},
},
},

typescript: {
// typescript compilation check is disabled until we upgrade the babel version
// which is required for the latest version of storybook to do typechecking
// https://github.com/FormidableLabs/victory/issues/2746
check: false,
checkOptions: {
typescript: {
configFile: path.join(__dirname, "../tsconfig.base.json"),
},
},
},
};

export default config;
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "^7.17.12",
"@changesets/cli": "^2.24.1",
"@storybook/addon-actions": "^7.6.7",
"@storybook/addon-options": "^5.3.21",
"@storybook/addon-storysource": "^7.6.7",
"@storybook/addon-storysource": "^7.6.10",
"@storybook/addon-essentials": "^7.6.10",
"@storybook/react": "^7.6.7",
"@storybook/react-webpack5": "^7.6.7",
"@svitejs/changesets-changelog-github-compact": "^0.1.1",
Expand Down Expand Up @@ -354,11 +353,10 @@
]
},
"lint:root": {
"command": "nps \"lint:base *.js .storybook scripts config demo stories test\"",
"command": "nps \"lint:base *.js scripts config demo stories test\"",
"files": [
".eslintrc.js",
"*.js",
".storybook",
"scripts",
"config",
"demo",
Expand All @@ -372,11 +370,10 @@
]
},
"lint:root:fix": {
"command": "pnpm run lint:root || nps \"lint:base --fix *.js .storybook scripts config demo stories test\"",
"command": "pnpm run lint:root || nps \"lint:base --fix *.js scripts config demo stories test\"",
"files": [
".eslintrc.js",
"*.js",
".storybook",
"scripts",
"config",
"demo",
Expand Down
Loading

1 comment on commit 3e7b21d

@vercel
Copy link

@vercel vercel bot commented on 3e7b21d Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.