feat(cli): make CLI works with Yarn 2 for React scripts projects

Before, it was assumed that "When working with `create-react-app@>=2.0.0`, we know `babel-loader` is installed."
But `babel` is a peer dependency of `@storybook/core` (itself dep of `@storybook/react`) and so it must be added to the project's `package.json`
This commit is contained in:
Gaëtan Maisse 2020-02-15 11:43:31 +01:00
parent e46fecfc05
commit febe9e7204

View File

@ -1,6 +1,5 @@
import path from 'path';
import fs from 'fs';
import semver from 'semver';
import {
retrievePackageJson,
getVersionedPackages,
@ -44,14 +43,7 @@ export default async (npmOptions, { storyFormat = 'csf' }) => {
writePackageJson(packageJson);
// When working with `create-react-app@>=2.0.0`, we know `babel-loader` is installed.
let babelDependencies = [];
const reactScriptsDep =
packageJson.dependencies['react-scripts'] || packageJson.devDependencies['react-scripts'];
if (reactScriptsDep && semver.gtr('2.0.0', reactScriptsDep)) {
babelDependencies = await getBabelDependencies(npmOptions, packageJson);
}
const babelDependencies = await getBabelDependencies(npmOptions, packageJson);
installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};