Nx Workspace

nrwl/nx/.cursor/skills/nx-workspace

作者 nrwl2989ece2ac76f5507cf8fa3be38d455273b89178無授權條款收錄於 2026年10月9日更新於 2026年10月9日

Explore and understand Nx workspaces. USE WHEN answering any questions about the nx workspace, the projects in it or tasks to run. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What targets can I run?', 'What's affected by my changes?', 'Which projects depend on library Y?', or any questions about Nx workspace structure, project configuration, or available tasks.

AI 產生的概覽

以唯讀方式探索 Nx 工作區:列出專案、查看專案設定、目標以及受影響的項目。

功能
此技能引導代理使用 Nx CLI 指令以唯讀方式檢視 Nx 工作區。內容涵蓋以篩選條件列出專案、以 JSON 取得專案的完整解析設定、查看目標及其執行器、選項、輸入與輸出,以及讀取工作區層級的 nx.json 設定。它也說明如何判斷受影響的專案,以及如何找出相依於某個程式庫的專案。
適用情境
適用於回答有關 Nx 工作區的問題,例如有哪些專案、某個專案如何設定、可以執行哪些目標、變更影響了哪些內容,或哪些專案相依於某個程式庫。其用途是理解工作區結構與設定,而非修改它們。
執行需求
需要一個 Nx 工作區,並可使用 Nx CLI,可直接呼叫或依鎖定檔透過 npx、pnpx 或 yarn 呼叫。指令可能使用 jq 解析 JSON、使用 git 偵測變更;不隨附指令碼。

Nx Workspace Exploration

This skill provides read-only exploration of Nx workspaces. Use it to understand workspace structure, project configuration, available targets, and dependencies.

Keep in mind that you might have to prefix commands with npx/pnpx/yarn if nx isn't installed globally. Check the lockfile to determine the package manager in use.

Listing Projects

Use nx show projects to list projects in the workspace.

bash
# List all projectsnx show projects
# Filter by pattern (glob)nx show projects --projects "apps/*"nx show projects --projects "shared-*"
# Filter by project typenx show projects --type appnx show projects --type libnx show projects --type e2e
# Filter by target (projects that have a specific target)nx show projects --withTarget buildnx show projects --withTarget e2e
# Find affected projects (changed since base branch)nx show projects --affectednx show projects --affected --base=mainnx show projects --affected --type app
# Combine filtersnx show projects --type lib --withTarget testnx show projects --affected --exclude="*-e2e"
# Output as JSONnx show projects --json

Project Configuration

Use nx show project <name> --json to get the full resolved configuration for a project.

Important: Do NOT read project.json directly - it only contains partial configuration. The nx show project command returns the full resolved config including inferred targets from plugins.

You can read the full project schema at node_modules/nx/schemas/project-schema.json to understand nx project configuration options.

bash
# Get full project configurationnx show project my-app --json
# Extract specific parts from the JSONnx show project my-app --json | jq '.targets'nx show project my-app --json | jq '.targets.build'nx show project my-app --json | jq '.targets | keys'
# Check project metadatanx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'

Target Information

Targets define what tasks can be run on a project.

bash
# List all targets for a projectnx show project my-app --json | jq '.targets | keys'
# Get full target configurationnx show project my-app --json | jq '.targets.build'
# Check target executor/commandnx show project my-app --json | jq '.targets.build.executor'nx show project my-app --json | jq '.targets.build.command'
# View target optionsnx show project my-app --json | jq '.targets.build.options'
# Check target inputs/outputs (for caching)nx show project my-app --json | jq '.targets.build.inputs'nx show project my-app --json | jq '.targets.build.outputs'
# Find projects with a specific targetnx show projects --withTarget servenx show projects --withTarget e2e

Workspace Configuration

Read nx.json directly for workspace-level configuration. You can read the full project schema at node_modules/nx/schemas/nx-schema.json to understand nx project configuration options.

bash
# Read the full nx.jsoncat nx.json
# Or use jq for specific sectionscat nx.json | jq '.targetDefaults'cat nx.json | jq '.namedInputs'cat nx.json | jq '.plugins'cat nx.json | jq '.generators'

Key nx.json sections:

  • targetDefaults - Default configuration applied to all targets of a given name
  • namedInputs - Reusable input definitions for caching
  • plugins - Nx plugins and their configuration
  • ...and much more, read the schema or nx.json for details

Affected Projects

Find projects affected by changes in the current branch.

bash
# Affected since base branch (auto-detected)nx show projects --affected
# Affected with explicit basenx show projects --affected --base=mainnx show projects --affected --base=origin/main
# Affected between two commitsnx show projects --affected --base=abc123 --head=def456
# Affected apps onlynx show projects --affected --type app
# Affected excluding e2e projectsnx show projects --affected --exclude="*-e2e"
# Affected by uncommitted changesnx show projects --affected --uncommitted
# Affected by untracked filesnx show projects --affected --untracked

Common Exploration Patterns

"What's in this workspace?"

bash
nx show projectsnx show projects --type appnx show projects --type lib

"How do I build/test/lint project X?"

bash
nx show project X --json | jq '.targets | keys'nx show project X --json | jq '.targets.build'

"What depends on library Y?"

bash
# Find projects that may depend on Y by searching for imports# (Nx doesn't have a direct "dependents" command via CLI)grep -r "from '@myorg/Y'" --include="*.ts" --include="*.tsx" apps/ libs/

"What configuration options are available?"

bash
cat node_modules/nx/schemas/nx-schema.json | jq '.properties | keys'cat node_modules/nx/schemas/project-schema.json | jq '.properties | keys'

"Why is project X affected?"

bash
# Check what files changedgit diff --name-only main
# See which project owns those filesnx show project X --json | jq '.root'

來源與署名

來源:nrwl/nx位於.cursor/skills/nx-workspace提交2989ece

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架