Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate storybook to typescript #2747

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading