diff --git a/packages/storybook/src/generators/configuration/lib/util-functions.ts b/packages/storybook/src/generators/configuration/lib/util-functions.ts index b54839d838f35..40afbf3a58511 100644 --- a/packages/storybook/src/generators/configuration/lib/util-functions.ts +++ b/packages/storybook/src/generators/configuration/lib/util-functions.ts @@ -488,11 +488,14 @@ export function addStorybookToNamedInputs(tree: Tree) { } } -export function addStorybookToTargetDefaults(tree: Tree) { +export function addStorybookToTargetDefaults(tree: Tree, setCache = true) { const nxJson = readNxJson(tree); nxJson.targetDefaults ??= {}; nxJson.targetDefaults['build-storybook'] ??= {}; + if (setCache) { + nxJson.targetDefaults['build-storybook'].cache ??= true; + } nxJson.targetDefaults['build-storybook'].inputs ??= [ 'default', nxJson.namedInputs && 'production' in nxJson.namedInputs @@ -630,25 +633,20 @@ export function getTsConfigPath( } export function addBuildStorybookToCacheableOperations(tree: Tree) { - updateJson(tree, 'nx.json', (json) => ({ - ...json, - tasksRunnerOptions: { - ...(json.tasksRunnerOptions ?? {}), - default: { - ...(json.tasksRunnerOptions?.default ?? {}), - options: { - ...(json.tasksRunnerOptions?.default?.options ?? {}), - cacheableOperations: Array.from( - new Set([ - ...(json.tasksRunnerOptions?.default?.options - ?.cacheableOperations ?? []), - 'build-storybook', - ]) - ), - }, - }, - }, - })); + const nxJson = readNxJson(tree); + + if ( + nxJson.tasksRunnerOptions?.default?.options?.cacheableOperations && + !nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes( + 'build-storybook' + ) + ) { + nxJson.tasksRunnerOptions.default.options.cacheableOperations.push( + 'build-storybook' + ); + + updateNxJson(tree, nxJson); + } } export function projectIsRootProjectInStandaloneWorkspace(projectRoot: string) { diff --git a/packages/storybook/src/migrations/update-16-5-0/move-storybook-tsconfig.ts b/packages/storybook/src/migrations/update-16-5-0/move-storybook-tsconfig.ts index 387418beaa7e0..baeea742ceacc 100644 --- a/packages/storybook/src/migrations/update-16-5-0/move-storybook-tsconfig.ts +++ b/packages/storybook/src/migrations/update-16-5-0/move-storybook-tsconfig.ts @@ -27,6 +27,6 @@ export default async function (tree: Tree) { ); addStorybookToNamedInputs(tree); - addStorybookToTargetDefaults(tree); + addStorybookToTargetDefaults(tree, false); await formatFiles(tree); }