Skip to content

Commit

Permalink
Implement version checks to support automigrations from 6 to 8
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Feb 16, 2024
1 parent 8c9fc39 commit 05ebcc2
Show file tree
Hide file tree
Showing 33 changed files with 261 additions and 517 deletions.
3 changes: 2 additions & 1 deletion code/lib/cli/src/autoblock/block-dependencies-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const minimalVersionsMap = {
preact: '10.0.0',
svelte: '4.0.0',
vue: '3.0.0',
vite: '4.0.0',
};

type Result = {
Expand Down Expand Up @@ -83,7 +84,7 @@ export const blocker = createBlocker({
default:
return dedent`
Support for ${data.packageName} version < ${data.minimumVersion} has been removed.
Storybook 8 needs minimum version of ${data.minimumVersion}, but you had version ${data.installedVersion}.
Since version 8, Storybook needs minimum version of ${data.minimumVersion}, but you had version ${data.installedVersion}.
Please update this dependency.
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const angularBuildersMultiproject: Fix<AngularBuildersMultiprojectRunOpti
id: 'angular-builders-multiproject',
promptOnly: true,

versionRange: ['<7', '>=7'],

async check({ packageManager, mainConfig }) {
// Skip in case of NX
const angularVersion = await packageManager.getPackageVersion('@angular/core');
Expand Down
18 changes: 0 additions & 18 deletions code/lib/cli/src/automigrate/fixes/angular-builders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ describe('is not Nx project', () => {
});
});

describe('Angular < 15.0.0', () => {
const packageManager = {
getPackageVersion: (packageName: string) => {
if (packageName === '@angular/core') {
return Promise.resolve('14.0.0');
}

return null;
},
} as Partial<JsPackageManager>;

it('should throw an Error', async () => {
await expect(
checkAngularBuilders({ packageManager, mainConfig: { framework: '@storybook/angular' } })
).rejects.toThrowErrorMatchingSnapshot();
});
});

describe('Angular >= 16.0.0', () => {
const packageManager = {
getPackageVersion: (packageName) => {
Expand Down
10 changes: 2 additions & 8 deletions code/lib/cli/src/automigrate/fixes/angular-builders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { dedent } from 'ts-dedent';
import semver from 'semver';
import type { StorybookConfig } from '@storybook/types';
import chalk from 'chalk';
import prompts from 'prompts';
Expand All @@ -17,6 +16,8 @@ interface AngularBuildersRunOptions {
export const angularBuilders: Fix<AngularBuildersRunOptions> = {
id: 'angular-builders',

versionRange: ['<7', '>=7'],

async check({ packageManager, mainConfig }) {
const angularVersion = await packageManager.getPackageVersion('@angular/core');

Expand All @@ -31,13 +32,6 @@ export const angularBuilders: Fix<AngularBuildersRunOptions> = {
return null;
}

if (semver.lt(angularVersion, '15.0.0')) {
throw new Error(dedent`
❌ Your project uses Angular < 15.0.0. Storybook 8.0 for Angular requires Angular 15.0.0 or higher.
Please upgrade your Angular version to at least version 15.0.0 to use Storybook 8.0 in your project.
`);
}

const angularJSON = new AngularJSON();

const { hasStorybookBuilder } = angularJSON;
Expand Down
2 changes: 2 additions & 0 deletions code/lib/cli/src/automigrate/fixes/autodocs-true.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface AutodocsTrueFrameworkRunOptions {
export const autodocsTrue: Fix<AutodocsTrueFrameworkRunOptions> = {
id: 'autodocsTrue',

versionRange: ['<7', '>=7'],

async check({ mainConfig }) {
const { docs } = mainConfig;

Expand Down
13 changes: 1 addition & 12 deletions code/lib/cli/src/automigrate/fixes/bare-mdx-stories-glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ describe('bare-mdx fix', () => {
});

describe('should no-op', () => {
it('in SB < v7.0.0', async () => {
const packageJson = {
dependencies: { '@storybook/react': '^6.2.0' },
};
const main = { stories: ['../**/*.stories.mdx'] };
await expect(
checkBareMdxStoriesGlob({ packageJson, main, storybookVersion: '6.5.0' })
).resolves.toBeFalsy();
});

describe('in SB >= v7.0.0', () => {
it('without main', async () => {
const packageJson = {
Expand Down Expand Up @@ -162,7 +152,7 @@ describe('bare-mdx fix', () => {
}
In Storybook 7, we have deprecated defining stories in MDX files, and consequently have changed the suffix to simply .mdx.
Now, since Storybook 8.0, we have removed support for .stories.mdx files.
We can automatically migrate your 'stories' config to include any .mdx file instead of just .stories.mdx.
That would result in the following 'stories' config:
"../src/**/*.mdx"
Expand All @@ -171,7 +161,6 @@ describe('bare-mdx fix', () => {
"directory": "../src/**",
"files": "*.mdx"
}
To learn more about this change, see: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mdx-docs-files"
`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import chalk from 'chalk';
import dedent from 'ts-dedent';
import semver from 'semver';
import type { StoriesEntry } from '@storybook/types';
import { updateMainConfig } from '../helpers/mainConfigFile';
import type { Fix } from '../types';
Expand Down Expand Up @@ -31,11 +30,8 @@ const getNextGlob = (glob: string) => {

export const bareMdxStoriesGlob: Fix<BareMdxStoriesGlobRunOptions> = {
id: 'bare-mdx-stories-glob',
async check({ storybookVersion, mainConfig }) {
if (!semver.gte(storybookVersion, '7.0.0')) {
return null;
}

versionRange: ['<7', '>=7'],
async check({ mainConfig }) {
const existingStoriesEntries = mainConfig.stories as StoriesEntry[];

if (!existingStoriesEntries) {
Expand All @@ -45,10 +41,9 @@ export const bareMdxStoriesGlob: Fix<BareMdxStoriesGlobRunOptions> = {
)}, skipping ${chalk.cyan(this.id)} fix.
In Storybook 7, we have deprecated defining stories in MDX files, and consequently have changed the suffix to simply .mdx.
Now, since Storybook 8.0, we have removed support for .stories.mdx files.
We were unable to automatically migrate your 'stories' config to include any .mdx file instead of just .stories.mdx.
We suggest you make this change manually.
To learn more about this change, see: ${chalk.yellow(
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mdx-docs-files'
)}
Expand Down Expand Up @@ -100,11 +95,10 @@ export const bareMdxStoriesGlob: Fix<BareMdxStoriesGlobRunOptions> = {
${chalk.cyan(prettyExistingStoriesEntries)}
In Storybook 7, we have deprecated defining stories in MDX files, and consequently have changed the suffix to simply .mdx.
Now, since Storybook 8.0, we have removed support for .stories.mdx files.
We can automatically migrate your 'stories' config to include any .mdx file instead of just .stories.mdx.
That would result in the following 'stories' config:
${chalk.cyan(prettyNextStoriesEntries)}
To learn more about this change, see: ${chalk.yellow(
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mdx-docs-files'
)}
Expand Down
2 changes: 2 additions & 0 deletions code/lib/cli/src/automigrate/fixes/builder-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ interface BuilderViteOptions {
export const builderVite: Fix<BuilderViteOptions> = {
id: 'builder-vite',

versionRange: ['<7', '>=7'],

async check({ packageManager, mainConfig }) {
const packageJson = await packageManager.retrievePackageJson();
const builder = mainConfig.core?.builder;
Expand Down
2 changes: 2 additions & 0 deletions code/lib/cli/src/automigrate/fixes/cra5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface CRA5RunOptions {
export const cra5: Fix<CRA5RunOptions> = {
id: 'cra5',

versionRange: ['<7', '>=7'],

async check({ packageManager, mainConfig, storybookVersion }) {
const craVersion = await packageManager.getPackageVersion('react-scripts');

Expand Down
2 changes: 2 additions & 0 deletions code/lib/cli/src/automigrate/fixes/eslint-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface EslintPluginRunOptions {
export const eslintPlugin: Fix<EslintPluginRunOptions> = {
id: 'eslintPlugin',

versionRange: ['<8', '>=7'],

async check({ packageManager }) {
const { hasEslint, isStorybookPluginInstalled } = await extractEslintInfo(packageManager);

Expand Down
106 changes: 0 additions & 106 deletions code/lib/cli/src/automigrate/fixes/incompatible-addons.test.ts

This file was deleted.

33 changes: 0 additions & 33 deletions code/lib/cli/src/automigrate/fixes/incompatible-addons.ts

This file was deleted.

6 changes: 0 additions & 6 deletions code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Fix } from '../types';

import { cra5 } from './cra5';
import { webpack5 } from './webpack5';
import { vite4 } from './vite4';
import { vue3 } from './vue3';
import { mdxgfm } from './mdx-gfm';
import { eslintPlugin } from './eslint-plugin';
Expand All @@ -12,10 +11,8 @@ import { sbScripts } from './sb-scripts';
import { sbBinary } from './sb-binary';
import { newFrameworks } from './new-frameworks';
import { removedGlobalClientAPIs } from './remove-global-client-apis';
import { mdx1to2 } from './mdx-1-to-2';
import { autodocsTrue } from './autodocs-true';
import { angularBuilders } from './angular-builders';
import { incompatibleAddons } from './incompatible-addons';
import { angularBuildersMultiproject } from './angular-builders-multiproject';
import { wrapRequire } from './wrap-require';
import { reactDocgen } from './react-docgen';
Expand All @@ -30,16 +27,13 @@ export const allFixes: Fix[] = [
cra5,
webpack5,
vue3,
vite4,
viteConfigFile,
eslintPlugin,
builderVite,
sbBinary,
sbScripts,
incompatibleAddons,
removeJestTestingLibrary,
removedGlobalClientAPIs,
mdx1to2,
mdxgfm,
autodocsTrue,
angularBuildersMultiproject,
Expand Down
Loading

0 comments on commit 05ebcc2

Please sign in to comment.