From 4059e678d5c361f716beb904b9d6086da3fe3fb8 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 29 Nov 2023 16:42:17 +0100 Subject: [PATCH] fix ts issue --- .../cli/src/doctor/getMismatchingVersionsWarning.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/code/lib/cli/src/doctor/getMismatchingVersionsWarning.ts b/code/lib/cli/src/doctor/getMismatchingVersionsWarning.ts index e69ac3d9ba61..68e93f491075 100644 --- a/code/lib/cli/src/doctor/getMismatchingVersionsWarning.ts +++ b/code/lib/cli/src/doctor/getMismatchingVersionsWarning.ts @@ -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; @@ -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); } @@ -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'; @@ -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; @@ -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 )}` );