From 381efa8e0d2485761bf27c5ed8cc95e2a3602753 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 31 Jul 2024 10:45:56 -0500 Subject: [PATCH] =?UTF-8?q?fix(core):=20show=20target=20description,=20add?= =?UTF-8?q?=20metadata=20to=20schema,=20and=20docum=E2=80=A6=20(#27131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …ent it ## Current Behavior Target description is not shown in the PDV. Also, being able to set a description in `project.json` is not in the schema nor is it documented. ## Expected Behavior Target descriptions are shown in the PDV. Also, being able to set a description in `project.json` is in the schema and documented on https://nx-dev-git-metadata-docs-nrwl.vercel.app/project-configuration#target-metadata ![image](https://github.com/user-attachments/assets/2037eca8-d516-4513-81fd-12b8384a9411) ## Related Issue(s) Fixes https://github.com/nrwl/nx/issues/19355 --- .../shared/reference/project-configuration.md | 33 ++++++++++++- .../target-configuration-details.tsx | 19 ++++++++ packages/nx/schemas/project-schema.json | 46 ++++++++++++++++--- 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/docs/shared/reference/project-configuration.md b/docs/shared/reference/project-configuration.md index 83c5af40b7..bd65924cc0 100644 --- a/docs/shared/reference/project-configuration.md +++ b/docs/shared/reference/project-configuration.md @@ -650,6 +650,23 @@ In the case of an explicit target using an executor, you can specify the executo } ``` +### Target Metadata + +You can add additional metadata to be attached to a target. For example, you can provide a description stating what the +target does: + +```jsonc {% fileName="project.json" %} +{ + "targets": { + "build": { + "metadata": { + "description": "Build the application for production" + } + } + } +} +``` + ## Project Metadata The following properties describe the project as a whole. @@ -769,7 +786,21 @@ An implicit dependency could also be a glob pattern: {% /tab %} {% /tabs %} -### Including package.json files as projects in the graph +### Metadata + +You can add additional metadata to be attached to the project. For example, you can provide a description for your +project: + +```jsonc {% fileName="project.json" %} +{ + "name": "admin", + "metadata": { + "description": "This is the admin application" + } +} +``` + +## Including package.json files as projects in the graph Any `package.json` file that is referenced by the `workspaces` property in the root `package.json` file will be included as a project in the graph. If you are using Lerna, projects defined in `lerna.json` will be included. If you are using pnpm, projects defined in `pnpm-workspace.yml` will be included. diff --git a/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx b/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx index 5a8b05b629..bb99534f98 100644 --- a/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx +++ b/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx @@ -103,6 +103,25 @@ export default function TargetConfigurationDetails({ {/* body */} {!collapsed && (
+ {targetConfiguration.metadata?.description && ( +
+

+ Description + + + +

+

+ {targetConfiguration.metadata?.description} +

+
+ )} +

diff --git a/packages/nx/schemas/project-schema.json b/packages/nx/schemas/project-schema.json index cb8fa2b220..2e62de0559 100644 --- a/packages/nx/schemas/project-schema.json +++ b/packages/nx/schemas/project-schema.json @@ -115,8 +115,12 @@ "required": ["target"], "not": { "anyOf": [ - { "required": ["projects"] }, - { "required": ["dependencies"] } + { + "required": ["projects"] + }, + { + "required": ["dependencies"] + } ] } } @@ -138,6 +142,17 @@ "type": "boolean", "default": true, "description": "Whether this target can be run in parallel with other tasks" + }, + "metadata": { + "type": "object", + "description": "Metadata about the target", + "properties": { + "description": { + "type": "string", + "description": "A description of the target" + } + }, + "additionalProperties": true } } } @@ -154,6 +169,17 @@ "type": "string" } }, + "metadata": { + "type": "object", + "description": "Metadata about the project.", + "properties": { + "description": { + "type": "string", + "description": "A description of the project." + } + }, + "additionalProperties": true + }, "release": { "type": "object", "description": "Configuration for the nx release commands.", @@ -205,7 +231,9 @@ { "type": "array", "description": "The projects that the targets belong to.", - "items": { "type": "string" } + "items": { + "type": "string" + } } ] }, @@ -229,8 +257,12 @@ "required": ["input"], "not": { "anyOf": [ - { "required": ["projects"] }, - { "required": ["dependencies"] } + { + "required": ["projects"] + }, + { + "required": ["dependencies"] + } ] } } @@ -262,7 +294,9 @@ "properties": { "externalDependencies": { "type": "array", - "items": { "type": "string" }, + "items": { + "type": "string" + }, "description": "The list of external dependencies that our target depends on for `nx:run-commands` and community plugins." } },