From 62319c83dab0630948315d395c9ed9a2993a4f68 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 6 Jan 2023 10:49:36 +0100 Subject: [PATCH] account for CRA preset --- .../src/automigrate/fixes/missing-babelrc.test.ts | 13 +++++++++++++ .../cli/src/automigrate/fixes/missing-babelrc.ts | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts b/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts index 6c7b548235f2..1f896ed5e8e8 100644 --- a/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts +++ b/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts @@ -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: { diff --git a/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts b/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts index 7fda44e0a0cb..6ef7fa56202f 100644 --- a/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts +++ b/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts @@ -57,7 +57,14 @@ export const missingBabelRc: Fix = { 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, });