From ccda7f9f0011ff9ba93f8c19dce826fb4ba30ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 4 Sep 2024 23:12:53 +0200 Subject: [PATCH] feat(core): allow skipping sync when running tasks (#27697) - Add a new flag `--skipSync` to the run commands to skip running syncing when running tasks. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- .../nx/src/command-line/yargs-utils/shared-options.ts | 10 ++++++++-- packages/nx/src/tasks-runner/run-command.ts | 6 +++++- packages/nx/src/utils/command-line-utils.ts | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/command-line/yargs-utils/shared-options.ts b/packages/nx/src/command-line/yargs-utils/shared-options.ts index f93fc2d2330aa..06c78c7fdb986 100644 --- a/packages/nx/src/command-line/yargs-utils/shared-options.ts +++ b/packages/nx/src/command-line/yargs-utils/shared-options.ts @@ -13,7 +13,7 @@ export const defaultYargsParserConfiguration: Partial { +export function withExcludeOption(yargs: Argv): Argv { return yargs.option('exclude', { describe: 'Exclude certain projects from being processed', type: 'string', @@ -37,6 +37,7 @@ export interface RunOptions { batch: boolean; useAgents: boolean; excludeTaskDependencies: boolean; + skipSync: boolean; } export function withRunOptions(yargs: Argv): Argv { @@ -94,6 +95,11 @@ export function withRunOptions(yargs: Argv): Argv { type: 'boolean', default: false, }) + .option('skipSync', { + type: 'boolean', + // TODO(leo): add description and make it visible once it is stable + hidden: true, + }) .options('cloud', { type: 'boolean', hidden: true, @@ -106,7 +112,7 @@ export function withRunOptions(yargs: Argv): Argv { type: 'boolean', hidden: true, alias: 'agents', - }) as Argv> as any; + }) as Argv> as any; } export function withTargetAndConfigurationOption( diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index c249dcc17c84d..f944cf9db2dcb 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -233,6 +233,10 @@ async function ensureWorkspaceIsInSyncAndGetGraphs( extraOptions ); + if (nxArgs.skipSync) { + return { projectGraph, taskGraph }; + } + // collect unique syncGenerators from the tasks const uniqueSyncGenerators = collectEnabledTaskSyncGeneratorsFromTaskGraph( taskGraph, @@ -255,7 +259,7 @@ async function ensureWorkspaceIsInSyncAndGetGraphs( const outOfSyncTitle = 'The workspace is out of sync'; const resultBodyLines = [...syncGeneratorResultsToMessageLines(results), '']; const fixMessage = - 'You can manually run `nx sync` to update your workspace or you can set `sync.applyChanges` to `true` in your `nx.json` to apply the changes automatically when running tasks.'; + 'You can manually run `nx sync` to update your workspace or you can set `sync.applyChanges` to `true` in your `nx.json` to apply the changes automatically when running tasks in interactive environments.'; const willErrorOnCiMessage = 'Please note that this will be an error on CI.'; if (isCI() || !process.stdout.isTTY) { diff --git a/packages/nx/src/utils/command-line-utils.ts b/packages/nx/src/utils/command-line-utils.ts index 69f6a2e392c1f..688f511fb5541 100644 --- a/packages/nx/src/utils/command-line-utils.ts +++ b/packages/nx/src/utils/command-line-utils.ts @@ -37,6 +37,7 @@ export interface NxArgs { type?: string; batch?: boolean; excludeTaskDependencies?: boolean; + skipSync?: boolean; } export function createOverrides(__overrides_unparsed__: string[] = []) {