feat(core): allow nx show project to infer project from cwd#33661
feat(core): allow nx show project to infer project from cwd#33661AgentEnder merged 4 commits intomasterfrom
nx show project to infer project from cwd#33661Conversation
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@copilot we already do this when generating something inside a project dir, or when running something with run-one inside a project dir - check those to see the pattern |
|
@copilot we should use the calculateDefaultProjectName util, it consumes the cwd based one and has some extra affordances |
1 similar comment
|
@copilot we should use the calculateDefaultProjectName util, it consumes the cwd based one and has some extra affordances |
|
@AgentEnder Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
|
@AgentEnder Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
nx show project to infer project from cwd
AgentEnder
left a comment
There was a problem hiding this comment.
@copilot the findmatchingprojects logic is correct here, but we should be using the existing calculateDefaultProjectName utility as we do in run.ts instead of bespoke logic for cwd support
|
@AgentEnder Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
|
@copilot the findmatchingprojects logic is correct here, but we should be using the existing calculateDefaultProjectName utility as we do in run.ts instead of bespoke logic for cwd support |
|
@AgentEnder Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
…project Refactored the cwd-based project inference in `nx show project` to use the existing `calculateDefaultProjectName` utility instead of bespoke logic. This aligns with the pattern used in run-one.ts and provides additional affordances like NX_DEFAULT_PROJECT env var support and nxJson.defaultProject fallback. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit bd2258d
☁️ Nx Cloud last updated this comment at |
## Current Behavior Running `nx show project` without specifying a project name fails, even when inside a project directory: ```bash cd packages/my-lib nx show project # Error: requires projectName argument ``` ## Expected Behavior When run from within a project directory, `nx show project` infers the project from the current working directory: ```bash cd packages/my-lib nx show project # Shows my-lib configuration and targets nx show project --json # Outputs JSON for my-lib ``` Explicit project name still works: ```bash nx show project other-project ``` If cwd is not within any project, shows a helpful error with usage instructions. ### Changes - `command-object.ts`: Make `projectName` positional arg optional (`[projectName]`) - `project.ts`: Infer project from cwd using `findProjectForPath` when no project specified - `project.spec.ts`: Add unit tests for cwd inference, nested directories, root projects, and error cases ## Related Issue(s) Fixes #31055 > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `repo.gradle.org` > - Triggering command: `/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en` (dns block) > - `staging.nx.app` > - Triggering command: `/usr/local/bin/node node ./bin/post-install` (dns block) > - Triggering command: `/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/nx/nx/node_modules/.pnpm/nx@22.2.0-beta.1_@swc-node+register@1.9.1_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+typ_e0638a3d25d549ce0cdd3a7d8bad3b61/node_modules/nx/src/project-graph/plugins/isolation/plugin-worker /tmp/plugin3517-16-424.353971.sock @nx/enterprise-cloud` (dns block) > - Triggering command: `/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/nx/nx/node_modules/.pnpm/nx@22.2.0-beta.1_@swc-node+register@1.9.1_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+typ_e0638a3d25d549ce0cdd3a7d8bad3b61/node_modules/nx/src/project-graph/plugins/isolation/plugin-worker /tmp/plugin4274-16-431.526748.sock @nx/enterprise-cloud` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/nrwl/nx/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Feature: allow `nx show targets` to infer project from the cwd</issue_title> > <issue_description>### Description > When I'm already working inside a project's folder (for example `github/abapify/packages/adk` that has its own `project.json`), I would love to ask Nx to list the targets that belong to that project without having to remember or type the project name. Ideally `npx nx show targets` could detect the `project.json` in the current working directory and operate on that project automatically. > > ### Current behavior > Running the command from inside a project directory fails because the CLI insists on a `--project` argument: > > ``` > $ cd github/abapify/packages/adk > $ npx nx show targets > Please provide a project name via --project=<name> > ``` > > ### Expected behavior > If the current directory (or one of its ancestors) contains a `project.json`, Nx should infer the project from that file and list the targets without extra flags. This would make it much easier to explore available targets while staying focused on a single project, especially in large workspaces with many similarly named packages. > > ### Environment > - Nx: 21.6.3 > - Node: 24.10.0 > - Package manager: bun 1.3.1 > - OS: WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2) > </issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes #33503 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/nrwl/nx/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com> Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> (cherry picked from commit 6be0a7e)
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
Running
nx show projectwithout specifying a project name fails, even when inside a project directory:Expected Behavior
When run from within a project directory,
nx show projectinfers the project from the current working directory:Explicit project name still works:
If cwd is not within any project, shows a helpful error with usage instructions.
Changes
command-object.ts: MakeprojectNamepositional arg optional ([projectName])project.ts: Infer project from cwd usingfindProjectForPathwhen no project specifiedproject.spec.ts: Add unit tests for cwd inference, nested directories, root projects, and error casesRelated Issue(s)
Fixes #31055
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.gradle.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en(dns block)staging.nx.app/usr/local/bin/node node ./bin/post-install(dns block)/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/nx/nx/node_modules/.pnpm/nx@22.2.0-beta.1_@swc-node+register@1.9.1_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+typ_e0638a3d25d549ce0cdd3a7d8bad3b61/node_modules/nx/src/project-graph/plugins/isolation/plugin-worker /tmp/plugin3517-16-424.353971.sock @nx/enterprise-cloud(dns block)/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/nx/nx/node_modules/.pnpm/nx@22.2.0-beta.1_@swc-node+register@1.9.1_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+typ_e0638a3d25d549ce0cdd3a7d8bad3b61/node_modules/nx/src/project-graph/plugins/isolation/plugin-worker /tmp/plugin4274-16-431.526748.sock @nx/enterprise-cloud(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
nx show targetsto infer project from the cwd #33503✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.