Skip to content

Commit

Permalink
feat(core): allow skipping sync when running tasks (nrwl#27697)
Browse files Browse the repository at this point in the history
- 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 #
  • Loading branch information
leosvelperez authored and ZackDeRose committed Sep 6, 2024
1 parent 3c35366 commit 9f672df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/nx/src/command-line/yargs-utils/shared-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const defaultYargsParserConfiguration: Partial<ParserConfigurationOptions
'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', {
describe: 'Exclude certain projects from being processed',
type: 'string',
Expand All @@ -37,6 +37,7 @@ export interface RunOptions {
batch: boolean;
useAgents: boolean;
excludeTaskDependencies: boolean;
skipSync: boolean;
}

export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
Expand Down Expand Up @@ -94,6 +95,11 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
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,
Expand All @@ -106,7 +112,7 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
type: 'boolean',
hidden: true,
alias: 'agents',
}) as Argv<Omit<RunOptions, 'exclude' | 'batch'>> as any;
}) as Argv<Omit<RunOptions, 'batch'>> as any;
}

export function withTargetAndConfigurationOption(
Expand Down
6 changes: 5 additions & 1 deletion packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
extraOptions
);

if (nxArgs.skipSync) {
return { projectGraph, taskGraph };
}

// collect unique syncGenerators from the tasks
const uniqueSyncGenerators = collectEnabledTaskSyncGeneratorsFromTaskGraph(
taskGraph,
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/utils/command-line-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface NxArgs {
type?: string;
batch?: boolean;
excludeTaskDependencies?: boolean;
skipSync?: boolean;
}

export function createOverrides(__overrides_unparsed__: string[] = []) {
Expand Down

0 comments on commit 9f672df

Please sign in to comment.