Skip to content

Commit

Permalink
fix config check
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 5, 2023
1 parent 8969c56 commit 600a5ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 9 additions & 8 deletions code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const babelContent = JSON.stringify({
});

const check = async ({ packageJson = {}, main = {}, extraFiles }: any) => {
if (extraFiles) {
// eslint-disable-next-line global-require
require('fs-extra').__setMockFiles({
[path.join('.storybook', 'main.js')]: `module.exports = ${JSON.stringify(main)};`,
...extraFiles,
});
}
// eslint-disable-next-line global-require
require('fs-extra').__setMockFiles({
[path.join('.storybook', 'main.js')]: `module.exports = ${JSON.stringify(main)};`,
...(extraFiles || {}),
});

const packageManager = {
retrievePackageJson: () => ({ dependencies: {}, devDependencies: {}, ...packageJson }),
} as JsPackageManager;
Expand Down Expand Up @@ -84,7 +83,9 @@ describe('missing-babelrc fix', () => {
},
};

await expect(check({ packageJson })).resolves.toBe({
await expect(
check({ main: { framework: '@storybook/react-webpack5' }, packageJson })
).resolves.toEqual({
needsBabelRc: true,
});
});
Expand Down
7 changes: 5 additions & 2 deletions code/lib/cli/src/automigrate/fixes/missing-babelrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ export const missingBabelRc: Fix<MissingBabelRcOptions> = {
typeof frameworkField === 'string' ? frameworkField : frameworkField?.name;

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

if (!config.config && !config.babelrc && !packageJson.babel) {
return { needsBabelRc: true };
}
}
Expand Down

0 comments on commit 600a5ec

Please sign in to comment.