-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): run-commands cwd
issue
#4728
fix(core): run-commands cwd
issue
#4728
Conversation
setting cwd option for run-commands would result in an error if the command was run from somewhere that is not a workspace root
Nx Cloud ReportCI ran the following commands for commit 6ed2d6a. Click to see the status, the terminal output, and the build insights.
Sent with 💌 from NxCloud. |
On further thought, this doesn't make sense. the |
Thank you for submitting the PR. How about the following rules:
Basically, your current working directly when invoking a command only matters for 1. If you want it not to matter, you can set it to ".", and it will always be the workspace root. What do you think? |
Thank you as well for including me in the PR process :) I'm not too familiar with the codebase so I guess by you not pointing something is clearly wrong means my gamble on this file being the source of the
I agree with the rules you created. Even more the rules 1, 3 are already established by the current implementation of the Not setting
On the one hand it's perfectly understandable, but also the way you put it is a bit confusing to me (as a user) because both an empty cwd "", ".", "./", and not setting the cwd all mean the "commands" are being run from the workspace root anyway? So I agree with what you say, but if I didn't care about the cwd then I just wouldn't set it though. But as I read through the docs it's actually not specified? If you answer that the empty cwd property in I think same goes for "", "." and "./" that it could both mean relative to cwd or relative to workspace root. I am personally of the opinion to have it be relative to workspace root, what's your opinion? |
To be more concrete, these are the two options I see: What I outlined above:
This option sets cwd to root when not specified. No issues with nesting.
I personally prefer Option 2 cause it's more predictable, but it's not how it works right now. Since current behaviour is under-specified, we could treat it as a bug fix. As a side note, we also need to update run-script.impl.ts to set cwd like this:
As a second side note :), one way to test it if e2e don't run for it for some reason is to run: |
@JakubKoralewski let me know if you need any help |
@JakubKoralewski thanks for sending the PR! |
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. |
setting cwd option for run-commands would result in an error
if the command was run from somewhere that is not a workspace root
Current Behavior
Running a
run-commands
executor command from outside the root with thecwd
option set is not working.https://stackoverflow.com/questions/18894433/nodejs-child-process-working-directory
nodejs/node#11520
This is the error:
Expected Behavior
I tried to change the cwd to the workspace root if the joined path of
process.cwd()
and the providedcwd
did not exist.I'm having issues actually testing whether this works, with line endings on WSL and the local release giving me errors. Just not a nice experience for me. I'd appreciate if someone was able to take over this PR and properly test this.
EDIT: Additionally, just remembering to call all the commands from the workspace root is not a valid fix/workaround, because if I want to nest my commands, where both have the
cwd
option set then theoptions.commands
command which calls the other nx command (nx run app:other-command
) will crash, because I think the first command goes to (pseudojs)${root}${firstCommand.cwd}
and the second call attempts to do something like this${root}${firstCommand.cwd}${secondCommand.cwd}
and there's an error.So the current workaround is:
workspace.json
.