Skip to content
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

[Feature] add a new move generator to @nx-dotnet/core #406

Closed
AgentEnder opened this issue Apr 4, 2022 · 15 comments · Fixed by #588
Closed

[Feature] add a new move generator to @nx-dotnet/core #406

AgentEnder opened this issue Apr 4, 2022 · 15 comments · Fixed by #588
Labels

Comments

@AgentEnder
Copy link
Member

Is your feature request related to a problem? Please describe.
.csproj files contain relative paths to any other projects in the repo that they reference

Describe the solution you'd like
These paths are updated during the move generator such that you can move a project from the command line without breaking other projects.

Additional context
dotnet doesn't support any kind of path aliases, so these have to be relative.

@bcallaghan-et
Copy link
Collaborator

Thinking out loud here: the generator would need to do the following.

  1. Move the project's files to the new directory
  2. Update the .csproj of every project that references the moved project.
  3. Update the root/sourceRoot properties project.json/workspace.json of the moved project
  4. Update the path within workspace.json (if using separate project.json files)
  5. Update the .csproj name to match the new directory
  6. Update the namespace of every .cs file in the moved project
  7. Update the usings of every .cs file that references the now-renamed namespaces

Steps 1-4 seem simple enough. Steps 5-7 are much harder, and would normally be accomplished through refactoring tools like Visual Studio or ReSharper.

@AgentEnder
Copy link
Member Author

A minimalist version of the generator could only do steps 1-4 and be "done", later we could enhance it with the refactoring / ast work.

For steps 1-4, you'd just call through to the regular Nx move and then after calling it youd need to handle the csproj name changes

@bcallaghan-et
Copy link
Collaborator

Should this generator also support changing an application to a library (or vice versa)? I've got a few console applications that I want to change to simple libraries.

@AgentEnder
Copy link
Member Author

I don't think so, since the regular Nx move generator doesn't. It could be added perhaps, but I'm not sure how I'd design it in terms of schema

@bcallaghan-et
Copy link
Collaborator

Two other things this generator might need to do

  1. Update the solution folder path (when used with a Visual Studio solution)
  2. Update the Nx project name (which currently contains the relative path of the project). For example, moving a project from libs/billing/api to libs/shipping/shared would rename the project from billing-api to shipping-shared.

@AgentEnder
Copy link
Member Author

2 should be done when invoking nrwl/workspace:move, so I wouldn't worry about it. 1 is definitely something we'd need to handle.

@bcallaghan-et
Copy link
Collaborator

So you plan on using @nrwl/workspace:move do some of the heavy lifting? I wasn't sure if we could re-use the logic from that generator.

@AgentEnder
Copy link
Member Author

I'd let it do as much as possible. The only parts we should be doing is updating file contents after the relocation

@bcallaghan-et
Copy link
Collaborator

The existing @nrwl/workspace:move generator crashes when used with an nx-dotnet project.

> Executing task: npx nx generate @nrwl/workspace:move new --projectName=old-common --no-updateImportPath --no-interactive --dry-run <


>  NX  Generating @nrwl/workspace:move


 >  NX   unable to find "@etogy-test/old/common" in tsconfig.base.json compilerOptions.paths

   Pass --verbose to see the stacktrace.

The terminal process "C:\Program Files\Git\bin\bash.exe '-c', 'npx nx generate @nrwl/workspace:move new --projectName=old-common --no-updateImportPath --no-interactive --dry-run'" terminated with exit code: 1.

I tried with and without the --no-updateImportPath flag. If I add the following to tsconfig.base.json, then the generator completes as normal.

"paths": {
  "@etogy-test/old/common": []
}

@AgentEnder
Copy link
Member Author

That's interesting 🤔, on the Nx side we should update that then... I'll add a backlog item, should be a quick change to make it work without tsconfig path

@AgentEnder
Copy link
Member Author

Feel free to deep import the utils that the workspace move generator uses in the meantime

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@AgentEnder
Copy link
Member Author

For reference I settled on a simple generator for now that handles some, but not all of this.

Currently the generator:

  • moves files
  • renames the nx project
  • updates any strings in the project configuration that contained the old path (e.g. sourceRoot)
  • updates any project or solution files that contained a reference to it

@AgentEnder
Copy link
Member Author

Notably, the current implementation does not rename namespaces

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants