Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook): do not set cacheableOperations if not previously set #22535

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache option was introduced in Nx 17, but there's a migration for 16.5 using this utility. We don't set it in that case.

nxJson.targetDefaults['build-storybook'].cache ??= true;
}
nxJson.targetDefaults['build-storybook'].inputs ??= [
'default',
nxJson.namedInputs && 'production' in nxJson.namedInputs
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export default async function (tree: Tree) {
);

addStorybookToNamedInputs(tree);
addStorybookToTargetDefaults(tree);
addStorybookToTargetDefaults(tree, false);
await formatFiles(tree);
}