Skip to content

Commit

Permalink
fix: workarounds for storybook emotion v10
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Dec 4, 2020
1 parent 1f305ea commit b7be12b
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 450 deletions.
6 changes: 3 additions & 3 deletions examples/custom-pages-storybook-6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"@babel/preset-react": "^7.9.4",
"@component-controls/storybook": "^1.44.1",
"@component-controls/storybook-custom-docs": "^1.41.1",
"@storybook/addon-docs": "^6.1.3",
"@storybook/client-api": "^6.1.3",
"@storybook/react": "^6.1.3",
"@storybook/addon-docs": "^6.2.0-alpha.3",
"@storybook/client-api": "^6.2.0-alpha.3",
"@storybook/react": "^6.2.0-alpha.3",
"babel-loader": "^8.1.0",
"prop-types": "^15.7.2",
"react": "^17.0.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/storybook-6-no-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@component-controls/store": "^1.44.1",
"@component-controls/storybook": "^1.44.1",
"@component-controls/viewport-plugin": "^1.44.1",
"@storybook/react": "^6.1.3",
"@storybook/react": "^6.2.0-alpha.3",
"babel-loader": "^8.0.6",
"babel-preset-react-app": "^9.0.0",
"cross-env": "^5.2.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/storybook-6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@component-controls/store": "^1.44.1",
"@component-controls/storybook": "^1.44.1",
"@component-controls/viewport-plugin": "^1.44.1",
"@storybook/addon-docs": "^6.1.3",
"@storybook/react": "^6.1.3",
"@storybook/addon-docs": "^6.2.0-alpha.3",
"@storybook/react": "^6.2.0-alpha.3",
"babel-loader": "^8.0.6",
"babel-preset-react-app": "^9.0.0",
"cross-env": "^5.2.0",
Expand Down
11 changes: 4 additions & 7 deletions integrations/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@
"@component-controls/store": "^1.44.1",
"@component-controls/storybook-custom-docs": "^1.41.1",
"@component-controls/webpack-configs": "^1.44.1",
"broadcast-channel": "^3.1.0",
"deepmerge": "^4.2.2",
"global": "^4.3.2",
"@emotion/styled": "^11.0.0",
"typescript": "^4.0.5"
},
"devDependencies": {
"@component-controls/ts-markdown-docs": "^1.37.0",
"@storybook/addons": "^6.1.3",
"@storybook/api": "^6.1.3",
"@storybook/client-api": "^6.1.3",
"@storybook/addons": "^6.2.0-alpha.3",
"@storybook/api": "^6.2.0-alpha.3",
"@storybook/client-api": "^6.2.0-alpha.3",
"@types/node": "^13.7.0",
"@types/react": "^16.9.34",
"polished": "^3.4.4",
"react": "^17.0.1"
},
"peerDependencies": {
Expand Down
51 changes: 16 additions & 35 deletions integrations/storybook/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { RuleSetRule } from 'webpack';
import path from 'path';
import { mergeWebpackConfig } from '@component-controls/webpack-configs';
const LoaderPlugin = require('@component-controls/loader/plugin');
import { PresetOptions, defaultRules } from './types';

const toPath = (p: string) => path.join(process.cwd(), p);

module.exports = {
config: (entry: any[] = []) => {
const result = [...entry];
Expand Down Expand Up @@ -43,51 +45,30 @@ module.exports = {

return result;
},

webpackFinal: (config: any = {}, options: PresetOptions = {}) => {
const mergedConfig = mergeWebpackConfig(
config,
options?.webpack || defaultRules,
{},
);
return {
const newConfig = {
...mergedConfig,
module: {
...mergedConfig.module,
rules: mergedConfig.module?.rules.map(r => {
return Array.isArray(r.use)
? {
...r,
use: r.use.map(use =>
(use as RuleSetRule).options && (use as RuleSetRule).options
? {
...(use as RuleSetRule),
options: {
...(use as any).options,
presets: Array.isArray((use as any).options?.presets)
? (use as any).options.presets.map(
(preset: any) => {
return Array.isArray(preset)
? preset.map(p =>
p.runtime
? { ...p, runtime: 'classic' }
: p,
)
: preset;
},
)
: undefined,
},
}
: use,
),
}
: r;
}),
},
plugins: [
...(mergedConfig.plugins as any),
new LoaderPlugin({ defaultConfigPath: '.storybook' }),
],
};
if (config._version > '6.0.0') {
newConfig.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
'@emotion/core': toPath('node_modules/@emotion/react'),
'emotion-theming': toPath('node_modules/@emotion/react'),
},
};
}
return newConfig;
},
};
8 changes: 4 additions & 4 deletions misc/storybook-custom-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"license": "MIT",
"devDependencies": {
"@component-controls/ts-markdown-docs": "^1.37.0",
"@storybook/addons": "^6.1.3",
"@storybook/api": "^6.1.3",
"@storybook/client-api": "^6.1.3",
"@storybook/core-events": "^6.1.3",
"@storybook/addons": "^6.2.0-alpha.3",
"@storybook/api": "^6.2.0-alpha.3",
"@storybook/client-api": "^6.2.0-alpha.3",
"@storybook/core-events": "^6.2.0-alpha.3",
"@types/react": "^16.9.34",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
]
},
"resolutions": {
"npm-packlist": "1.1.12"
"@emotion/styled": "11.0.0",
"npm-packlist": "1.1.12",
"**/react": "17.0.1",
"**/react-dom": "17.0.1"
}
}
Loading

0 comments on commit b7be12b

Please sign in to comment.