Skip to content

Commit

Permalink
fix(core): print args warning when base is not passed (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jun 26, 2020
1 parent bd0a558 commit 7218f81
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
4 changes: 3 additions & 1 deletion e2e/workspace/src/workspace-aux-commands.test.ts
Expand Up @@ -179,7 +179,9 @@ forEachCli((cli) => {
expect(stdout).not.toContain(`apps/${myapp}/src/app/app.component.ts`);

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

it('should support workspace-specific schematics', async () => {
Expand Down
6 changes: 1 addition & 5 deletions packages/workspace/src/command-line/affected.ts
@@ -1,7 +1,7 @@
import * as yargs from 'yargs';
import { generateGraph } from './dep-graph';
import { output } from '../utils/output';
import { parseFiles, printArgsWarning } from './shared';
import { parseFiles } from './shared';
import { runCommand } from '../tasks-runner/run-command';
import { NxArgs, splitArgsIntoNxArgsAndOverrides } from './utils';
import { filterAffected } from '../core/affected-project-graph';
Expand Down Expand Up @@ -52,7 +52,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
if (parsedArgs.plain) {
console.log(apps.join(' '));
} else {
printArgsWarning(nxArgs);
if (apps.length) {
output.log({
title: 'Affected apps:',
Expand All @@ -69,7 +68,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
if (parsedArgs.plain) {
console.log(libs.join(' '));
} else {
printArgsWarning(nxArgs);
if (libs.length) {
output.log({
title: 'Affected libs:',
Expand All @@ -81,7 +79,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {

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

Expand All @@ -108,7 +105,6 @@ export function affected(command: string, parsedArgs: yargs.Arguments): void {
affectedProjects,
nxArgs
);
printArgsWarning(nxArgs);
runCommand(
projectsWithTarget,
projectGraph,
Expand Down
3 changes: 1 addition & 2 deletions packages/workspace/src/command-line/format.ts
@@ -1,7 +1,7 @@
import { execSync } from 'child_process';
import * as path from 'path';
import * as resolve from 'resolve';
import { getProjectRoots, parseFiles, printArgsWarning } from './shared';
import { getProjectRoots, parseFiles } from './shared';
import { fileExists } from '../utils/fileutils';
import { output } from '../utils/output';
import { createProjectGraph } from '../core/project-graph';
Expand Down Expand Up @@ -71,7 +71,6 @@ function getPatterns(args: NxArgs & { libsAndApps: boolean; _: string[] }) {
return allFilesPattern;
}

printArgsWarning(args);
const p = parseFiles(args);
let patterns = p.files
.filter((f) => fileExists(f))
Expand Down
30 changes: 1 addition & 29 deletions packages/workspace/src/command-line/shared.ts
@@ -1,36 +1,8 @@
import { execSync } from 'child_process';
import { output } from '../utils/output';
import { createProjectGraph, ProjectGraphNode } from '../core/project-graph';
import { NxJson } from '../core/shared-interfaces';
import { readWorkspaceJson, TEN_MEGABYTES } from '../core/file-utils';
import { NxArgs, getAffectedConfig } from './utils';

export function printArgsWarning(options: NxArgs) {
const { files, uncommitted, untracked, base, head, all } = options;
const affectedConfig = getAffectedConfig();

if (!files && !uncommitted && !untracked && !base && !head && !all) {
output.note({
title: `Affected criteria defaulted to --base=${output.bold(
`${affectedConfig.defaultBase}`
)} --head=${output.bold('HEAD')}`,
});
}

if (all) {
output.warn({
title: `Running affected:* commands with --all can result in very slow builds.`,
bodyLines: [
output.bold('--all') +
' is not meant to be used for any sizable project or to be used in CI.',
'',
output.colors.gray(
'Learn more about checking only what is affected: '
) + 'https://nx.dev/guides/monorepo-affected.',
],
});
}
}
import { NxArgs } from './utils';

export function parseFiles(options: NxArgs): { files: string[] } {
const { files, uncommitted, untracked, base, head } = options;
Expand Down
29 changes: 29 additions & 0 deletions packages/workspace/src/command-line/utils.ts
Expand Up @@ -2,6 +2,7 @@ import * as yargsParser from 'yargs-parser';
import * as yargs from 'yargs';
import * as fileUtils from '../core/file-utils';
import { NxAffectedConfig } from '../core/shared-interfaces';
import { output } from '../utils/output';

const runOne = [
'target',
Expand Down Expand Up @@ -102,6 +103,7 @@ export function splitArgsIntoNxArgsAndOverrides(
}

if (mode === 'affected') {
printArgsWarning(nxArgs);
if (
!nxArgs.files &&
!nxArgs.uncommitted &&
Expand Down Expand Up @@ -141,3 +143,30 @@ export function getAffectedConfig(): NxAffectedConfig {
};
}
}

function printArgsWarning(options: NxArgs) {
const { files, uncommitted, untracked, base, head, all } = options;
const affectedConfig = getAffectedConfig();

if (!files && !uncommitted && !untracked && !base && !head && !all) {
output.note({
title: `Affected criteria defaulted to --base=${output.bold(
`${affectedConfig.defaultBase}`
)} --head=${output.bold('HEAD')}`,
});
}

if (all) {
output.warn({
title: `Running affected:* commands with --all can result in very slow builds.`,
bodyLines: [
output.bold('--all') +
' is not meant to be used for any sizable project or to be used in CI.',
'',
output.colors.gray(
'Learn more about checking only what is affected: '
) + 'https://nx.dev/guides/monorepo-affected.',
],
});
}
}

0 comments on commit 7218f81

Please sign in to comment.