Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook): check storybook is installed and not on v7 already #16402

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as build from '@storybook/core-server';
import { CLIOptions } from '@storybook/types'; // TODO(katerina): Remove when Storybook 7
import 'dotenv/config';
import {
isStorybookV7,
storybookConfigExistsCheck,
storybookMajorVersion,
} from '../../utils/utilities';
import { CommonNxStorybookConfig } from '../../utils/models';
import {
Expand All @@ -18,7 +18,7 @@ export default async function buildStorybookExecutor(
context: ExecutorContext
) {
storybookConfigExistsCheck(options.configDir, context.projectName);
const storybook7 = isStorybookV7();
const storybook7 = storybookMajorVersion() === 7;
if (storybook7) {
const buildOptions: CLIOptions = options;
logger.info(`NX Storybook builder starting ...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ExecutorContext } from '@nx/devkit';
import * as build from '@storybook/core-server';
import 'dotenv/config';
import {
isStorybookV7,
storybookConfigExistsCheck,
storybookMajorVersion,
} from '../../utils/utilities';
import {
getStorybookFrameworkPath,
Expand All @@ -20,7 +20,7 @@ export default async function* storybookExecutor(
success: boolean;
info?: { port: number; baseUrl?: string };
}> {
const storybook7 = isStorybookV7();
const storybook7 = storybookMajorVersion() === 7;
storybookConfigExistsCheck(options.configDir, context.projectName);
if (storybook7) {
const buildOptions: CLIOptions = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Tree } from '@nx/devkit';
import { output } from 'nx/src/utils/output';
import migrate7Generator from '../../generators/migrate-7/migrate-7';
import { storybookMajorVersion } from '../../utils/utilities';

export default async function changeStorybookTargets(tree: Tree) {
const storybookVersion = storybookMajorVersion();
if (!storybookVersion || storybookVersion === 7) {
return;
}

output.log({
title: 'Migrating Storybook to v7',
bodyLines: [
Expand Down
12 changes: 2 additions & 10 deletions packages/storybook/src/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { storybookVersion } from './versions';
import { statSync } from 'fs';
import { findNodes } from '@nx/js';
import ts = require('typescript');
import { gte, lt, major } from 'semver';
import { major } from 'semver';
import { join } from 'path';

export const Constants = {
Expand Down Expand Up @@ -51,15 +51,7 @@ type Framework = {
uiFramework: Constants['uiFrameworks'][keyof Constants['uiFrameworks']];
};

export function isStorybookV7() {
const storybookPackageVersion = require(join(
'@storybook/core-server',
'package.json'
)).version;
return gte(storybookPackageVersion, '7.0.0-alpha.0');
}

export function storybookMajorVersion() {
export function storybookMajorVersion(): number | undefined {
try {
const storybookPackageVersion = require(join(
'@storybook/core-server',
Expand Down