From b1a8917b8da2cea7edac8354fe0f4b604f306985 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Fri, 7 Jul 2023 11:33:46 +0300 Subject: [PATCH] fix(storybook): optional chain .length in utils (#18001) (cherry picked from commit 3edbe49fa2ea0503547ba5bff707a67382fb4d13) --- .../generators/configuration/lib/util-functions.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storybook/src/generators/configuration/lib/util-functions.ts b/packages/storybook/src/generators/configuration/lib/util-functions.ts index 595578b44860b..0b46fcd9220f8 100644 --- a/packages/storybook/src/generators/configuration/lib/util-functions.ts +++ b/packages/storybook/src/generators/configuration/lib/util-functions.ts @@ -564,7 +564,7 @@ export function getTsConfigPath( const { root, projectType } = readProjectConfiguration(tree, projectName); return join( root, - path && path.length > 0 + path?.length > 0 ? path : projectType === 'application' ? 'tsconfig.app.json' @@ -595,7 +595,7 @@ export function addBuildStorybookToCacheableOperations(tree: Tree) { } export function projectIsRootProjectInStandaloneWorkspace(projectRoot: string) { - return relative(workspaceRoot, projectRoot).length === 0; + return relative(workspaceRoot, projectRoot)?.length === 0; } export function workspaceHasRootProject(tree: Tree) { @@ -682,14 +682,14 @@ export function renameAndMoveOldTsConfig( json.extends = json.extends.replace('../', './'); } - for (let i = 0; i < json.files.length; i++) { + for (let i = 0; i < json.files?.length; i++) { // drop one level of nesting if (json.files[i].startsWith('../../../')) { json.files[i] = json.files[i].replace('../../../', '../../'); } } - for (let i = 0; i < json.include.length; i++) { + for (let i = 0; i < json.include?.length; i++) { if (json.include[i].startsWith('../')) { json.include[i] = json.include[i].replace('../', ''); } @@ -702,7 +702,7 @@ export function renameAndMoveOldTsConfig( } } - for (let i = 0; i < json.exclude.length; i++) { + for (let i = 0; i < json.exclude?.length; i++) { if (json.exclude[i].startsWith('../')) { json.exclude[i] = json.exclude[i].replace('../', 'src/'); } @@ -719,7 +719,7 @@ export function renameAndMoveOldTsConfig( const projectTsConfig = joinPathFragments(projectRoot, 'tsconfig.json'); updateJson(tree, projectTsConfig, (json) => { - for (let i = 0; i < json.references.length; i++) { + for (let i = 0; i < json.references?.length; i++) { if (json.references[i].path === './.storybook/tsconfig.json') { json.references[i].path = './tsconfig.storybook.json'; break;