-
Notifications
You must be signed in to change notification settings - Fork 329
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
Added support for better handling of transitive dependencies #539
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @popara96,
thanks for the contribution. It was a much requested feature, I also wanted to include the feature but had no time. It generally looks good, I added some comments it would be nice if you fix them.
Also one UnitTest is failing.
.gitignore
Outdated
@@ -1,3 +1,4 @@ | |||
/[Bb]in/ | |||
|
|||
*.log | |||
/src/NuGetForUnity.CreateDll/.idea/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/src/NuGetForUnity.CreateDll/.idea/** | |
**/.idea |
@@ -67,6 +67,8 @@ public static class NugetHelper | |||
/// </summary> | |||
private static readonly List<NugetPackageSource> packageSources = new List<NugetPackageSource>(); | |||
|
|||
public static event Action OnInstalledPackagesChanged; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like events especially static ones. The UI (NugetWindow
) knows when packages are installed so it don't needs to depend on NugetHelper to manage a event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember there being a code earlier that would automatically trigger Restore when packages.config file was changed and we thought we needed this event because of that case but it seems that code is now only triggered the first time project is loaded.
Is that right? Does that mean if I install some packages and push packages.config other developers won't automatically get that package installed when they pull my changes if they already have project open in Unity and they will have to manually run Restore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for packages.config
change detection we would need to implement a AssetPostprocessor / add this feature to the NugetPackageAssetPostprocessor
installedPackages?.Remove(foundPackage.Id); | ||
|
||
if (installedPackages != null && installedPackages.Count > 0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installedPackages?.Remove(foundPackage.Id); | |
if (installedPackages != null && installedPackages.Count > 0) | |
{ | |
if (installedPackages != null && installedPackages.Count > 0) | |
{ | |
installedPackages.Remove(foundPackage.Id); |
|
||
if (installedPackages != null && installedPackages.Count > 0) | ||
{ | ||
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage); | |
// uninstall all non manually installed dependencies that are not a dependency of another installed package | |
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage); |
var actualData = PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id); | ||
if (actualData != null) | ||
{ | ||
package.IsManuallyInstalled = actualData.IsManuallyInstalled; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var actualData = PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id); | |
if (actualData != null) | |
{ | |
package.IsManuallyInstalled = actualData.IsManuallyInstalled; | |
} | |
package.IsManuallyInstalled = PackagesConfigFile.Packages.FirstOrDefault(pkg => pkg.Id == package.Id)?.IsManuallyInstalled ?? false; |
I more like this "one liners"
The unit test that is failing tests the following:
But with new functionality uninstalling bootstrap uninstalls the jquery since it is a transitive dependency and also reinstalls the old version again. The question is what do we want to do when updating packages. I guess the most correct option would be to update all the transitive dependencies that no other package depends on but only to a newer version, so if some dependency was already manually updated to a new version there is no need to downgrade it. Or maybe if you manually update some transitive dependency we should just mark it as manually installed from then on? |
One more thing we considered is that people with old packages.config files when they update to this new version of NugetForUnity all their packages will be marked as transitive dependencies. They can, of course, manually mark some as manually installed afterwards. The only other option that came to our mind is to detect when none of the packages are marked as manually installed and then to mark them all. What do you think? |
I think best way would be to mark all packages as manually installed that are not a dependency of any other installed package. So only the root packages in the dependency tree are considered manually installed. This way we mark the minimum number of packages as manually installed to get a state that lead to the current amount of packages being installed. |
Updating a package always ensures that the minimum version of all its dependencies are also installed so the only issue here is that the test expects jquery to not being uninstalled. I think uninstalling jquery is the scorest behavior, even if the package is updated manually, the user has the possibility to mark it as manually installed to prevent this. So in the UnitTest I would just mark jquery as manually installed so the test can still check the dependency installation. |
I decided to merge this because I think we agreed on all or almost all points, and all of the suggested fixes were implemented. In case you do have some additional comments, I can fix them later. This way it will be easier to work on other issues as most of them would make conflict with these changes. |
Details of new usage are explained in README file.