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.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
<!-- Fixes NXC-946 -->

Fixes #
This commit is contained in:
Leosvel Pérez Espinosa 2024-09-04 23:12:53 +02:00 committed by GitHub
parent 6a4a510e8f
commit ccda7f9f00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View File

@ -13,7 +13,7 @@ export const defaultYargsParserConfiguration: Partial<ParserConfigurationOptions
'parse-positional-numbers': false, 'parse-positional-numbers': false,
}; };
export function withExcludeOption(yargs: Argv): Argv<ExcludeOptions> { export function withExcludeOption<T>(yargs: Argv<T>): Argv<T & ExcludeOptions> {
return yargs.option('exclude', { return yargs.option('exclude', {
describe: 'Exclude certain projects from being processed', describe: 'Exclude certain projects from being processed',
type: 'string', type: 'string',
@ -37,6 +37,7 @@ export interface RunOptions {
batch: boolean; batch: boolean;
useAgents: boolean; useAgents: boolean;
excludeTaskDependencies: boolean; excludeTaskDependencies: boolean;
skipSync: boolean;
} }
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> { export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
@ -94,6 +95,11 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
type: 'boolean', type: 'boolean',
default: false, default: false,
}) })
.option('skipSync', {
type: 'boolean',
// TODO(leo): add description and make it visible once it is stable
hidden: true,
})
.options('cloud', { .options('cloud', {
type: 'boolean', type: 'boolean',
hidden: true, hidden: true,
@ -106,7 +112,7 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
type: 'boolean', type: 'boolean',
hidden: true, hidden: true,
alias: 'agents', alias: 'agents',
}) as Argv<Omit<RunOptions, 'exclude' | 'batch'>> as any; }) as Argv<Omit<RunOptions, 'batch'>> as any;
} }
export function withTargetAndConfigurationOption( export function withTargetAndConfigurationOption(

View File

@ -233,6 +233,10 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
extraOptions extraOptions
); );
if (nxArgs.skipSync) {
return { projectGraph, taskGraph };
}
// collect unique syncGenerators from the tasks // collect unique syncGenerators from the tasks
const uniqueSyncGenerators = collectEnabledTaskSyncGeneratorsFromTaskGraph( const uniqueSyncGenerators = collectEnabledTaskSyncGeneratorsFromTaskGraph(
taskGraph, taskGraph,
@ -255,7 +259,7 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
const outOfSyncTitle = 'The workspace is out of sync'; const outOfSyncTitle = 'The workspace is out of sync';
const resultBodyLines = [...syncGeneratorResultsToMessageLines(results), '']; const resultBodyLines = [...syncGeneratorResultsToMessageLines(results), ''];
const fixMessage = 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.'; const willErrorOnCiMessage = 'Please note that this will be an error on CI.';
if (isCI() || !process.stdout.isTTY) { if (isCI() || !process.stdout.isTTY) {

View File

@ -37,6 +37,7 @@ export interface NxArgs {
type?: string; type?: string;
batch?: boolean; batch?: boolean;
excludeTaskDependencies?: boolean; excludeTaskDependencies?: boolean;
skipSync?: boolean;
} }
export function createOverrides(__overrides_unparsed__: string[] = []) { export function createOverrides(__overrides_unparsed__: string[] = []) {