Skip to content

Commit

Permalink
add a flag for detecting is the latest version we got from npm matche…
Browse files Browse the repository at this point in the history
…s the version of the CLI exactly
  • Loading branch information
ndelangen committed Mar 11, 2024
1 parent bfa0570 commit d978771
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const doAutomigrate = async (options: AutofixOptionsFromCLI) => {
mainConfigPath,
configDir,
isUpgrade: false,
isLatest: false,
});

if (outcome) {
Expand All @@ -125,6 +126,7 @@ export const automigrate = async ({
skipInstall,
hideMigrationSummary = false,
isUpgrade,
isLatest,
}: AutofixOptions): Promise<{
fixResults: Record<string, FixStatus>;
preCheckFailure?: PreCheckFailure;
Expand All @@ -140,7 +142,7 @@ export const automigrate = async ({
// we only allow this automigration when the user explicitly asks for it, or they are upgrading to the latest version of storybook
if (
fix.id === upgradeStorybookRelatedDependencies.id &&
isUpgrade !== 'latest' &&
isLatest === false &&
fixId !== upgradeStorybookRelatedDependencies.id
) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions code/lib/cli/src/automigrate/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StorybookConfigRaw } from '@storybook/types';
import type { JsPackageManager, PackageManagerName } from '@storybook/core-common';
import type { StorybookConfigRaw } from '@storybook/types';

export interface CheckOptions {
packageManager: JsPackageManager;
Expand Down Expand Up @@ -75,7 +75,8 @@ export interface AutofixOptions extends Omit<AutofixOptionsFromCLI, 'packageMana
/**
* Whether the migration is part of an upgrade.
*/
isUpgrade: false | true | 'latest';
isUpgrade: boolean;
isLatest: boolean;
}
export interface AutofixOptionsFromCLI {
fixId?: FixId;
Expand Down
7 changes: 4 additions & 3 deletions code/lib/cli/src/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { listCodemods, runCodemod } from '@storybook/codemod';
import { runFixes } from './automigrate';
import { mdxToCSF } from './automigrate/fixes/mdx-to-csf';
import {
JsPackageManagerFactory,
getStorybookInfo,
getCoercedStorybookVersion,
getStorybookInfo,
} from '@storybook/core-common';

import { runFixes } from './automigrate';
import { mdxToCSF } from './automigrate/fixes/mdx-to-csf';
import { getStorybookVersionSpecifier } from './helpers';

const logger = console;
Expand Down
4 changes: 3 additions & 1 deletion code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const doUpgrade = async ({
]);

const isOutdated = lt(currentVersion, latestVersion);
const isExactLatest = currentVersion === latestVersion;
const isPrerelease = prerelease(currentVersion) !== null;

const borderColor = isOutdated ? '#FC521F' : '#F1618C';
Expand Down Expand Up @@ -261,7 +262,8 @@ export const doUpgrade = async ({
mainConfigPath,
beforeVersion,
storybookVersion: currentVersion,
isUpgrade: isOutdated ? true : 'latest',
isUpgrade: isOutdated,
isLatest: isExactLatest,
});
}

Expand Down

0 comments on commit d978771

Please sign in to comment.