From 1105963caf72ad567a5f64bc2cb38f7ce409db72 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Mon, 15 Jun 2020 18:26:03 -0700 Subject: [PATCH 1/2] load root tsconfig.json into docgen-typescript --- .../src/server/framework-preset-react-docgen.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/react/src/server/framework-preset-react-docgen.ts b/app/react/src/server/framework-preset-react-docgen.ts index b9fae23849d0..581e6180e041 100644 --- a/app/react/src/server/framework-preset-react-docgen.ts +++ b/app/react/src/server/framework-preset-react-docgen.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import type { TransformOptions } from '@babel/core'; import type { Configuration } from 'webpack'; import type { StorybookOptions } from '@storybook/core/types'; @@ -28,13 +29,23 @@ export function babel(config: TransformOptions, { typescriptOptions }: Storybook }; } +const tsconfigPath = './tsconfig.json'; + export function webpackFinal(config: Configuration, { typescriptOptions }: StorybookOptions) { - const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions; + const { reactDocgen, reactDocgenTypescriptOptions = {} } = typescriptOptions; if (reactDocgen !== 'react-docgen-typescript') { return config; } + if ( + !reactDocgenTypescriptOptions.tsconfigPath && + !reactDocgenTypescriptOptions.compilerOptions && + fs.existsSync(tsconfigPath) + ) { + reactDocgenTypescriptOptions.tsconfigPath = tsconfigPath; + } + return { ...config, plugins: [...config.plugins, new ReactDocgenTypescriptPlugin(reactDocgenTypescriptOptions)], From 482a5a8ec66be1e8a3d433af91a4a165674cf7ac Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Tue, 16 Jun 2020 14:22:53 -0700 Subject: [PATCH 2/2] update plugin --- app/react/package.json | 2 +- .../src/server/framework-preset-react-docgen.ts | 13 +------------ examples/cra-ts-kitchen-sink/package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/react/package.json b/app/react/package.json index 8e66d2d9cff1..9233a0f8e689 100644 --- a/app/react/package.json +++ b/app/react/package.json @@ -50,7 +50,7 @@ "lodash": "^4.17.15", "prop-types": "^15.7.2", "react-dev-utils": "^10.0.0", - "react-docgen-typescript-plugin": "^0.4.0", + "react-docgen-typescript-plugin": "^0.5.0", "regenerator-runtime": "^0.13.3", "ts-dedent": "^1.1.1", "webpack": "^4.43.0" diff --git a/app/react/src/server/framework-preset-react-docgen.ts b/app/react/src/server/framework-preset-react-docgen.ts index 581e6180e041..b9fae23849d0 100644 --- a/app/react/src/server/framework-preset-react-docgen.ts +++ b/app/react/src/server/framework-preset-react-docgen.ts @@ -1,4 +1,3 @@ -import fs from 'fs'; import type { TransformOptions } from '@babel/core'; import type { Configuration } from 'webpack'; import type { StorybookOptions } from '@storybook/core/types'; @@ -29,23 +28,13 @@ export function babel(config: TransformOptions, { typescriptOptions }: Storybook }; } -const tsconfigPath = './tsconfig.json'; - export function webpackFinal(config: Configuration, { typescriptOptions }: StorybookOptions) { - const { reactDocgen, reactDocgenTypescriptOptions = {} } = typescriptOptions; + const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions; if (reactDocgen !== 'react-docgen-typescript') { return config; } - if ( - !reactDocgenTypescriptOptions.tsconfigPath && - !reactDocgenTypescriptOptions.compilerOptions && - fs.existsSync(tsconfigPath) - ) { - reactDocgenTypescriptOptions.tsconfigPath = tsconfigPath; - } - return { ...config, plugins: [...config.plugins, new ReactDocgenTypescriptPlugin(reactDocgenTypescriptOptions)], diff --git a/examples/cra-ts-kitchen-sink/package.json b/examples/cra-ts-kitchen-sink/package.json index 1eebbc886977..42bc6b2fd673 100644 --- a/examples/cra-ts-kitchen-sink/package.json +++ b/examples/cra-ts-kitchen-sink/package.json @@ -47,7 +47,7 @@ "enzyme-adapter-react-16": "^1.9.1", "enzyme-to-json": "^3.4.1", "fork-ts-checker-webpack-plugin": "^4.0.3", - "react-docgen-typescript-plugin": "^0.4.0", + "react-docgen-typescript-plugin": "^0.5.0", "react-moment-proptypes": "^1.7.0", "ts-node": "~8.9.1" }, diff --git a/yarn.lock b/yarn.lock index 616800eca2a7..ae947ad1347b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26565,10 +26565,10 @@ react-docgen-typescript-loader@^3.7.2: loader-utils "^1.2.3" react-docgen-typescript "^1.15.0" -react-docgen-typescript-plugin@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/react-docgen-typescript-plugin/-/react-docgen-typescript-plugin-0.4.0.tgz#79416e040a7e2c8ece49ded538b6e6661462d46a" - integrity sha512-04zRzxpx5BOC0i8QKBH8lNDMuSxZQHH7OVvXwfShaVNd482MnNlf2+MjN6I3vYUhd0X85i3r2KFRFeMS7fOpCA== +react-docgen-typescript-plugin@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/react-docgen-typescript-plugin/-/react-docgen-typescript-plugin-0.5.0.tgz#704733d99be7d41c64ee651240212d7fd6f8edc5" + integrity sha512-7bTj/or5u4UZls7x07MwEFj6Ak9icHwMLSs2mUL5QZON51gDdGCTbbmSR0nKsPISYP+iNqtbsRnlsbvjcM06nw== dependencies: debug "^4.1.1" endent "^2.0.1"