Enable TypeScript live update in Storybook (#5)

* chore: enable live TS in Storybook

* chore: 🤖 manually add tsconfig for storybook

* chore: 🤖 enable typescript for preset-chart-xy
This commit is contained in:
Krist Wongsuphasawat 2019-02-27 12:19:00 -08:00 committed by Yongjie Zhao
parent 3e05f6f143
commit 618f50b01b
6 changed files with 72 additions and 3 deletions

View File

@ -1,5 +1,6 @@
.babelrc .babelrc
.cache .cache
.cache-loader
.DS_Store .DS_Store
.eslintcache .eslintcache
.eslintignore .eslintignore

View File

@ -9,8 +9,8 @@
"build:esm": "NODE_ENV=production beemo babel --extensions=\".js,.jsx,.ts,.tsx\" ./src --out-dir esm/ --esm --minify --workspaces=\"@superset-ui/!(plugins-demo)\"", "build:esm": "NODE_ENV=production beemo babel --extensions=\".js,.jsx,.ts,.tsx\" ./src --out-dir esm/ --esm --minify --workspaces=\"@superset-ui/!(plugins-demo)\"",
"build:assets": "node ./buildAssets.js", "build:assets": "node ./buildAssets.js",
"commit": "git-cz", "commit": "git-cz",
"type": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(plugin-*)\" --noEmit", "type": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/((preset|plugin)-*)\" --noEmit",
"type:dts": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(plugin-*)\" --emitDeclarationOnly", "type:dts": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/((preset|plugin)-*)\" --emitDeclarationOnly",
"lint": "beemo create-config prettier && beemo eslint \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"", "lint": "beemo create-config prettier && beemo eslint \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "beemo create-config prettier && beemo eslint --fix \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"", "lint:fix": "beemo create-config prettier && beemo eslint --fix \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"",
"jest": "beemo jest --color --coverage --react", "jest": "beemo jest --color --coverage --react",

View File

@ -41,6 +41,10 @@
"@superset-ui/connection": "^0.10.0", "@superset-ui/connection": "^0.10.0",
"@superset-ui/translation": "^0.10.0", "@superset-ui/translation": "^0.10.0",
"babel-loader": "^8.0.4", "babel-loader": "^8.0.4",
"cache-loader": "^1.2.2",
"fork-ts-checker-webpack-plugin": "^0.4.9",
"thread-loader": "^1.2.0",
"ts-loader": "^5.2.0",
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"git-directory-deploy": "^1.5.1", "git-directory-deploy": "^1.5.1",
"react": "^16.6.0", "react": "^16.6.0",

View File

@ -1,4 +1,6 @@
const path = require('path'); const path = require('path');
const os = require('os');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// Export a function. Accept the base config as the only param. // Export a function. Accept the base config as the only param.
module.exports = (storybookBaseConfig, configType, defaultConfig) => { module.exports = (storybookBaseConfig, configType, defaultConfig) => {
@ -6,6 +8,13 @@ module.exports = (storybookBaseConfig, configType, defaultConfig) => {
// You can change the configuration based on that. // You can change the configuration based on that.
// 'PRODUCTION' is used when building the static version of storybook. // 'PRODUCTION' is used when building the static version of storybook.
defaultConfig.resolve = defaultConfig.resolve || {};
defaultConfig.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx'];
defaultConfig.plugins.push(new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
}));
defaultConfig.module.rules[0].use[0].options.plugins.push('@babel/plugin-syntax-dynamic-import'); defaultConfig.module.rules[0].use[0].options.plugins.push('@babel/plugin-syntax-dynamic-import');
defaultConfig.module.rules.push({ defaultConfig.module.rules.push({
@ -15,6 +24,28 @@ module.exports = (storybookBaseConfig, configType, defaultConfig) => {
use: defaultConfig.module.rules[0].use, use: defaultConfig.module.rules[0].use,
}); });
defaultConfig.module.rules.push({
test: /\.tsx?$/,
use: [
{ loader: 'cache-loader' },
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: os.cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
// transpile only in happyPack mode
// type checking is done via fork-ts-checker-webpack-plugin
happyPackMode: true,
},
},
],
});
// Return the altered config // Return the altered config
return defaultConfig; return defaultConfig;
}; };

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist",
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true
},
"include": ["./storybook/stories/**/*", "../superset-ui-*/src/**/*", "./src/**/*", "./spec/**/*"]
}

View File

@ -1,4 +1,14 @@
export default function adjustMargin(baseMargin = {}, minMargin = {}) { interface Margin {
top: number;
left: number;
bottom: number;
right: number;
}
export default function adjustMargin(
baseMargin: Partial<Margin> = {},
minMargin: Partial<Margin> = {},
) {
const { top = 0, left = 0, bottom = 0, right = 0 } = baseMargin; const { top = 0, left = 0, bottom = 0, right = 0 } = baseMargin;
const { const {
top: minTop = 0, top: minTop = 0,