Skip to content

Commit

Permalink
account for CRA preset
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 6, 2023
1 parent a079ce1 commit 62319c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('missing-babelrc fix', () => {
await expect(check({ packageJson })).resolves.toBeNull();
});

it('skips when using CRA preset', async () => {
const packageJson = {
devDependencies: {
'@storybook/react': '^7.0.0',
'@storybook/react-webpack5': '^7.0.0',
},
};

await expect(
check({ packageJson, main: { addons: ['@storybook/preset-create-react-app'] } })
).resolves.toBeNull();
});

it('prompts when babelrc file is missing and framework does not provide babel config', async () => {
const packageJson = {
devDependencies: {
Expand Down
9 changes: 8 additions & 1 deletion code/lib/cli/src/automigrate/fixes/missing-babelrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export const missingBabelRc: Fix<MissingBabelRcOptions> = {
const frameworkPackage =
typeof frameworkField === 'string' ? frameworkField : frameworkField?.name;

if (frameworksThatNeedBabelConfig.includes(frameworkPackage)) {
const addons: any[] = main.getFieldValue(['addons']) || [];

const hasCraPreset = addons.find((addon) => {
const name = typeof addon === 'string' ? addon : addon.name;
return name === '@storybook/preset-create-react-app';
});

if (frameworksThatNeedBabelConfig.includes(frameworkPackage) && !hasCraPreset) {
const config = await loadPartialConfigAsync({
babelrc: true,
});
Expand Down

0 comments on commit 62319c8

Please sign in to comment.