Skip to content

Commit

Permalink
fix ts issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Nov 29, 2023
1 parent ffbb86e commit 4059e67
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions code/lib/cli/src/doctor/getMismatchingVersionsWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { frameworkPackages } from '@storybook/core-common';
import type { InstallationMetadata } from '../js-package-manager/types';
import storybookCorePackages from '../versions';

function getPrimaryVersion(name: string, installationMetadata?: InstallationMetadata) {
function getPrimaryVersion(name: string | undefined, installationMetadata?: InstallationMetadata) {
if (!name) {
return undefined;
}
const packageMetadata = installationMetadata?.dependencies[name];
if (!packageMetadata) {
return undefined;
Expand All @@ -23,7 +26,7 @@ export function getMismatchingVersionsWarnings(

const messages: string[] = [];
try {
const frameworkPackageName = Object.keys(installationMetadata?.dependencies).find(
const frameworkPackageName = Object.keys(installationMetadata?.dependencies || []).find(
(packageName) => {
return Object.keys(frameworkPackages).includes(packageName);
}
Expand All @@ -47,7 +50,7 @@ export function getMismatchingVersionsWarnings(
let packageToDisplay: string;
if (semver.lt(cliVersion, frameworkVersion)) {
versionToCompare = frameworkVersion;
packageToDisplay = frameworkPackageName;
packageToDisplay = frameworkPackageName as string;
} else {
versionToCompare = cliVersion;
packageToDisplay = 'storybook';
Expand All @@ -59,7 +62,7 @@ export function getMismatchingVersionsWarnings(
)} (from the ${chalk.cyan(packageToDisplay)} package) or higher.`
);

const filteredDependencies = Object.entries(installationMetadata?.dependencies).filter(
const filteredDependencies = Object.entries(installationMetadata?.dependencies || []).filter(
([name, packages]) => {
if (Object.keys(storybookCorePackages).includes(name)) {
const packageVersion = packages[0].version;
Expand Down Expand Up @@ -95,7 +98,7 @@ export function getMismatchingVersionsWarnings(
)} to upgrade all of your Storybook packages to the latest version.
Alternatively you can try manually changing the versions to match in your package.json. We also recommend regenerating your lockfile, or running the following command to possibly deduplicate your Storybook package versions: ${chalk.cyan(
installationMetadata.dedupeCommand
installationMetadata?.dedupeCommand
)}`
);

Expand Down

0 comments on commit 4059e67

Please sign in to comment.