mcpField
N
nx-workspace

nx-workspace

github.com/nrwl開発1.4k35 回インストール今日更新
リポジトリ

nx-workspace について

nx-workspaceは、Nxワークスペースを読み取り専用で調査するスキルです。プロジェクト、解決済み設定、ターゲット、依存関係をNx CLIで確認し、JSON出力をコマンドラインで処理できます。

主な機能

  1. 01ワークスペースのプロジェクト一覧と絞り込み
  2. 02解決済み設定とターゲットの確認
  3. 03ワークスペース設定の確認
  4. 04プロジェクト依存グラフの照会
  5. 05CLI結果のJSON処理

活用シーン

  1. 01ワークスペース内のアプリとライブラリの把握
  2. 02プロジェクトのビルド・テストターゲットの確認
  3. 03ライブラリに依存するプロジェクトの特定

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/nrwl/nx-console --skill nx-workspace

インストール後、Claude Code で/nx-workspaceを入力して読み込まれたか確認します。

同梱ファイルreferences/AFFECTED.md

詳細

Nx ワークスペースの調査

このスキルでは、Nx ワークスペースを読み取り専用で調査できます。ワークスペースの構造、プロジェクト設定、利用可能なターゲット、依存関係を把握するために使用します。

nx がグローバルにインストールされていない場合、コマンドの先頭に npx/pnpx/yarn を付ける必要があることがあります。ロックファイルを確認して、使用中のパッケージマネージャーを特定してください。

プロジェクトの一覧表示

nx show projects を使用して、ワークスペース内のプロジェクトを一覧表示します。

プロジェクトのフィルター構文(-p/--projects)は、nx run-many、nx release、nx show projects など、多くの Nx コマンドで使用できます。フィルターでは、明示的な名前、glob パターン、タグ参照(例:tag:name)、ディレクトリ、否定(例:!project-name)を指定できます。

# List all projects
nx show projects

# Filter by pattern (glob)
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'

# Filter by target (projects that have a specific target)
nx show projects --withTarget build

# Combine filters
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="*-e2e"
nx show projects -p "tag:scope:client,packages/*"

# Negate patterns
nx show projects -p '!tag:private'
nx show projects -p '!*-e2e'

# Output as JSON
nx show projects --json

プロジェクト設定

nx show project <name> --json を使用すると、プロジェクトの解決済み設定全体を取得できます。

重要:project.json を直接読まないでください。そこに含まれるのは設定の一部だけです。nx show project --json コマンドは、プラグインから推測されるターゲットも含め、解決済みの設定全体を返します。

Nx のプロジェクト設定オプションを把握するには、node_modules/nx/schemas/project-schema.json でプロジェクトスキーマ全体を確認できます。

# Get full project configuration
nx show project my-app --json

# Extract specific parts from the 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'


# Check project metadata
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'

ターゲット情報

ターゲットは、プロジェクトで実行できるタスクを定義します。

# List all targets for a project
nx show project my-app --json | jq '.targets | keys'

# Get full target configuration
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'

# View target 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'

# Find projects with a specific target
nx show projects --withTarget serve
nx show projects --withTarget e2e

ワークスペース設定

ワークスペースレベルの設定は、nx.json を直接読んで確認してください。 Nx のプロジェクト設定オプションを把握するには、node_modules/nx/schemas/nx-schema.json でプロジェクトスキーマ全体を確認できます。

# Read the full nx.json
cat nx.json

# Or use jq for specific sections
cat 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 プラグインとその設定
  • ...ほかにも多数あります。詳細はスキーマまたは nx.json を確認してください

影響を受けるプロジェクト

ユーザーが影響を受けるプロジェクトについて質問している場合は、詳しいコマンドと例が記載された影響を受けるプロジェクトのリファレンスを確認してください。

よくある調査パターン

「このワークスペースには何がありますか?」
nx show projects
nx show projects --type app
nx show projects --type lib
「プロジェクト X をビルド/テスト/リントするにはどうすればよいですか?」
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'
「ライブラリ Y に依存しているものは何ですか?」
# Use the project graph to find dependents
nx graph --print | jq '.graph.dependencies | to_entries[] | select(.value[].target == "Y") | .key'

プログラムによる回答

nx CLI の結果を処理する際は、出力を手動で数えたり解析したりするのではなく、コマンドラインツールを使ってプログラムで回答を算出してください。構造化された出力を取得するため、必ず --json フラグを使用し、ローカルにインストールされている jq、grep、その他のツールで処理してください。

プロジェクトの一覧表示
nx show projects --json

出力例:

["my-app", "my-app-e2e", "shared-ui", "shared-utils", "api"]

よく使う操作:

# Count projects
nx show projects --json | jq 'length'

# Filter by pattern
nx show projects --json | jq '.[] | select(startswith("shared-"))'

# Get affected projects as array
nx show projects --affected --json | jq '.'
プロジェクトの詳細
nx show project my-app --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": []
}

よく使う操作:

# Get target names
nx show project my-app --json | jq '.targets | keys'

# Get specific target config
nx show project my-app --json | jq '.targets.build'

# Get tags
nx show project my-app --json | jq '.tags'

# Get project root
nx show project my-app --json | jq -r '.root'
プロジェクトグラフ
nx graph --print

出力例:

{
  "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": []
    }
  }
}

よく使う操作:

# Get all project names from graph
nx graph --print | jq '.graph.nodes | keys'

# Find dependencies of a project
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'

トラブルシューティング

「タスク X:target の設定が見つかりません」
# Check what targets exist on the project
nx show project X --json | jq '.targets | keys'

# Check if any projects have that target
nx show projects --withTarget target
「ワークスペースの同期が取れていません」
nx sync
nx reset  # if sync doesn't fix stale cache

コメント