Skip to content

Commit

Permalink
feat(core): add support for tags selection in affected and run-many c…
Browse files Browse the repository at this point in the history
…ommands
  • Loading branch information
fguitton authored and AgentEnder committed Apr 5, 2023
1 parent 8b4e5f6 commit 86c0fa5
Show file tree
Hide file tree
Showing 66 changed files with 495 additions and 160 deletions.
8 changes: 7 additions & 1 deletion docs/generated/cli/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ Test proj1 and proj2 in sequence:
Test all projects ending with `*-app` except `excluded-app`. Note: your shell may require you to escape the `*` like this: `\*`:

```shell
nx run-many --target=test --projects=*-app --exclude excluded-app
nx run-many --target=test --projects=*-app --exclude=excluded-app
```

Test all projects with tags starting with `api-*`. Note: your shell may require you to escape the `*` like this: `\*`:

```shell
nx run-many --target=test --projects=tag:api-*
```

Run lint, test, and build targets for all projects. Requires Nx v15.4+:
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/angular/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"linter": {
"description": "The tool to use for running lint checks.",
Expand Down Expand Up @@ -165,7 +165,7 @@
},
"additionalProperties": false,
"required": ["name"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/angular:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n```bash\nnx g @nrwl/angular:app my-app --directory=my-dir --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Single File Components application\" %}\n\nCreate an application with Single File Components (inline styles and inline templates):\n\n```bash\nnx g @nrwl/angular:app my-app --inlineStyle --inlineTemplate\n```\n\n{% /tab %}\n\n{% tab label=\"Standalone Components application\" %}\n\nCreate an application that is setup to use standalone components:\n\n```bash\nnx g @nrwl/angular:app my-app --standalone\n```\n\n{% /tab %}\n\n{% tab label=\"Set custom prefix and tags\" %}\n\nSet the prefix to apply to generated selectors and add tags to the application (used for linting).\n\n```bash\nnx g @nrwl/angular:app my-app --prefix=admin --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/angular:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n```bash\nnx g @nrwl/angular:app my-app --directory=my-dir --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Single File Components application\" %}\n\nCreate an application with Single File Components (inline styles and inline templates):\n\n```bash\nnx g @nrwl/angular:app my-app --inlineStyle --inlineTemplate\n```\n\n{% /tab %}\n\n{% tab label=\"Standalone Components application\" %}\n\nCreate an application that is setup to use standalone components:\n\n```bash\nnx g @nrwl/angular:app my-app --standalone\n```\n\n{% /tab %}\n\n{% tab label=\"Set custom prefix and tags\" %}\n\nSet the prefix to apply to generated selectors and add tags to the application.\n\n```bash\nnx g @nrwl/angular:app my-app --prefix=admin --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"presets": []
},
"aliases": ["app"],
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/angular/generators/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"linter": {
"description": "The tool to use for running lint checks.",
Expand Down
5 changes: 1 addition & 4 deletions docs/generated/packages/angular/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@
"description": "Path to the parent route configuration using `loadChildren` or `children`, depending on what `lazy` is set to.",
"x-priority": "important"
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting)."
},
"tags": { "type": "string", "description": "Add tags to the library." },
"unitTestRunner": {
"type": "string",
"enum": ["jest", "none"],
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/angular/generators/remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"linter": {
"description": "The tool to use for running lint checks.",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/expo/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)",
"description": "Add tags to the application",
"alias": "t"
},
"js": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/expo/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"frontendProject": {
"type": "string",
Expand Down
5 changes: 1 addition & 4 deletions docs/generated/packages/js/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
"description": "Test runner to use for unit tests.",
"x-prompt": "Which unit test runner would you like to use?"
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting)."
},
"tags": { "type": "string", "description": "Add tags to the library." },
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/nest/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"default": "jest"
},
"tags": {
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"type": "string"
},
"frontendProject": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/nest/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"default": "jest"
},
"tags": {
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"type": "string",
"alias": "t"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/next/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"alias": "t"
},
"js": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/next/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/node/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"frontendProject": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/node/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/nx-plugin/generators/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
8 changes: 7 additions & 1 deletion docs/generated/packages/nx/documents/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ Test proj1 and proj2 in sequence:
Test all projects ending with `*-app` except `excluded-app`. Note: your shell may require you to escape the `*` like this: `\*`:

