Skip to content

Commit

Permalink
Merge pull request #12492 from AndrewLeedham/next
Browse files Browse the repository at this point in the history
React: Fix reactDocgen option when false
  • Loading branch information
shilman committed Sep 16, 2020
2 parents 9a2ed57 + 3ab18b5 commit cb87bc1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
45 changes: 44 additions & 1 deletion app/react/src/server/framework-preset-react-docgen.test.ts
@@ -1,9 +1,10 @@
import ReactDocgenTypescriptPlugin from 'react-docgen-typescript-plugin';
import * as preset from './framework-preset-react-docgen';

describe('framework-preset-react-docgen', () => {
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');

it('should return the config with the extra plugin', () => {
it('should return the babel config with the extra plugin', () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
Expand Down Expand Up @@ -33,4 +34,46 @@ describe('framework-preset-react-docgen', () => {
],
});
});

it('should return the webpack config with the extra plugin', () => {
const webpackConfig = {
plugins: [],
};

const config = preset.webpackFinal(webpackConfig, {
typescriptOptions: { check: false, reactDocgen: 'react-docgen-typescript' },
});

expect(config).toEqual({
plugins: [expect.any(ReactDocgenTypescriptPlugin)],
});
});

it('should not add any extra plugins', () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
};

const webpackConfig = {
plugins: [],
};

const outputBabelconfig = preset.babel(babelConfig, {
typescriptOptions: { check: false, reactDocgen: false },
});
const outputWebpackconfig = preset.webpackFinal(webpackConfig, {
typescriptOptions: { check: false, reactDocgen: false },
});

expect(outputBabelconfig).toEqual({
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
});
expect(outputWebpackconfig).toEqual({
plugins: [],
});
});
});
4 changes: 4 additions & 0 deletions app/react/src/server/framework-preset-react-docgen.ts
Expand Up @@ -6,6 +6,10 @@ import ReactDocgenTypescriptPlugin from 'react-docgen-typescript-plugin';
export function babel(config: TransformOptions, { typescriptOptions }: StorybookOptions) {
const { reactDocgen } = typescriptOptions;

if (reactDocgen === false) {
return config;
}

return {
...config,
overrides: [
Expand Down
12 changes: 6 additions & 6 deletions docs/configure/typescript.md
Expand Up @@ -30,9 +30,9 @@ The following code snippets shows the fields for you to use with TypeScript:

<!-- prettier-ignore-end -->

| Field | Framework | Description | Type |
| :------------------------------- | :-------- | :--------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------- |
| **check** | All | Optionally run fork-ts-checker-webpack-plugin | boolean |
| **checkOptions** | All | Options to pass to fork-ts-checker-webpack-plugin if it's enabled | [See docs](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) |
| **reactDocgen** | React | Which react docgen processor to run: `react-docgen-typescript`, `react-docgen`, `none` | string |
| **reactDocgenTypescriptOptions** | React | Options to pass to react-docgen-typescript-plugin if react-docgen-typescript is enabled. | [See docs](https://github.com/hipstersmoothie/react-docgen-typescript-plugin) |
| Field | Framework | Description | Type |
| :------------------------------- | :-------- | :-------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------- |
| **check** | All | Optionally run fork-ts-checker-webpack-plugin | boolean |
| **checkOptions** | All | Options to pass to fork-ts-checker-webpack-plugin if it's enabled | [See docs](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) |
| **reactDocgen** | React | Which react docgen processor to run: `"react-docgen-typescript"`, `"react-docgen"`, `false` | string or false |
| **reactDocgenTypescriptOptions** | React | Options to pass to react-docgen-typescript-plugin if react-docgen-typescript is enabled. | [See docs](https://github.com/hipstersmoothie/react-docgen-typescript-plugin) |

0 comments on commit cb87bc1

Please sign in to comment.