Skip to content

Commit 7218f81

Browse files
committed
fix(core): print args warning when base is not passed (#3237)
1 parent bd0a558 commit 7218f81

File tree

5 files changed

+35
-37
lines changed

5 files changed

+35
-37
lines changed

e2e/workspace/src/workspace-aux-commands.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ forEachCli((cli) => {
179179
expect(stdout).not.toContain(`apps/${myapp}/src/app/app.component.ts`);
180180

181181
runCommand('npm run format:write -- --all');
182-
expect(runCommand('npm run -s format:check -- --all')).toEqual('');
182+
expect(runCommand('npm run -s format:check -- --all')).not.toContain(
183+
`apps/${myapp}/src/main.ts`
184+
);
183185
});
184186

185187
it('should support workspace-specific schematics', async () => {

packages/workspace/src/command-line/affected.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as yargs from 'yargs';
22
import { generateGraph } from './dep-graph';
33
import { output } from '../utils/output';
4-
import { parseFiles, printArgsWarning } from './shared';
4+
import { parseFiles } from './shared';
55
import { runCommand } from '../tasks-runner/run-command';
66
import { NxArgs, splitArgsIntoNxArgsAndOverrides } from './utils';
77
import { filterAffected } from '../core/affected-project-graph';
@@ -52,7 +52,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
5252
if (parsedArgs.plain) {
5353
console.log(apps.join(' '));
5454
} else {
55-
printArgsWarning(nxArgs);
5655
if (apps.length) {
5756
output.log({
5857
title: 'Affected apps:',
@@ -69,7 +68,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
6968
if (parsedArgs.plain) {
7069
console.log(libs.join(' '));
7170
} else {
72-
printArgsWarning(nxArgs);
7371
if (libs.length) {
7472
output.log({
7573
title: 'Affected libs:',
@@ -81,7 +79,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
8179

8280
case 'dep-graph':
8381
const projectNames = affectedProjects.map((p) => p.name);
84-
printArgsWarning(nxArgs);
8582
generateGraph(parsedArgs as any, projectNames);
8683
break;
8784

@@ -108,7 +105,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
108105
affectedProjects,
109106
nxArgs
110107
);
111-
printArgsWarning(nxArgs);
112108
runCommand(
113109
projectsWithTarget,
114110
projectGraph,

packages/workspace/src/command-line/format.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from 'child_process';
22
import * as path from 'path';
33
import * as resolve from 'resolve';
4-
import { getProjectRoots, parseFiles, printArgsWarning } from './shared';
4+
import { getProjectRoots, parseFiles } from './shared';
55
import { fileExists } from '../utils/fileutils';
66
import { output } from '../utils/output';
77
import { createProjectGraph } from '../core/project-graph';
@@ -71,7 +71,6 @@ function getPatterns(args: NxArgs & { libsAndApps: boolean; _: string[] }) {
7171
return allFilesPattern;
7272
}
7373

74-
printArgsWarning(args);
7574
const p = parseFiles(args);
7675
let patterns = p.files
7776
.filter((f) => fileExists(f))

packages/workspace/src/command-line/shared.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
11
import { execSync } from 'child_process';
2-
import { output } from '../utils/output';
32
import { createProjectGraph, ProjectGraphNode } from '../core/project-graph';
43
import { NxJson } from '../core/shared-interfaces';
54
import { readWorkspaceJson, TEN_MEGABYTES } from '../core/file-utils';
6-
import { NxArgs, getAffectedConfig } from './utils';
7-
8-
export function printArgsWarning(options: NxArgs) {
9-
const { files, uncommitted, untracked, base, head, all } = options;
10-
const affectedConfig = getAffectedConfig();
11-
12-
if (!files && !uncommitted && !untracked && !base && !head && !all) {
13-
output.note({
14-
title: `Affected criteria defaulted to --base=${output.bold(
15-
`${affectedConfig.defaultBase}`
16-
)} --head=${output.bold('HEAD')}`,
17-
});
18-
}
19-
20-
if (all) {
21-
output.warn({
22-
title: `Running affected:* commands with --all can result in very slow builds.`,
23-
bodyLines: [
24-
output.bold('--all') +
25-
' is not meant to be used for any sizable project or to be used in CI.',
26-
'',
27-
output.colors.gray(
28-
'Learn more about checking only what is affected: '
29-
) + 'https://nx.dev/guides/monorepo-affected.',
30-
],
31-
});
32-
}
33-
}
5+
import { NxArgs } from './utils';
346

357
export function parseFiles(options: NxArgs): { files: string[] } {
368
const { files, uncommitted, untracked, base, head } = options;

packages/workspace/src/command-line/utils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as yargsParser from 'yargs-parser';
22
import * as yargs from 'yargs';
33
import * as fileUtils from '../core/file-utils';
44
import { NxAffectedConfig } from '../core/shared-interfaces';
5+
import { output } from '../utils/output';
56

67
const runOne = [
78
'target',
@@ -102,6 +103,7 @@ export function splitArgsIntoNxArgsAndOverrides(
102103
}
103104

104105
if (mode === 'affected') {
106+
printArgsWarning(nxArgs);
105107
if (
106108
!nxArgs.files &&
107109
!nxArgs.uncommitted &&
@@ -141,3 +143,30 @@ export function getAffectedConfig(): NxAffectedConfig {
141143
};
142144
}
143145
}
146+
147+
function printArgsWarning(options: NxArgs) {
148+
const { files, uncommitted, untracked, base, head, all } = options;
149+
const affectedConfig = getAffectedConfig();
150+
151+
if (!files && !uncommitted && !untracked && !base && !head && !all) {
152+
output.note({
153+
title: `Affected criteria defaulted to --base=${output.bold(
154+
`${affectedConfig.defaultBase}`
155+
)} --head=${output.bold('HEAD')}`,
156+
});
157+
}
158+
159+
if (all) {
160+
output.warn({
161+
title: `Running affected:* commands with --all can result in very slow builds.`,
162+
bodyLines: [
163+
output.bold('--all') +
164+
' is not meant to be used for any sizable project or to be used in CI.',
165+
'',
166+
output.colors.gray(
167+
'Learn more about checking only what is affected: '
168+
) + 'https://nx.dev/guides/monorepo-affected.',
169+
],
170+
});
171+
}
172+
}

0 commit comments

Comments
 (0)