Skip to content

Commit 2614669

Browse files
authored
fix(angular): cache server build (#13933)
1 parent ae8e028 commit 2614669

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/angular/src/generators/setup-ssr/lib/update-project-config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import type { Tree } from '@nrwl/devkit';
22
import {
33
joinPathFragments,
44
readProjectConfiguration,
5+
readWorkspaceConfiguration,
56
updateProjectConfiguration,
7+
updateWorkspaceConfiguration,
68
} from '@nrwl/devkit';
79
import type { Schema } from '../schema';
810

@@ -72,4 +74,18 @@ export function updateProjectConfig(tree: Tree, schema: Schema) {
7274
};
7375

7476
updateProjectConfiguration(tree, schema.project, projectConfig);
77+
78+
const workspaceConfig = readWorkspaceConfiguration(tree);
79+
if (
80+
workspaceConfig.tasksRunnerOptions?.default &&
81+
!workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations.includes(
82+
'server'
83+
)
84+
) {
85+
workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations = [
86+
...workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations,
87+
'server',
88+
];
89+
updateWorkspaceConfiguration(tree, workspaceConfig);
90+
}
7591
}

packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
NxJsonConfiguration,
23
readJson,
34
readProjectConfiguration,
45
updateProjectConfiguration,
@@ -130,6 +131,23 @@ describe('setupSSR', () => {
130131
for (const [dep, version] of Object.entries(devDeps)) {
131132
expect(packageJson.devDependencies[dep]).toEqual(version);
132133
}
134+
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
135+
expect(nxJson.tasksRunnerOptions).toMatchInlineSnapshot(`
136+
Object {
137+
"default": Object {
138+
"options": Object {
139+
"cacheableOperations": Array [
140+
"build",
141+
"lint",
142+
"test",
143+
"e2e",
144+
"server",
145+
],
146+
},
147+
"runner": "nx/tasks-runners/default",
148+
},
149+
}
150+
`);
133151
});
134152

135153
it('should use fileReplacements if they already exist', async () => {

packages/react/src/generators/setup-ssr/setup-ssr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ export async function setupSsrGenerator(tree: Tree, options: Schema) {
168168
const workspace = readWorkspaceConfiguration(tree);
169169
if (
170170
workspace.tasksRunnerOptions?.default &&
171-
!workspace.tasksRunnerOptions.default.options.cacheableOperations['server']
171+
!workspace.tasksRunnerOptions.default.options.cacheableOperations.includes(
172+
'server'
173+
)
172174
) {
173175
workspace.tasksRunnerOptions.default.options.cacheableOperations = [
174176
...workspace.tasksRunnerOptions.default.options.cacheableOperations,

0 commit comments

Comments
 (0)