-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24165 from storybookjs/shilman/default-to-react-d…
…ocgen React: Set `react-docgen` to default TS docgen
- Loading branch information
Showing
10 changed files
with
158 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { StorybookConfig } from '@storybook/types'; | ||
import { reactDocgen } from './react-docgen'; | ||
|
||
const check = async ({ | ||
packageManager, | ||
main: mainConfig, | ||
storybookVersion = '7.0.0', | ||
}: { | ||
packageManager: any; | ||
main: Partial<StorybookConfig> & Record<string, unknown>; | ||
storybookVersion?: string; | ||
}) => { | ||
return reactDocgen.check({ | ||
packageManager, | ||
configDir: '', | ||
mainConfig: mainConfig as any, | ||
storybookVersion, | ||
}); | ||
}; | ||
|
||
describe('no-ops', () => { | ||
test('typescript.reactDocgen is already set', async () => { | ||
await expect( | ||
check({ | ||
packageManager: {}, | ||
main: { | ||
typescript: { | ||
// @ts-expect-error assume react | ||
reactDocgen: 'react-docgen-typescript', | ||
}, | ||
}, | ||
}) | ||
).resolves.toBeFalsy(); | ||
|
||
await expect( | ||
check({ | ||
packageManager: {}, | ||
main: { | ||
typescript: { | ||
// @ts-expect-error assume react | ||
reactDocgen: false, | ||
}, | ||
}, | ||
}) | ||
).resolves.toBeFalsy(); | ||
}); | ||
test('typescript.reactDocgen and typescript.reactDocgenTypescriptOptions are both unset', async () => { | ||
await expect( | ||
check({ | ||
packageManager: {}, | ||
main: { | ||
typescript: { | ||
// @ts-expect-error assume react | ||
reactDocgen: 'react-docgen-typescript', | ||
reactDocgenTypescriptOptions: undefined, | ||
}, | ||
}, | ||
}) | ||
).resolves.toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('continue', () => { | ||
test('typescript.reactDocgenTypescriptOptions is set', async () => { | ||
await expect( | ||
check({ | ||
packageManager: {}, | ||
main: { | ||
typescript: { | ||
// @ts-expect-error assume react | ||
reactDocgenTypescriptOptions: {}, | ||
}, | ||
}, | ||
}) | ||
).resolves.toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { dedent } from 'ts-dedent'; | ||
import { updateMainConfig } from '../helpers/mainConfigFile'; | ||
import type { Fix } from '../types'; | ||
|
||
const logger = console; | ||
|
||
interface Options { | ||
reactDocgenTypescriptOptions: any; | ||
} | ||
|
||
/** | ||
*/ | ||
export const reactDocgen: Fix<Options> = { | ||
id: 'react-docgen', | ||
|
||
async check({ mainConfig }) { | ||
// @ts-expect-error assume react | ||
const { reactDocgenTypescriptOptions } = mainConfig.typescript || {}; | ||
|
||
return reactDocgenTypescriptOptions ? { reactDocgenTypescriptOptions } : null; | ||
}, | ||
|
||
prompt() { | ||
return dedent` | ||
You have "typescript.reactDocgenTypescriptOptions" configured in your main.js, | ||
but "typescript.reactDocgen" is unset. | ||
In Storybook 8.0, we changed the default React docgen analysis from | ||
"react-docgen-typescript" to "react-docgen", which dramatically faster | ||
but doesn't handle all TypeScript constructs. | ||
We can update your config to continue to use "react-docgen-typescript", | ||
though we recommend giving "react-docgen" for a much faster dev experience. | ||
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-docgen-component-analysis-by-default | ||
`; | ||
}, | ||
|
||
async run({ dryRun, mainConfigPath }) { | ||
if (!dryRun) { | ||
await updateMainConfig({ mainConfigPath, dryRun: !!dryRun }, async (main) => { | ||
logger.info(`✅ Setting typescript.reactDocgen`); | ||
if (!dryRun) { | ||
main.setFieldValue(['typescript', 'reactDocgen'], 'react-docgen-typescript'); | ||
} | ||
}); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters