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

Move react-docgen dependency to docs addon preset. #9533

Closed
Closed
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
1 change: 0 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ module.exports = {
'babel-plugin-macros',
['emotion', { sourceMap: true, autoLabel: true }],
'@babel/plugin-transform-react-constant-elements',
'babel-plugin-add-react-displayname',
],
env: {
test: withTests,
Expand Down
5 changes: 1 addition & 4 deletions addons/a11y/src/components/Report/HighlightToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,4 @@ class HighlightToggle extends Component<ToggleProps> {
}
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(HighlightToggle);
export default connect(mapStateToProps, mapDispatchToProps)(HighlightToggle);
5 changes: 4 additions & 1 deletion addons/contexts/src/manager/components/ToolBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe('Tests on addon-contexts component: ToolBar', () => {
icon: 'box' as const,
nodeId: 'Some Context B',
options: { cancelable: true, deep: false, disable: false },
params: [{ name: 'Some Param X', props: {} }, { name: 'Some Param Y', props: {} }],
params: [
{ name: 'Some Param X', props: {} },
{ name: 'Some Param Y', props: {} },
],
title: 'Some Context B',
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ describe('Tests on addon-contexts component: ToolBarControl', () => {
icon: 'box' as const,
nodeId: 'Some Context',
options: { cancelable: true, deep: false, disable: false },
params: [{ name: 'A', props: {} }, { name: 'B', props: {} }],
params: [
{ name: 'A', props: {} },
{ name: 'B', props: {} },
],
title: 'Some Context',
selected: '',
setSelected: jest.fn,
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"acorn": "^7.1.0",
"acorn-jsx": "^5.1.0",
"acorn-walk": "^7.0.0",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-react-docgen": "^4.1.0",
"core-js": "^3.0.1",
"doctrine": "^3.0.0",
"escodegen": "^1.12.0",
Expand Down
25 changes: 25 additions & 0 deletions addons/docs/src/frameworks/common/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import createCompiler from '@storybook/addon-docs/mdx-compiler-plugin';
import remarkSlug from 'remark-slug';
import remarkExternalLinks from 'remark-external-links';
import { TransformOptions } from '@babel/core';

function createBabelOptions(babelOptions?: any, configureJSX?: boolean) {
if (!configureJSX) {
return babelOptions;
}

const babelPlugins = (babelOptions && babelOptions.plugins) || [];

return {
...babelOptions,
// for frameworks that are not working with react, we need to configure
Expand All @@ -18,6 +20,29 @@ function createBabelOptions(babelOptions?: any, configureJSX?: boolean) {
};
}

// eslint-disable-next-line no-shadow
export function babel(config: TransformOptions) {
// Ensure plugins are defined or fallback to an array to avoid empty values.
const babelConfigPlugins = config.plugins || [];

const extraPlugins = [
[
'babel-plugin-react-docgen',
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
'babel-plugin-add-react-displayname',
],
];

// If `babelConfigPlugins` is not an `Array`, calling `concat` will inject it
// as a single value, if it is an `Array` it will spread.
return {
...config,
plugins: [].concat(babelConfigPlugins, extraPlugins),
};
}

export function webpack(webpackConfig: any = {}, options: any = {}) {
const { module = {} } = webpackConfig;
// it will reuse babel options that are already in use in storybook
Expand Down
2 changes: 0 additions & 2 deletions app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
"@storybook/node-logger": "5.3.7",
"@svgr/webpack": "^4.0.3",
"@types/webpack-env": "^1.15.0",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-named-asset-import": "^0.3.1",
"babel-plugin-react-docgen": "^4.0.0",
"core-js": "^3.0.1",
"global": "^4.3.2",
"lodash": "^4.17.15",
Expand Down
76 changes: 0 additions & 76 deletions app/react/src/server/framework-preset-react-docgen.test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions app/react/src/server/framework-preset-react-docgen.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/react/src/server/framework-preset-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function babelDefault(config: TransformOptions) {
plugins: [
...(config.plugins || []),
require.resolve('@babel/plugin-transform-react-constant-elements'),
require.resolve('babel-plugin-add-react-displayname'),
],
};
}
1 change: 0 additions & 1 deletion app/react/src/server/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default {
frameworkPresets: [
require.resolve('./framework-preset-react.js'),
require.resolve('./framework-preset-cra.js'),
require.resolve('./framework-preset-react-docgen.js'),
],
};
18 changes: 1 addition & 17 deletions examples/cra-ts-kitchen-sink/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@ const path = require('path');
module.exports = {
stories: ['../src/**/*.stories.(mdx|[tj]sx?)'],
addons: [
{
name: '@storybook/preset-create-react-app',
options: {
tsDocgenLoaderOptions: {
tsconfigPath: path.resolve(__dirname, '../tsconfig.json'),
shouldExtractLiteralValuesFromEnum: true,
propFilter: prop => {
// Currently not working, prop.parent is always null.
if (prop.parent) {
return !prop.parent.fileName.includes('node_modules/@types/react/');
}

return true;
},
},
},
},
'@storybook/preset-create-react-app',
'@storybook/addon-docs',
'@storybook/addon-actions',
'@storybook/addon-links',
Expand Down
2 changes: 1 addition & 1 deletion examples/cra-ts-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"devDependencies": {
"@storybook/addon-a11y": "5.3.7",
"@storybook/addon-actions": "5.3.7",
"@storybook/addon-docs": "5.3.7",
"@storybook/addon-info": "5.3.7",
"@storybook/addon-knobs": "5.3.7",
"@storybook/addon-links": "5.3.7",
Expand All @@ -50,7 +51,6 @@
"enzyme-adapter-react-16": "^1.9.1",
"enzyme-to-json": "^3.4.1",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"react-docgen-typescript-loader": "^3.3.0",
"react-moment-proptypes": "^1.7.0",
"react-scripts": "^3.0.1",
"tslint": "^5.14.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@ interface TypeScriptHtmlComponentProps {
text: string;
}

export const TypeScriptHtmlComponent: FC<
React.HTMLAttributes<HTMLDivElement> & TypeScriptHtmlComponentProps
> = () => <div>My HTML component</div>;
export const TypeScriptHtmlComponent: FC<React.HTMLAttributes<HTMLDivElement> &
TypeScriptHtmlComponentProps> = () => <div>My HTML component</div>;
5 changes: 4 additions & 1 deletion lib/components/src/tooltip/TooltipMessage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ storiesOf('basics/Tooltip/TooltipMessage', module)
<TooltipMessage
title="Lorem ipsum dolor sit"
desc="Amet consectatur vestibulum concet durum politu coret weirom"
links={[{ title: 'Get more tips', href: 'test' }, { title: 'Done', href: 'test' }]}
links={[
{ title: 'Get more tips', href: 'test' },
{ title: 'Done', href: 'test' },
]}
/>
))
.add('minimal message', () => (
Expand Down
8 changes: 3 additions & 5 deletions lib/components/src/tooltip/WithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ WithTooltipPure.defaultProps = {
tooltipShown: false,
};

const WithToolTipState: FunctionComponent<
WithTooltipPureProps & {
startOpen?: boolean;
}
> = ({ startOpen, ...rest }) => {
const WithToolTipState: FunctionComponent<WithTooltipPureProps & {
startOpen?: boolean;
}> = ({ startOpen, ...rest }) => {
const [tooltipShown, onVisibilityChange] = useState(startOpen || false);

useEffect(() => {
Expand Down
1 change: 0 additions & 1 deletion lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"airbnb-js-shims": "^2.2.1",
"ansi-to-html": "^0.6.11",
"autoprefixer": "^9.7.2",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-emotion": "^10.0.20",
"babel-plugin-macros": "^2.7.0",
"babel-preset-minify": "^0.5.0 || 0.6.0-alpha.5",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.5",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-emotion": "^10.0.20",
"babel-plugin-macros": "^2.7.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6793,10 +6793,10 @@ babel-plugin-named-asset-import@^0.3.1, babel-plugin-named-asset-import@^0.3.2,
resolved "https://registry.yarnpkg.com/babel-plugin-named-asset-import/-/babel-plugin-named-asset-import-0.3.4.tgz#4a8fc30e9a3e2b1f5ed36883386ab2d84e1089bd"
integrity sha512-S6d+tEzc5Af1tKIMbsf2QirCcPdQ+mKUCY2H1nJj1DyA1ShwpsoxEOAwbWsG5gcXNV/olpvQd9vrUWRx4bnhpw==

babel-plugin-react-docgen@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-react-docgen/-/babel-plugin-react-docgen-4.0.0.tgz#1be997bc135b2a0eec54364202d01ed0f15f0098"
integrity sha512-6vdky/CRaq0zE64ZRR1fOjUfFS3kX7USMuC6mAH/ASYt/EGY9Ms1F5uLwHhmBhaOGKiJJHvhKz16wX9IBWBLKg==
babel-plugin-react-docgen@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/babel-plugin-react-docgen/-/babel-plugin-react-docgen-4.1.0.tgz#1dfa447dac9ca32d625a123df5733a9e47287c26"
integrity sha512-vzpnBlfGv8XOhJM2zbPyyqw2OLEbelgZZsaaRRTpVwNKuYuc+pUg4+dy7i9gCRms0uOQn4osX571HRcCJMJCmA==
dependencies:
lodash "^4.17.15"
react-docgen "^5.0.0"
Expand Down Expand Up @@ -26300,7 +26300,7 @@ react-devtools-core@^3.4.2, react-devtools-core@^3.6.0:
shell-quote "^1.6.1"
ws "^3.3.1"

react-docgen-typescript-loader@^3.3.0, react-docgen-typescript-loader@^3.6.0:
react-docgen-typescript-loader@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/react-docgen-typescript-loader/-/react-docgen-typescript-loader-3.6.0.tgz#5515f03f869e66d49e287c5f1e7ec10f2084f7bb"
integrity sha512-+uEsM3VYCdlcBGxF3tBqI5XWL1phvrh8dkiIfdpciKlM1BDHW+d82kKJI9hX6zk9H8TL+3Th/j/JAEaKb5FFNw==
Expand Down