Skip to content

Commit

Permalink
feat(core): add the ability to specify multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Dec 22, 2022
1 parent 376a4ca commit 8572eed
Show file tree
Hide file tree
Showing 33 changed files with 337 additions and 218 deletions.
6 changes: 3 additions & 3 deletions docs/generated/cli/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### uncommitted

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/cli/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### verbose

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/cli/print-affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ Type: `string`

Select the subset of the returned json document (e.g., --select=projects)

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### type

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/cli/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### verbose

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/packages/nx/documents/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### uncommitted

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/packages/nx/documents/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### verbose

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/packages/nx/documents/print-affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ Type: `string`

Select the subset of the returned json document (e.g., --select=projects)

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### type

Expand Down
6 changes: 3 additions & 3 deletions docs/generated/packages/nx/documents/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target
### targets

Type: `string`
Type: `array`

Task to run for affected projects
Tasks to run for affected projects

### verbose

Expand Down
4 changes: 2 additions & 2 deletions docs/shared/angular-standalone-tutorial/4-task-pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Build at: 2022-11-30T16:44:43.171Z - Hash: 9850ece7cc7c6b7c - Time: 6527ms
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 1 task(s) it depends on (9s)
> NX Successfully ran target build for project store and 1 task(s) they depend on (9s)
```

Expand Down Expand Up @@ -100,7 +100,7 @@ Build at: 2022-11-30T16:44:43.171Z - Hash: 9850ece7cc7c6b7c - Time: 6527ms
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 1 task(s) it depends on (13ms)
> NX Successfully ran target build for project store and 1 task(s) they depend on (13ms)
Nx read the output from the cache instead of running the command for 2 out of 2 tasks.
```
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/angular-tutorial/4-workspace-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Build at: 2022-11-23T22:53:29.097Z - Hash: 3cd478c78ebeead2 - Time: 5154ms
————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 1 task(s) it depends on (8s)
> NX Successfully ran target build for project store and 1 task(s) they depend on (8s)
```

Notice the line here:
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/node-tutorial/4-workspace-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ webpack compiled successfully (bafa37be9890ecb2)
———————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project products-cli and 1 task(s) it depends on (2s)
> NX Successfully ran target build for project products-cli and 1 task(s) they depend on (2s)
Nx read the output from the cache instead of running the command for 1 out of 2 tasks.
```
Expand Down
4 changes: 2 additions & 2 deletions docs/shared/react-standalone-tutorial/4-task-pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dist/store/assets/index.f18c2b19.js.map 565.79 KiB
————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 2 task(s) it depends on (6s)
> NX Successfully ran target build for project store and 2 task(s) they depend on (6s)
```

Expand Down Expand Up @@ -86,7 +86,7 @@ dist/store/assets/index.f18c2b19.js.map 565.79 KiB
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 2 task(s) it depends on (42ms)
> NX Successfully ran target build for project store and 2 task(s) they depend on (42ms)
Nx read the output from the cache instead of running the command for 3 out of 3 tasks.
```
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/react-tutorial/4-workspace-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ webpack compiled successfully (06e95dfdacea84c7)
———————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project store and 1 task(s) it depends on (5s)
> NX Successfully ran target build for project store and 1 task(s) they depend on (5s)
```

Notice the line here:
Expand Down
4 changes: 2 additions & 2 deletions e2e/js/src/js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('js e2e', () => {
});

const output = runCLI(`build ${parentLib}`);
expect(output).toContain('1 task(s) it depends on');
expect(output).toContain('1 task it depends on');
expect(output).toContain('Done compiling TypeScript files');

updateJson(`libs/${lib}/tsconfig.json`, (json) => {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('js e2e', () => {
});

const output = runCLI(`build ${parentLib}`);
expect(output).toContain('1 task(s) it depends on');
expect(output).toContain('1 task it depends on');
expect(output).toContain('Successfully compiled: 2 files with swc');

updateJson(`libs/${lib}/.lib.swcrc`, (json) => {
Expand Down
8 changes: 6 additions & 2 deletions e2e/linter/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ export function tslibC(): string {
const fixedStout = runCLI(`lint ${libC} --fix`, {
silenceError: true,
});
expect(fixedStout).toContain('Successfully ran target lint for project');
expect(fixedStout).toContain(
`Successfully ran target lint for project ${libC}`
);

const fileContent = readFile(`libs/${libC}/src/lib/tslib-c-another.ts`);
expect(fileContent).toContain(`import { tslibC } from './tslib-c';`);
Expand All @@ -424,7 +426,9 @@ export function tslibC(): string {
const fixedStout = runCLI(`lint ${libB} --fix`, {
silenceError: true,
});
expect(fixedStout).toContain('Successfully ran target lint for project');
expect(fixedStout).toContain(
`Successfully ran target lint for project ${libB}`
);

const fileContent = readFile(`libs/${libB}/src/lib/tslib-b.ts`);
expect(fileContent).toContain(
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Nx Affected and Graph Tests', () => {
const build = runCLI(
`affected:build --files="libs/${mylib}/src/index.ts" --parallel`
);
expect(build).toContain(`Running target build for 3 project(s):`);
expect(build).toContain(`Running target build for 3 projects:`);
expect(build).toContain(`- ${myapp}`);
expect(build).toContain(`- ${mypublishablelib}`);
expect(build).not.toContain('is not registered with the build command');
Expand All @@ -138,7 +138,7 @@ describe('Nx Affected and Graph Tests', () => {
const buildExcluded = runCLI(
`affected:build --files="libs/${mylib}/src/index.ts" --exclude ${myapp}`
);
expect(buildExcluded).toContain(`Running target build for 2 project(s):`);
expect(buildExcluded).toContain(`Running target build for 2 projects:`);
expect(buildExcluded).toContain(`- ${mypublishablelib}`);

// test
Expand Down
27 changes: 20 additions & 7 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe('Nx Running Tests', () => {

const output = runCLI(`build ${myapp}`);
expect(output).toContain(
`NX Running target build for project ${myapp} and 3 task(s) it depends on`
`NX Running target build for project ${myapp} and 3 tasks it depends on`
);
expect(output).toContain(myapp);
expect(output).toContain(mylib1);
Expand All @@ -310,7 +310,7 @@ describe('Nx Running Tests', () => {

const output = runCLI(`build ${myapp}`);
expect(output).toContain(
`NX Running target build for project ${myapp} and 2 task(s) it depends on`
`NX Running target build for project ${myapp} and 2 tasks it depends on`
);
expect(output).toContain(myapp);
expect(output).toContain(mylib1);
Expand Down Expand Up @@ -347,7 +347,7 @@ describe('Nx Running Tests', () => {

const output = runCLI(`outside ${myapp}`);
expect(output).toContain(
`NX Running target outside for project ${myapp} and 1 task(s) it depends on`
`NX Running target outside for project ${myapp} and 1 task it depends on`
);

removeFile(`one.txt`);
Expand Down Expand Up @@ -391,7 +391,7 @@ describe('Nx Running Tests', () => {
const buildParallel = runCLI(
`run-many --target=build --projects="${libC},${libB}"`
);
expect(buildParallel).toContain(`Running target build for 2 project(s):`);
expect(buildParallel).toContain(`Running target build for 2 projects:`);
expect(buildParallel).not.toContain(`- ${libA}`);
expect(buildParallel).toContain(`- ${libB}`);
expect(buildParallel).toContain(`- ${libC}`);
Expand All @@ -401,7 +401,7 @@ describe('Nx Running Tests', () => {
// testing run many --all starting
const buildAllParallel = runCLI(`run-many --target=build`);
expect(buildAllParallel).toContain(
`Running target build for 4 project(s):`
`Running target build for 4 projects:`
);
expect(buildAllParallel).toContain(`- ${appA}`);
expect(buildAllParallel).toContain(`- ${libA}`);
Expand All @@ -415,7 +415,7 @@ describe('Nx Running Tests', () => {
`run-many --target=build --projects="${libA}"`
);
expect(buildWithDeps).toContain(
`Running target build for 1 project(s) and 1 task(s) they depend on:`
`Running target build for project ${libA} and 1 task it depends on:`
);
expect(buildWithDeps).toContain(`- ${libA}`);
expect(buildWithDeps).toContain(`${libC}`); // build should include libC as dependency
Expand All @@ -428,7 +428,7 @@ describe('Nx Running Tests', () => {
`run-many --target=build --projects="${appA},${libA}" --prod`
);
expect(buildConfig).toContain(
`Running target build for 2 project(s) and 1 task(s) they depend on:`
`Running target build for 2 projects and 1 task they depend on:`
);
expect(buildConfig).toContain(`run ${appA}:build:production`);
expect(buildConfig).toContain(`run ${libA}:build`);
Expand All @@ -441,6 +441,19 @@ describe('Nx Running Tests', () => {
});
expect(buildWithDaemon).toContain(`Successfully ran target build`);
}, 1000000);

it('should run multiple targets', () => {
const myapp1 = uniq('myapp');
const myapp2 = uniq('myapp');
runCLI(`generate @nrwl/web:app ${myapp1}`);
runCLI(`generate @nrwl/web:app ${myapp2}`);

let outputs = runCLI(`run-many -t build test -p ${myapp1} ${myapp2}`);
expect(outputs).toContain('Running targets build, test for 2 projects:');

outputs = runCLI(`run-many -t build test -p=${myapp1},${myapp2}`);
expect(outputs).toContain('Running targets build, test for 2 projects:');
});
});

describe('exec', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/nx/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function affected(
break;

case 'print-affected':
if (nxArgs.target) {
if (nxArgs.targets && nxArgs.targets.length > 0) {
await printAffected(
allProjectsWithTarget(projects, nxArgs),
projectGraph,
Expand Down Expand Up @@ -163,7 +163,9 @@ function allProjectsWithTarget(
projects: ProjectGraphProjectNode[],
nxArgs: NxArgs
) {
return projects.filter((p) => projectHasTarget(p, nxArgs.target));
return projects.filter((p) =>
nxArgs.targets.find((target) => projectHasTarget(p, target))
);
}

function printError(e: any, verbose?: boolean) {
Expand Down
14 changes: 10 additions & 4 deletions packages/nx/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,12 @@ function withRunManyOptions(yargs: yargs.Argv): yargs.Argv {
'populate--': true,
})
.option('projects', {
type: 'array',
string: true,
alias: 'p',
coerce: parseCSV,
describe:
'Projects to run. (comma delimited project names and/or patterns)',
type: 'string',
})
.option('all', {
describe: '[deprecated] Run the target on all projects in the workspace',
Expand Down Expand Up @@ -649,10 +652,12 @@ function withTargetAndConfigurationOption(
yargs: yargs.Argv,
demandOption = true
): yargs.Argv {
return withConfiguration(yargs).option('target', {
describe: 'Task to run for affected projects',
type: 'string',
return withConfiguration(yargs).option('targets', {
describe: 'Tasks to run for affected projects',
type: 'array',
alias: ['target', 't'],
requiresArg: true,
coerce: parseCSV,
demandOption,
global: false,
});
Expand Down Expand Up @@ -946,6 +951,7 @@ function withWatchOptions(yargs: yargs.Argv) {
.option('projects', {
type: 'array',
string: true,
alias: 'p',
coerce: parseCSV,
description: 'Projects to watch (comma delimited).',
})
Expand Down
Loading

1 comment on commit 8572eed

@vercel
Copy link

@vercel vercel bot commented on 8572eed Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.