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

Allow semver ranges #2011

Closed
wants to merge 8 commits into from
Closed

Allow semver ranges #2011

wants to merge 8 commits into from

Conversation

dappnodedev
Copy link
Contributor

@dappnodedev dappnodedev commented Aug 12, 2024

This PR refactors the DappGetFetcher class to improve the handling of dependencies and their version ranges. The main improvements include:

  1. Separation of Concerns:

    • The processDependencies method was introduced to handle two main responsibilities:
      • Filtering out dependencies that are already satisfied by installed packages.
      • Parsing and converting semver ranges to appropriate APM-compatible versions.
  2. Improved Optional Dependencies Handling:

    • A new mergeOptionalDependencies method was introduced to inject optional dependencies into the main dependencies object only if the corresponding packages are installed.
  3. Enhanced Semver Range Handling:

    • The parseSemverRangeToApmVersion method was created to convert semver ranges like ^x.x.x, ~x.x.x, >x.x.x, and >=x.x.x to appropriate APM-compatible versions or the latest version (*) if applicable.
    • Added checks to ensure that only simple version ranges are supported, throwing errors for complex or combined ranges.
  4. Code Readability and Maintainability:

    • The code was refactored to be more modular and easier to understand, with clear method responsibilities and added inline documentation.
    • Methods were renamed and reorganized for clarity, following best practices.

@dappnodedev dappnodedev requested a review from a team as a code owner August 12, 2024 12:27
Copy link

github-actions bot commented Aug 12, 2024

Copy link

github-actions bot commented Aug 12, 2024

Dappnode bot has built and pinned the built packages to an IPFS node, for commit: e9e20dc

This is a development version and should only be installed for testing purposes.

  1. Package dappmanager.dnp.dappnode.eth

Install link

Hash: /ipfs/QmYgH3yKFQuLZ1Ks273kfNjL5V2aArt8AooCNvnUNUc5Ft

(by dappnodebot/build-action)

* @param semverRange The semver range to be parsed.
* @returns The parsed version as a string.
*/
private parseSemverRangeToApmVersion(semverRange: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

For context:

"pattern": "^((([0-9]+).([0-9]+).([0-9]+)))$",
    function isValidBump(uint16[3] _oldVersion, uint16[3] _newVersion) public pure returns (bool) {
        bool hasBumped;
        uint i = 0;
        while (i < 3) {
            if (hasBumped) {
                if (_newVersion[i] != 0) {
                    return false;
                }
            } else if (_newVersion[i] != _oldVersion[i]) {
                if (_oldVersion[i] > _newVersion[i] || _newVersion[i] - _oldVersion[i] != 1) {
                    return false;
                }
                hasBumped = true;
            }
            i++;
        }
        return hasBumped;
    }

Which means that we will kind of follow JS ecosystem where packages will have always a semver version and the package manager can parse the dependency target defined in the manifest (package.json)

Copy link
Contributor

Choose a reason for hiding this comment

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

we should document this in the dev documentation letting devs know that they are allowed to do so

}

// Use x.x.x if version is ^x.x.x or ~x.x.x
if (/^[\^~]\d+\.\d+\.\d+$/.test(semverRange)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this correct? shouldnt determine the following?

^1.2.3 - Matches the latest patch version for the 1.2.x range.
~1.2.3 - Matches the latest minor version for the 1.x.x range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been fixed in 2b8c470

* @param semverRange The semver range to be parsed.
* @returns The parsed version as a string.
*/
private parseSemverRangeToApmVersion(semverRange: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename the function to something like parseSemverRangeToSemverStrict since semver is something not specific to APM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function has been removed, as it is not needed anymore

@github-actions github-actions bot temporarily deployed to commit August 13, 2024 09:50 Inactive
* @param dependencies The main dependencies object to be processed.
* @param installedPackages The list of currently installed packages.
*/
private filterSatisfiedDependencies(
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me weird deleting the dependency if its installed already. It must be checked still if it satisfies the version range defined

Copy link
Contributor

Choose a reason for hiding this comment

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

I would take a different approach than deleting the dependency, it is still a dependency so whenever its going to be installed that code should bypass if already installed and version satisfies

packages/installer/src/dappGet/fetch/DappGetFetcher.ts Outdated Show resolved Hide resolved
}
}

private async defineExactVersions(
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a description to the function also providing an example of how looks the object before and after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Done

@github-actions github-actions bot temporarily deployed to commit August 13, 2024 12:57 Inactive
@github-actions github-actions bot temporarily deployed to commit August 13, 2024 14:07 Inactive
@github-actions github-actions bot temporarily deployed to commit August 14, 2024 12:21 Inactive
@dappnodedev
Copy link
Contributor Author

This should not be necessary as it is already supported in another way

@dappnodedev dappnodedev closed this Sep 4, 2024
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.

2 participants