nx show projects should return packages' pathnames #23438
Replies: 6 comments 9 replies
-
So I did something similar to create a custom monorepo_root=$(git rev-parse --show-cdup)
project_path=$(nx show project "$1" | jq -r .root)
cd "${monorepo_root}${project_path}" Full script: # For usage information see inlined usage conditional
gtp() {
# Show usage if on errors
showUsage=0
# Check that an argument was passed
# https://unix.stackexchange.com/questions/25945/how-to-check-if-there-are-no-parameters-provided-to-a-command
if [ $# -eq 0 ]; then
echo "Argument [projectName] not passed"
showUsage=1
fi
# Check that needed programs exist
# https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
if ! command -v git &> /dev/null; then
echo "git could not be found, please install it globally"
showUsage=1
fi
if ! command -v nx &> /dev/null; then
echo "nx could not be found, please install it globally"
showUsage=1
fi
if ! command -v jq &> /dev/null; then
echo "jq could not be found, please install it globally"
showUsage=1
fi
# Print usage
if [ $showUsage -eq 1 ]; then
echo "Usage: $0 [projectName]"
echo "Example: $0 @crowdstrike/mega-slat-table"
echo "This function uses NX to CD into a project by the project name"
echo "Required globally installed commands: git, nx, jq"
return 1
fi
# Get monorepo root using git. Ex: ../../../ (Needs to relative in case of worktree)
monorepo_root=$(git rev-parse --show-cdup)
# Get NX project path relative to root. Ex: packages/apps/store
project_path=$(nx show project "$1" | jq -r .root)
# Show error if project_path failed
if [ $? -ne 0 ]; then
echo "NX failed to show the project, make sure you are in the monorepo and the project name is correct"
# Run gtp again with no arguments to show usage
gtp
return 1
fi
# CD into the root+path combo
cd "${monorepo_root}${project_path}"
} |
Beta Was this translation helpful? Give feedback.
-
I was able to make it work via |
Beta Was this translation helpful? Give feedback.
-
For our tooling we relied on the project path name in the workspace.json which is now removed. Currently I am looking for a way to ditch the old workspace.json and get the project path. |
Beta Was this translation helpful? Give feedback.
-
Hi! It needs a little bit more design, though. There is already a You could read the list of affected projects in I'd love some more concrete thoughts on how you would design this updated API and what use cases you have that aren't solvable with another solution. Let's continue the conversation in a discussion :) |
Beta Was this translation helpful? Give feedback.
-
I was running into the exact same need. Building github workflows with reusable components that I want to run as a matrix for affected projects can't be an unlikely usecase. And since some workflows expect to be run in the root of a project (such as SAST tooling) it would be incredibly useful to have the possibility to output the paths via Has this discussion been converted into a feature request? |
Beta Was this translation helpful? Give feedback.
-
Have you looked into this>
I'd love some more specific ideas on how you would design the commands :) It seems pretty easy to write your own script for atm, no? |
Beta Was this translation helpful? Give feedback.
-
I was trying to extract affected packages by changes I had made.
Unfortunately,
nx graph --affected
returns deprecatedaffectedPackages
attribute I should not rely on.So, I have to run both commands in a sequence:
nx show projects --affected
nx graph
Unfortunately,
nx show projects
returns only a simple list of packages names, and it's not enough to determine packages location.If
nx show projects --affected
returns extended list of packages, it would be totally enoughMotivation
I was trying to ditribute tests execution between runners, so I had to determine affected packages and gradually distribute tests betweeen runners.
Suggested Implementation
Return a list of objects. Each object should have the following:
Beta Was this translation helpful? Give feedback.
All reactions