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

feat(core): move generator now includes namespace #770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tungsten78
Copy link
Contributor

@Tungsten78 Tungsten78 commented Oct 6, 2023

The app and lib generators derive the namespace from the project name.
For consistency, it makes sense to align the namespace in the move generator.

Cases:
1 - Update .NET project (.csproj) file name
2 - Update <RootNamespace> (if exists)
3 - Update namespace in all code files within moved project
4 - Update project reference path+filename in all referenced projects
5 - Update namespace in all referencing project code files

@sonarcloud
Copy link

sonarcloud bot commented Oct 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@nx-cloud
Copy link

nx-cloud bot commented Oct 6, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f6502f0. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


⌛ The following target is in progress

✅ Successfully ran 6 targets

Sent with 💌 from NxCloud.

const destination = joinPathFragments(uniq('app'));
console.log(tree.read(csProjPath)?.toString());
const destination = uniq('app');
console.log(tree.read(otherCsProjPath)?.toString());
Copy link
Member

Choose a reason for hiding this comment

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

Rm

</Project>
`,
);
console.log(tree.read(projectFilePath)?.toString());
Copy link
Member

Choose a reason for hiding this comment

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

Rm

Comment on lines +90 to +93
console.log({
originalNamespace: normalizedOptions.currentNamespace,
newNamespace: normalizedOptions.destinationNamespace,
});
Copy link
Member

Choose a reason for hiding this comment

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

Rm

const newPath = normalizePath(
relative(directory, options.destinationRoot),
relative(projectDirectory, options.destinationRoot),
);

console.log({ pathToUpdate, newPath });
Copy link
Member

Choose a reason for hiding this comment

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

I know this one's already here, but let's rm it too

path,
contents
.toString()
.replaceAll(options.currentNamespace, options.destinationNamespace),
Copy link
Member

Choose a reason for hiding this comment

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

It may be worth having more advanced pattern matching here. As is, if your renaming a namespace called Shop and have a variable named something like ShopCreator it would update that variable declaration and may not be desired.

For now, this is likely fine, so don't worry about trying to improve it on this PR, just something to keep in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I had my npm scoped deeply nested namespaces in my brain. I agree better pattern matching would be safest.

Comment on lines +59 to +62
currentNamespace: getNamespaceFromSchema(
tree,
currentRoot.replace(trimPattern, ''),
),
Copy link
Member

Choose a reason for hiding this comment

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

This part doesn't work if the namespace has been updated manually or if the project was imported rather than generated. Is there maybe a property inside the csproj we could read for this? There very well may not be, in which case we shouldn't replace things at all.

I'm really kind of wondering about building a basic AST or tokenizer for .NET, that would make things like this easier to query. Just a thought though, wouldn't be super fun...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Renaming the namespaces probably only makes sense in the case the project is using the defaults of the create generators.

  • We could conditionally rename based on whether the project name is consistent with what we expect it to be if not overridden or imported?

AFAIK, filename vs namespaces is only a convention.

Also, the csproj has <RootNamespace> which is optional and only serves as a hint to IDEs when creating new class files. * I included it in the rename because it shows up in the vbproj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants