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

React: Fix reactDocgen option when false #12492

Merged
merged 1 commit into from Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) |