Skip to content

Commit dba883d

Browse files
kasperpeulenstorybook-bot
authored andcommitted
Merge pull request #27217 from storybookjs/kasper/disable-upgrade-to-same-version-error
CLI: Only log the UpgradeStorybookToSameVersionError but continue the upgrade as normal (cherry picked from commit 68809b6)
1 parent 780f153 commit dba883d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

code/lib/cli/src/upgrade.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { describe, it, expect, vi } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import * as sbcc from '@storybook/core-common';
3-
import {
4-
UpgradeStorybookToLowerVersionError,
5-
UpgradeStorybookToSameVersionError,
6-
} from '@storybook/core-events/server-errors';
3+
import { UpgradeStorybookToLowerVersionError } from '@storybook/core-events/server-errors';
74
import { doUpgrade, getStorybookVersion } from './upgrade';
5+
import { logger } from '@storybook/node-logger';
86

97
const findInstallationsMock = vi.fn<string[], Promise<sbcc.InstallationMetadata | undefined>>();
108

@@ -16,6 +14,8 @@ vi.mock('@storybook/core-common', async (importOriginal) => {
1614
JsPackageManagerFactory: {
1715
getPackageManager: () => ({
1816
findInstallations: findInstallationsMock,
17+
latestVersion: async () => '8.0.0',
18+
retrievePackageJson: async () => {},
1919
getAllDependencies: async () => ({ storybook: '8.0.0' }),
2020
}),
2121
},
@@ -68,7 +68,7 @@ describe('Upgrade errors', () => {
6868
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToLowerVersionError);
6969
expect(findInstallationsMock).toHaveBeenCalledWith(Object.keys(sbcc.versions));
7070
});
71-
it('should throw an error when upgrading to the same version number', async () => {
71+
it('should show a warning when upgrading to the same version number', async () => {
7272
findInstallationsMock.mockResolvedValue({
7373
dependencies: {
7474
'@storybook/cli': [
@@ -82,7 +82,15 @@ describe('Upgrade errors', () => {
8282
dedupeCommand: '',
8383
});
8484

85-
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToSameVersionError);
85+
// Mock as a throw, so that we don't have to mock the content of the doUpgrade fn that comes after it
86+
vi.spyOn(logger, 'warn').mockImplementation((error) => {
87+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
88+
throw error;
89+
});
90+
91+
await expect(doUpgrade({ packageManager: 'npm' } as any)).rejects.toContain(
92+
'You are upgrading Storybook to the same version that is currently installed in the project'
93+
);
8694
expect(findInstallationsMock).toHaveBeenCalledWith(Object.keys(sbcc.versions));
8795
});
8896
});

code/lib/cli/src/upgrade.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ export const doUpgrade = async ({
143143
if (!isCanary && lt(currentVersion, beforeVersion)) {
144144
throw new UpgradeStorybookToLowerVersionError({ beforeVersion, currentVersion });
145145
}
146+
146147
if (!isCanary && eq(currentVersion, beforeVersion)) {
147-
throw new UpgradeStorybookToSameVersionError({ beforeVersion });
148+
// Not throwing, as the beforeVersion calculation doesn't always work in monorepos.
149+
logger.warn(new UpgradeStorybookToSameVersionError({ beforeVersion }).message);
148150
}
149151

150152
const [latestVersion, packageJson, storybookVersion] = await Promise.all([

code/lib/core-events/src/errors/server-errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export class UpgradeStorybookToSameVersionError extends StorybookError {
545545

546546
template() {
547547
return dedent`
548-
You are trying to upgrade Storybook to the same version that is currently installed in the project, version ${this.data.beforeVersion}. This is not supported.
548+
You are upgrading Storybook to the same version that is currently installed in the project, version ${this.data.beforeVersion}.
549549
550550
This usually happens when running the upgrade command without a version specifier, e.g. "npx storybook upgrade".
551551
This will cause npm to run the globally cached storybook binary, which might be the same version that you already have.

0 commit comments

Comments
 (0)