nx-workspace
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNx Workspace Exploration
Nx工作区探索
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 // if nx isn't installed globally. Check the lockfile to determine the package manager in use.
npxpnpxyarn本技能提供Nx工作区的只读探索功能,可用于了解工作区结构、项目配置、可用目标任务及依赖关系。
请记住,如果未全局安装nx,你可能需要在命令前添加//前缀。可以通过锁文件确定当前使用的包管理器。
npxpnpxyarnListing Projects
列出项目
Use to list projects in the workspace.
nx show projectsThe project filtering syntax (/) works across many Nx commands including , , , and more. Filters support explicit names, glob patterns, tag references (e.g. ), directories, and negation (e.g. ).
-p--projectsnx run-manynx releasenx show projectstag:name!project-namebash
undefined使用命令列出工作区中的项目。
nx show projects项目过滤语法(/)适用于众多Nx命令,包括、、等。过滤器支持明确的项目名称、通配符模式、标签引用(如)、目录路径以及取反操作(如)。
-p--projectsnx run-manynx releasenx show projectstag:name!project-namebash
undefinedList all projects
列出所有项目
nx show projects
nx show projects
Filter by pattern (glob)
按通配符模式过滤
nx show projects --projects "apps/"
nx show projects --projects "shared-"
nx show projects --projects "apps/"
nx show projects --projects "shared-"
Filter by tag
按标签过滤
nx show projects --projects "tag:publishable"
nx show projects -p 'tag:publishable,!tag:internal'
nx show projects --projects "tag:publishable"
nx show projects -p 'tag:publishable,!tag:internal'
Filter by target (projects that have a specific target)
按目标任务过滤(包含指定目标任务的项目)
nx show projects --withTarget build
nx show projects --withTarget build
Find affected projects (changed since base branch)
查找受影响的项目(与基准分支相比有变更的项目)
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
Combine filters
组合过滤器
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="-e2e"
nx show projects -p "tag:scope:client,packages/"
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="-e2e"
nx show projects -p "tag:scope:client,packages/"
Negate patterns (use single quotes to prevent bash history expansion)
取反模式(使用单引号避免bash历史展开)
nx show projects -p '!tag:private'
nx show projects -p '!*-e2e'
nx show projects -p '!tag:private'
nx show projects -p '!*-e2e'
Output as JSON
以JSON格式输出
nx show projects --json
undefinednx show projects --json
undefinedProject Configuration
项目配置
Use to get the full resolved configuration for a project.
nx show project <name> --jsonImportant: Do NOT read directly - it only contains partial configuration. The command returns the full resolved config including inferred targets from plugins.
project.jsonnx show project --jsonYou can read the full project schema at to understand nx project configuration options.
node_modules/nx/schemas/project-schema.jsonbash
undefined使用获取项目的完整解析配置。
nx show project <name> --json重要提示:请勿直接读取文件——它仅包含部分配置。命令返回的是完整的解析配置,包括从插件中推断出的目标任务。
project.jsonnx show project --json你可以查看中的完整项目Schema,以了解Nx项目的配置选项。
node_modules/nx/schemas/project-schema.jsonbash
undefinedGet full project configuration
获取完整的项目配置
nx show project my-app --json
nx show project my-app --json
Extract specific parts from the JSON
从JSON中提取特定部分
nx 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'
nx 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 metadata
查看项目元数据
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
undefinednx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
undefinedTarget Information
目标任务信息
Targets define what tasks can be run on a project.
bash
undefined目标任务定义了可在项目上运行的操作。
bash
undefinedList all targets for a project
列出项目的所有目标任务
nx show project my-app --json | jq '.targets | keys'
nx show project my-app --json | jq '.targets | keys'
Get full target configuration
获取完整的目标任务配置
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets.build'
Check target executor/command
查看目标任务的执行器/命令
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
View target options
查看目标任务选项
nx show project my-app --json | jq '.targets.build.options'
nx 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'
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 target
查找包含特定目标任务的项目
nx show projects --withTarget serve
nx show projects --withTarget e2e
undefinednx show projects --withTarget serve
nx show projects --withTarget e2e
undefinedWorkspace Configuration
工作区配置
Read directly for workspace-level configuration.
You can read the full project schema at to understand nx project configuration options.
nx.jsonnode_modules/nx/schemas/nx-schema.jsonbash
undefined可直接读取文件获取工作区级别的配置。
你可以查看中的完整Schema,以了解Nx项目的配置选项。
nx.jsonnode_modules/nx/schemas/nx-schema.jsonbash
undefinedRead the full nx.json
读取完整的nx.json文件
cat nx.json
cat nx.json
Or use jq for specific sections
或使用jq提取特定部分
cat 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 detailscat nx.json | jq '.targetDefaults'
cat nx.json | jq '.namedInputs'
cat nx.json | jq '.plugins'
cat nx.json | jq '.generators'
nx.json的关键部分:
- `targetDefaults` - 应用于所有同名目标任务的默认配置
- `namedInputs` - 可复用的缓存输入定义
- `plugins` - Nx插件及其配置
- ...更多内容请查看Schema或nx.json文件详情Affected Projects
受影响的项目
Find projects affected by changes in the current branch.
bash
undefined查找当前分支中受变更影响的项目。
bash
undefinedAffected since base branch (auto-detected)
查找与基准分支相比受影响的项目(自动检测基准分支)
nx show projects --affected
nx show projects --affected
Affected with explicit base
指定基准分支查找受影响的项目
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
Affected between two commits
查找两个提交之间受影响的项目
nx show projects --affected --base=abc123 --head=def456
nx show projects --affected --base=abc123 --head=def456
Affected apps only
仅查找受影响的应用项目
nx show projects --affected --type app
nx show projects --affected --type app
Affected excluding e2e projects
查找受影响的项目(排除e2e项目)
nx show projects --affected --exclude="*-e2e"
nx show projects --affected --exclude="*-e2e"
Affected by uncommitted changes
查找受未提交变更影响的项目
nx show projects --affected --uncommitted
nx show projects --affected --uncommitted
Affected by untracked files
查找受未跟踪文件影响的项目
nx show projects --affected --untracked
undefinednx show projects --affected --untracked
undefinedCommon Exploration Patterns
常见探索场景
"What's in this workspace?"
"此工作区中有什么内容?"
bash
nx show projects
nx show projects --type app
nx show projects --type libbash
nx show projects
nx show projects --type app
nx show projects --type lib"How do I build/test/lint project X?"
"如何构建/测试/检查项目X?"
bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'"What depends on library Y?"
"哪些项目依赖库Y?"
bash
undefinedbash
undefinedUse the project graph to find dependents
使用项目图查找依赖该库的项目
nx graph --print | jq '.graph.dependencies | to_entries[] | select(.value[].target == "Y") | .key'
undefinednx graph --print | jq '.graph.dependencies | to_entries[] | select(.value[].target == "Y") | .key'
undefinedProgrammatic Answers
程序化处理结果
When processing nx CLI results, use command-line tools to compute the answer programmatically rather than counting or parsing output manually. Always use flags to get structured output that can be processed with , , or other tools you have installed locally.
--jsonjqgrep处理Nx CLI结果时,请使用命令行工具以程序化方式计算答案,而非手动计数或解析输出。请始终使用标志获取结构化输出,以便使用、或本地安装的其他工具进行处理。
--jsonjqgrepListing Projects
列出项目
bash
nx show projects --jsonExample output:
json
["my-app", "my-app-e2e", "shared-ui", "shared-utils", "api"]Common operations:
bash
undefinedbash
nx show projects --json示例输出:
json
["my-app", "my-app-e2e", "shared-ui", "shared-utils", "api"]常见操作:
bash
undefinedCount projects
统计项目数量
nx show projects --json | jq 'length'
nx show projects --json | jq 'length'
Filter by pattern
按模式过滤项目
nx show projects --json | jq '.[] | select(startswith("shared-"))'
nx show projects --json | jq '.[] | select(startswith("shared-"))'
Get affected projects as array
以数组形式获取受影响的项目
nx show projects --affected --json | jq '.'
undefinednx show projects --affected --json | jq '.'
undefinedProject Details
项目详情
bash
nx show project my-app --jsonExample output:
json
{
"root": "apps/my-app",
"name": "my-app",
"sourceRoot": "apps/my-app/src",
"projectType": "application",
"tags": ["type:app", "scope:client"],
"targets": {
"build": {
"executor": "@nx/vite:build",
"options": { "outputPath": "dist/apps/my-app" }
},
"serve": {
"executor": "@nx/vite:dev-server",
"options": { "buildTarget": "my-app:build" }
},
"test": {
"executor": "@nx/vite:test",
"options": {}
}
},
"implicitDependencies": []
}Common operations:
bash
undefinedbash
nx show project my-app --json示例输出:
json
{
"root": "apps/my-app",
"name": "my-app",
"sourceRoot": "apps/my-app/src",
"projectType": "application",
"tags": ["type:app", "scope:client"],
"targets": {
"build": {
"executor": "@nx/vite:build",
"options": { "outputPath": "dist/apps/my-app" }
},
"serve": {
"executor": "@nx/vite:dev-server",
"options": { "buildTarget": "my-app:build" }
},
"test": {
"executor": "@nx/vite:test",
"options": {}
}
},
"implicitDependencies": []
}常见操作:
bash
undefinedGet target names
获取目标任务名称
nx show project my-app --json | jq '.targets | keys'
nx show project my-app --json | jq '.targets | keys'
Get specific target config
获取特定目标任务的配置
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets.build'
Get tags
获取项目标签
nx show project my-app --json | jq '.tags'
nx show project my-app --json | jq '.tags'
Get project root
获取项目根目录
nx show project my-app --json | jq -r '.root'
undefinednx show project my-app --json | jq -r '.root'
undefinedProject Graph
项目图
bash
nx graph --printExample output:
json
{
"graph": {
"nodes": {
"my-app": {
"name": "my-app",
"type": "app",
"data": { "root": "apps/my-app", "tags": ["type:app"] }
},
"shared-ui": {
"name": "shared-ui",
"type": "lib",
"data": { "root": "libs/shared-ui", "tags": ["type:ui"] }
}
},
"dependencies": {
"my-app": [
{ "source": "my-app", "target": "shared-ui", "type": "static" }
],
"shared-ui": []
}
}
}Common operations:
bash
undefinedbash
nx graph --print示例输出:
json
{
"graph": {
"nodes": {
"my-app": {
"name": "my-app",
"type": "app",
"data": { "root": "apps/my-app", "tags": ["type:app"] }
},
"shared-ui": {
"name": "shared-ui",
"type": "lib",
"data": { "root": "libs/shared-ui", "tags": ["type:ui"] }
}
},
"dependencies": {
"my-app": [
{ "source": "my-app", "target": "shared-ui", "type": "static" }
],
"shared-ui": []
}
}
}常见操作:
bash
undefinedGet all project names from graph
从项目图中获取所有项目名称
nx graph --print | jq '.graph.nodes | keys'
nx graph --print | jq '.graph.nodes | keys'
Find dependencies of a project
查找项目的依赖项
nx graph --print | jq '.graph.dependencies["my-app"]'
nx graph --print | jq '.graph.dependencies["my-app"]'
Find projects that depend on a library
查找依赖某个库的项目
nx graph --print | jq '.graph.dependencies | to_entries[] | select(.value[].target == "shared-ui") | .key'
undefinednx graph --print | jq '.graph.dependencies | to_entries[] | select(.value[].target == "shared-ui") | .key'
undefinedTroubleshooting
故障排查
"Cannot find configuration for task X:target"
"找不到任务X:target的配置"
bash
undefinedbash
undefinedCheck what targets exist on the project
检查项目中存在哪些目标任务
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets | keys'
Check if any projects have that target
检查是否有项目包含该目标任务
nx show projects --withTarget target
undefinednx show projects --withTarget target
undefined"The workspace is out of sync"
"工作区不同步"
bash
nx sync
nx reset # if sync doesn't fix stale cachebash
nx sync
nx reset # 如果sync无法修复缓存过期问题