From 025899cc562ae06cef30fcecf87cb972add58ea3 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Fri, 1 Sep 2023 11:43:13 -0600 Subject: [PATCH] fix(nextjs): Ensure build-custom-server is only added once to nx.json closes: #18957 --- .../generators/custom-server/custom-server.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/next/src/generators/custom-server/custom-server.ts b/packages/next/src/generators/custom-server/custom-server.ts index aa1fc1f3e7175..8f6e8ae3f9b23 100644 --- a/packages/next/src/generators/custom-server/custom-server.ts +++ b/packages/next/src/generators/custom-server/custom-server.ts @@ -3,7 +3,6 @@ import { updateJson, convertNxGenerator, generateFiles, - joinPathFragments, logger, offsetFromRoot, readProjectConfiguration, @@ -100,12 +99,18 @@ export async function customServerGenerator( updateProjectConfiguration(host, options.project, project); updateJson(host, 'nx.json', (json) => { - json.tasksRunnerOptions ??= {}; - json.tasksRunnerOptions.default ??= { options: {} }; - json.tasksRunnerOptions.default.options.cacheableOperations = [ - ...json.tasksRunnerOptions.default.options.cacheableOperations, - 'build-custom-server', - ]; + if ( + !json.tasksRunnerOptions?.default?.options?.cacheableOperations?.includes( + 'build-custom-server' + ) + ) { + json.tasksRunnerOptions ??= {}; + json.tasksRunnerOptions.default ??= { options: {} }; + json.tasksRunnerOptions.default.options.cacheableOperations = [ + ...json.tasksRunnerOptions.default.options.cacheableOperations, + 'build-custom-server', + ]; + } return json; }); }