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

Doctor: Add dynamic check for incompatible Storybook packages #26219

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
106 changes: 0 additions & 106 deletions code/lib/cli/src/automigrate/fixes/incompatible-addons.test.ts

This file was deleted.

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ describe('getMigrationSummary', () => {



You can find more information for a given dependency by running yarn why <package-name>
Please try de-duplicating these dependencies by running yarn dedupe




Please try de-duplicating these dependencies by running yarn dedupe"
You can find more information for a given dependency by running yarn why <package-name>"
`);
});

Expand Down
5 changes: 4 additions & 1 deletion code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FixStatus, allFixes } from './fixes';
import { cleanLog } from './helpers/cleanLog';
import { getMigrationSummary } from './helpers/getMigrationSummary';
import { getStorybookData } from './helpers/mainConfigFile';
import { doctor } from '../doctor';

const logger = console;
const LOG_FILE_NAME = 'migration-storybook.log';
Expand Down Expand Up @@ -83,7 +84,7 @@ export const doAutomigrate = async (options: AutofixOptionsFromCLI) => {
throw new Error('Could not determine main config path');
}

return automigrate({
await automigrate({
...options,
packageManager,
storybookVersion,
Expand All @@ -92,6 +93,8 @@ export const doAutomigrate = async (options: AutofixOptionsFromCLI) => {
configDir,
isUpgrade: false,
});

await doctor({ configDir, packageManager: options.packageManager });
yannbf marked this conversation as resolved.
Show resolved Hide resolved
};

export const automigrate = async ({
Expand Down
8 changes: 4 additions & 4 deletions code/lib/cli/src/doctor/getDuplicatedDepsWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ export function getDuplicatedDepsWarnings(

messages.push(
'\n',
`You can find more information for a given dependency by running ${chalk.cyan(
`${installationMetadata.infoCommand} <package-name>`
`Please try de-duplicating these dependencies by running ${chalk.cyan(
`${installationMetadata.dedupeCommand}`
)}`
);

messages.push(
'\n',
`Please try de-duplicating these dependencies by running ${chalk.cyan(
`${installationMetadata.dedupeCommand}`
`You can find more information for a given dependency by running ${chalk.cyan(
`${installationMetadata.infoCommand} <package-name>`
)}`
);

Expand Down
158 changes: 158 additions & 0 deletions code/lib/cli/src/doctor/getIncompatibleStorybookPackages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { describe, it, expect, vi } from 'vitest';
import type { AnalysedPackage } from './getIncompatibleStorybookPackages';
import {
getIncompatibleStorybookPackages,
getIncompatiblePackagesSummary,
checkPackageCompatibility,
} from './getIncompatibleStorybookPackages';
import type { JsPackageManager } from '@storybook/core-common';

import * as doctorUtils from './utils';

vi.mock('chalk', () => {
return {
default: {
yellow: (str: string) => str,
cyan: (str: string) => str,
bold: (str: string) => str,
},
};
});

vi.mock('./utils', () => ({
getPackageJsonPath: vi.fn(() => Promise.resolve('package.json')),
getPackageJsonOfDependency: vi.fn(() => Promise.resolve({})),
PackageJsonNotFoundError: Error,
}));

const packageManagerMock = {
getAllDependencies: () =>
Promise.resolve({
'@storybook/addon-essentials': '7.0.0',
}),
latestVersion: vi.fn(() => Promise.resolve('8.0.0')),
} as Partial<JsPackageManager>;

describe('checkPackageCompatibility', () => {
it('returns that an package is incompatible', async () => {
const packageName = 'my-storybook-package';
vi.mocked(doctorUtils.getPackageJsonOfDependency).mockResolvedValueOnce({
name: packageName,
version: '1.0.0',
dependencies: {
'@storybook/core-common': '7.0.0',
},
} as any);
const result = await checkPackageCompatibility(packageName, {
currentStorybookVersion: '8.0.0',
packageManager: packageManagerMock as JsPackageManager,
yannbf marked this conversation as resolved.
Show resolved Hide resolved
});
expect(result).toEqual({
packageName: 'my-storybook-package',
packageVersion: '1.0.0',
hasIncompatibleDependencies: true,
homepage: undefined,
availableUpdate: undefined,
});
yannbf marked this conversation as resolved.
Show resolved Hide resolved
});

it('returns that an package is compatible', async () => {
const packageName = 'my-storybook-package';
vi.mocked(doctorUtils.getPackageJsonOfDependency).mockResolvedValueOnce({
name: packageName,
version: '1.0.0',
dependencies: {
'@storybook/core-common': '8.0.0',
},
} as any);
const result = await checkPackageCompatibility(packageName, {
currentStorybookVersion: '8.0.0',
packageManager: packageManagerMock as JsPackageManager,
});
expect(result).toEqual({
packageName: 'my-storybook-package',
packageVersion: '1.0.0',
hasIncompatibleDependencies: false,
homepage: undefined,
availableUpdate: undefined,
});
});

it('returns that an package is incompatible and because it is core, can be upgraded', async () => {
const packageName = '@storybook/addon-essentials';
vi.mocked(doctorUtils.getPackageJsonOfDependency).mockResolvedValueOnce({
name: packageName,
version: '7.0.0',
dependencies: {
'@storybook/core-common': '7.0.0',
},
} as any);
const result = await checkPackageCompatibility(packageName, {
currentStorybookVersion: '8.0.0',
packageManager: packageManagerMock as JsPackageManager,
});
expect(result).toEqual({
packageName: '@storybook/addon-essentials',
packageVersion: '7.0.0',
hasIncompatibleDependencies: true,
homepage: undefined,
availableUpdate: '8.0.0',
});
});
});

describe('getIncompatibleStorybookPackages', () => {
it('returns an array of incompatible packages', async () => {
vi.mocked(doctorUtils.getPackageJsonOfDependency).mockResolvedValueOnce({
name: '@storybook/addon-essentials',
version: '7.0.0',
dependencies: {
'@storybook/core-common': '7.0.0',
},
} as any);

const result = await getIncompatibleStorybookPackages({
currentStorybookVersion: '8.0.0',
packageManager: packageManagerMock as JsPackageManager,
});

expect(result).toEqual([
{
packageName: '@storybook/addon-essentials',
packageVersion: '7.0.0',
hasIncompatibleDependencies: true,
homepage: undefined,
availableUpdate: '8.0.0',
},
]);
});
});

describe('getIncompatiblePackagesSummary', () => {
it('generates a summary message for incompatible packages', () => {
const analysedPackages: AnalysedPackage[] = [
{
packageName: 'storybook-react',
packageVersion: '1.0.0',
hasIncompatibleDependencies: true,
},
{
packageName: '@storybook/addon-essentials',
packageVersion: '7.0.0',
hasIncompatibleDependencies: true,
availableUpdate: '8.0.0',
},
];
const summary = getIncompatiblePackagesSummary(analysedPackages, '8.0.0');
expect(summary).toMatchInlineSnapshot(`
"The following packages are incompatible with Storybook 8.0.0 as they depend on different major versions of Storybook packages:
- [email protected]
- @storybook/[email protected] (8.0.0 available!)


Please consider updating your packages or contacting the maintainers for compatibility details.
For more on Storybook 8 compatibility, see the linked Github issue:
yannbf marked this conversation as resolved.
Show resolved Hide resolved
https://github.com/storybookjs/storybook/issues/26031"
`);
});
});
Loading
Loading