```shell
nx run-many --target=test --projects=*-app --exclude excluded-app
nx run-many --target=test --projects=*-app --exclude=excluded-app
```

Test all projects with tags starting with `api-*`. Note: your shell may require you to escape the `*` like this: `\*`:

```shell
nx run-many --target=test --projects=tag:api-*
```

Run lint, test, and build targets for all projects. Requires Nx v15.4+:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"alias": "t"
},
"js": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/react/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"alias": "t"
},
"pascalCaseFiles": {
Expand Down Expand Up @@ -192,7 +192,7 @@
}
},
"required": [],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/react:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/react:app my-app --bundler=vite\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n```bash\nnx g @nrwl/react:app my-app --directory=my-dir --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application (used for linting).\n\n```bash\nnx g @nrwl/react:app my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/react:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/react:app my-app --bundler=vite\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n```bash\nnx g @nrwl/react:app my-app --directory=my-dir --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application.\n\n```bash\nnx g @nrwl/react:app my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"presets": []
},
"aliases": ["app"],
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"alias": "t"
},
"pascalCaseFiles": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"description": "Add tags to the library.",
"alias": "t"
},
"skipFormat": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting).",
"description": "Add tags to the application.",
"alias": "t"
},
"pascalCaseFiles": {
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/web/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)"
"description": "Add tags to the application"
},
"setParserOptionsProject": {
"type": "boolean",
Expand All @@ -104,7 +104,7 @@
}
},
"required": ["name"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/web:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/web:app my-app --bundler=vite\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory\" %}\n\nCreate an application named `my-app` in the `my-dir` directory:\n\n```bash\nnx g @nrwl/web:app my-app --directory=my-dir\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application (used for linting).\n\n```bash\nnx g @nrwl/web:app my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/web:application my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nrwl/web:app my-app --bundler=vite\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory\" %}\n\nCreate an application named `my-app` in the `my-dir` directory:\n\n```bash\nnx g @nrwl/web:app my-app --directory=my-dir\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application.\n\n```bash\nnx g @nrwl/web:app my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n",
"presets": []
},
"aliases": ["app"],
Expand Down
5 changes: 1 addition & 4 deletions docs/generated/packages/workspace/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
"description": "Test runner to use for unit tests.",
"default": "jest"
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting)."
},
"tags": { "type": "string", "description": "Add tags to the library." },
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/generators/generator-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ The alias of this property. Example:
{
"tags": {
"type": "string",
"description": "Add tags to the project (used for linting)",
"description": "Add tags to the project",
"alias": "t"
},
"directory": {
Expand Down
12 changes: 10 additions & 2 deletions e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Nx Affected and Graph Tests', () => {
runCLI(`generate @nrwl/js:lib ${mylib}`);
runCLI(`generate @nrwl/js:lib ${mylib2}`);
runCLI(
`generate @nrwl/js:lib ${mypublishablelib} --publishable --importPath=@${proj}/${mypublishablelib}`
`generate @nrwl/js:lib ${mypublishablelib} --publishable --importPath=@${proj}/${mypublishablelib} --tags=ui`
);

updateFile(
Expand Down Expand Up @@ -135,11 +135,19 @@ describe('Nx Affected and Graph Tests', () => {
expect(build).toContain('Successfully ran target build');

const buildExcluded = runCLI(
`affected:build --files="libs/${mylib}/src/index.ts" --exclude ${myapp}`
`affected:build --files="libs/${mylib}/src/index.ts" --exclude=${myapp}`
);
expect(buildExcluded).toContain(`Running target build for 2 projects:`);
expect(buildExcluded).toContain(`- ${mypublishablelib}`);

const buildExcludedByTag = runCLI(
`affected:build --files="libs/${mylib}/src/index.ts" --exclude=tag:ui`
);
expect(buildExcludedByTag).toContain(
`Running target build for 2 projects:`
);
expect(buildExcludedByTag).not.toContain(`- ${mypublishablelib}`);

// test
updateFile(
`apps/${myapp}/src/app/app.element.spec.ts`,
Expand Down
42 changes: 39 additions & 3 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,13 @@ describe('Nx Running Tests', () => {

runCLI(`generate @nrwl/web:app ${appA}`);
runCLI(`generate @nrwl/js:lib ${libA} --bundler=tsc --defaults`);
runCLI(`generate @nrwl/js:lib ${libB} --bundler=tsc --defaults`);
runCLI(`generate @nrwl/js:lib ${libC} --bundler=tsc --defaults`);
runCLI(`generate @nrwl/node:lib ${libD} --defaults`);
runCLI(
`generate @nrwl/js:lib ${libB} --bundler=tsc --defaults --tags=ui-a`
);
runCLI(
`generate @nrwl/js:lib ${libC} --bundler=tsc --defaults --tags=ui-b,shared`
);
runCLI(`generate @nrwl/node:lib ${libD} --defaults --tags=api`);

// libA depends on libC
updateFile(
Expand All @@ -462,6 +466,7 @@ describe('Nx Running Tests', () => {
`run-many --target=build --projects="${libC},${libB}"`
);
expect(buildParallel).toContain(`Running target build for 2 projects:`);
expect(buildParallel).not.toContain(`- ${appA}`);
expect(buildParallel).not.toContain(`- ${libA}`);
expect(buildParallel).toContain(`- ${libB}`);
expect(buildParallel).toContain(`- ${libC}`);
Expand All @@ -480,13 +485,44 @@ describe('Nx Running Tests', () => {
expect(buildAllParallel).not.toContain(`- ${libD}`);
expect(buildAllParallel).toContain('Successfully ran target build');

// testing run many by tags
const buildByTagParallel = runCLI(
`run-many --target=build --projects="tag:ui*"`
);
expect(buildByTagParallel).toContain(
`Running target build for 2 projects:`
);
expect(buildByTagParallel).not.toContain(`- ${appA}`);
expect(buildByTagParallel).not.toContain(`- ${libA}`);
expect(buildByTagParallel).toContain(`- ${libB}`);
expect(buildByTagParallel).toContain(`- ${libC}`);
expect(buildByTagParallel).not.toContain(`- ${libD}`);
expect(buildByTagParallel).toContain('Successfully ran target build');

// testing run many with exclude
const buildWithExcludeParallel = runCLI(
`run-many --target=build --exclude="${libD},tag:ui*"`
);
expect(buildWithExcludeParallel).toContain(
`Running target build for 2 projects and 1 task they depend on:`
);
expect(buildWithExcludeParallel).toContain(`- ${appA}`);
expect(buildWithExcludeParallel).toContain(`- ${libA}`);
expect(buildWithExcludeParallel).not.toContain(`- ${libB}`);
expect(buildWithExcludeParallel).toContain(`${libC}`); // should still include libC as dependency despite exclude
expect(buildWithExcludeParallel).not.toContain(`- ${libD}`);
expect(buildWithExcludeParallel).toContain(
'Successfully ran target build'
);

// testing run many when project depends on other projects
const buildWithDeps = runCLI(
`run-many --target=build --projects="${libA}"`
);
expect(buildWithDeps).toContain(
`Running target build for project ${libA} and 1 task it depends on:`
);
expect(buildWithDeps).not.toContain(`- ${appA}`);
expect(buildWithDeps).toContain(`- ${libA}`);
expect(buildWithDeps).toContain(`${libC}`); // build should include libC as dependency
expect(buildWithDeps).not.toContain(`- ${libB}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/docs/application-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ nx g @nrwl/angular:app my-app --standalone

{% tab label="Set custom prefix and tags" %}

Set the prefix to apply to generated selectors and add tags to the application (used for linting).
Set the prefix to apply to generated selectors and add tags to the application.

```bash
nx g @nrwl/angular:app my-app --prefix=admin --tags=scope:admin,type:ui
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
},
"tags": {
"type": "string",
"description": "Add tags to the application (used for linting)."
"description": "Add tags to the application."
},
"linter": {
"description": "The tool to use for running lint checks.",
Expand Down
Loading

0 comments on commit 86c0fa5

Please sign in to comment.