Skip to content

feat(core): allow nx show project to infer project from cwd#33661

Merged
AgentEnder merged 4 commits intomasterfrom
copilot/add-infer-project-from-cwd
Jan 13, 2026
Merged

feat(core): allow nx show project to infer project from cwd#33661
AgentEnder merged 4 commits intomasterfrom
copilot/add-infer-project-from-cwd

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 29, 2025

Current Behavior

Running nx show project without specifying a project name fails, even when inside a project directory:

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:

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:

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

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
    • 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:

Original prompt

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)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 29, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit bd2258d
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6962a6f5b2815300087ecdf7
😎 Deploy Preview https://deploy-preview-33661--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nx-dev Ready Ready Preview Jan 10, 2026 7:29pm

@AgentEnder
Copy link
Copy Markdown
Member

@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

@AgentEnder
Copy link
Copy Markdown
Member

@copilot we should use the calculateDefaultProjectName util, it consumes the cwd based one and has some extra affordances

1 similar comment
@AgentEnder
Copy link
Copy Markdown
Member

@copilot we should use the calculateDefaultProjectName util, it consumes the cwd based one and has some extra affordances

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 29, 2025

@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: f3dfcd8f-9e56-4a9a-9ad0-45c23c5a062b

Sorry for the inconvenience!

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 29, 2025

@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: 53ee6338-6af2-417c-9a3e-39fccf9d277e

Sorry for the inconvenience!

Copilot AI and others added 2 commits November 29, 2025 18:30
Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature to allow nx show targets to infer project from cwd feat(core): allow nx show project to infer project from cwd Nov 29, 2025
Copilot AI requested a review from AgentEnder November 29, 2025 18:35
Copy link
Copy Markdown
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 10, 2026

@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: 30802631-903f-447b-b993-90fd622b5915

Sorry for the inconvenience!

@AgentEnder
Copy link
Copy Markdown
Member

@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

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 10, 2026

@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: c3184d65-0983-4286-b3f1-5be35e6f0eef

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>
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jan 10, 2026

View your CI Pipeline Execution ↗ for commit bd2258d

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 23m 26s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 9s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 12s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-10 20:57:01 UTC

@AgentEnder AgentEnder marked this pull request as ready for review January 10, 2026 19:26
@AgentEnder AgentEnder requested a review from a team as a code owner January 10, 2026 19:26
@AgentEnder AgentEnder merged commit 6be0a7e into master Jan 13, 2026
21 of 22 checks passed
@AgentEnder AgentEnder deleted the copilot/add-infer-project-from-cwd branch January 13, 2026 15:10
FrozenPandaz pushed a commit that referenced this pull request Jan 14, 2026
## 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:&#43;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&#43;register@1.9.1_@swc&#43;core@1.5.7_@swc&#43;helpers@0.5.11__@swc&#43;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&#43;register@1.9.1_@swc&#43;core@1.5.7_@swc&#43;helpers@0.5.11__@swc&#43;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)
@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: allow nx show targets to infer project from the cwd

3 participants