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

fix(resolve-dependencies): prefer versions found in parent packages only #6742

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented Jun 30, 2023

close #6737

@zkochan
Copy link
Member Author

zkochan commented Jun 30, 2023

@zxbodya

Comment on lines 540 to 542
if (newPreferredVersions[resolvedPackage.name] === preferredVersions[resolvedPackage.name]) {
newPreferredVersions[resolvedPackage.name] = { ...preferredVersions[resolvedPackage.name] }
}
Copy link
Contributor

@zxbodya zxbodya Jun 30, 2023

Choose a reason for hiding this comment

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

alternative version:

    if (!Object.prototype.hasOwnProperty.call(newPreferredVersions, resolvedPackage.name)) {
      newPreferredVersions[resolvedPackage.name] = Object.create(preferredVersions[resolvedPackage.name])
    }

let me check if there is a difference in performance for this

@@ -537,6 +537,9 @@ export async function resolveDependencies (
newPreferredVersions[resolvedPackage.name] = {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of the change below, this can be replaced with

    if (!Object.prototype.hasOwnProperty.call(newPreferredVersions, resolvedPackage.name)) {
      newPreferredVersions[resolvedPackage.name] = preferredVersions[resolvedPackage.name]
        ? Object.create(preferredVersions[resolvedPackage.name])
        : {}
    }

which is noticeably faster - 2m 50s vs 3m 16.8s for me

Copy link
Member Author

Choose a reason for hiding this comment

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

But in npm-resolver we are then running Object.entries and Object.keys on newPreferredVersions[resolvedPackage.name], which will not list the properties if they were added with Object.create

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed that can be a problem, let's stick to safer option creating a copy

@zkochan zkochan merged commit ba93356 into main Jun 30, 2023
13 of 14 checks passed
@zkochan zkochan deleted the fix/6737 branch June 30, 2023 19:12
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.

Fix preferred versions in resolve dependencies
2 participants