Skip to content

Commit

Permalink
fix(storybook): only install react deps for storybook 7 #29213 (#29231)
Browse files Browse the repository at this point in the history
## Current Behavior
Storybook 7 requires `react` and `react-dom` to be installed as they are
peer deps of the storybook package.
Storybook 8 does not require these deps to be installed as they are now
bundled correctly into storybook

## Expected Behavior
When user's version of storybook < 8, install `react` and `react-dom`,
otherwise, do not.

## Related Issue(s)

Fixes #29213

(cherry picked from commit 51cf34f)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Dec 6, 2024
1 parent 62632a9 commit 6ed78d2
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
readJson,
type Tree,
} from '@nx/devkit';
import { gte } from 'semver';
import { coerce, gte } from 'semver';
import {
getInstalledStorybookVersion,
storybookMajorVersion,
Expand Down Expand Up @@ -44,19 +44,21 @@ export function ensureDependencies(
packageJson.dependencies ??= {};
packageJson.devDependencies ??= {};

// Needed for Storybook 7
// https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-peer-dependencies-required
if (
!packageJson.dependencies['react'] &&
!packageJson.devDependencies['react']
) {
dependencies['react'] = reactVersion;
}
if (
!packageJson.dependencies['react-dom'] &&
!packageJson.devDependencies['react-dom']
) {
dependencies['react-dom'] = reactVersion;
if (!gte(coerce(storybook7VersionToInstall), '8.0.0')) {
// Needed for Storybook 7
// https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-peer-dependencies-required
if (
!packageJson.dependencies['react'] &&
!packageJson.devDependencies['react']
) {
dependencies['react'] = reactVersion;
}
if (
!packageJson.dependencies['react-dom'] &&
!packageJson.devDependencies['react-dom']
) {
dependencies['react-dom'] = reactVersion;
}
}

if (options.uiFramework) {
Expand Down

0 comments on commit 6ed78d2

Please sign in to comment.