We use semver in multiple parts of the build system, including the config validation/resolution.
This package is notoriously slow to load, so we should only use it when needed.
The only places where we need the full power of semver are:
packages/hardhat/src/internal/core/plugins/detect-plugin-npm-dependency-problems.ts
packages/hardhat/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts
- And maybe the
packages/hardhat/src/internal/cli/init — This is less important to answer though, as that part of the codebase is not present in any hot-path.
In every other case, we only do basic comparisons, and we can get away with a much simpler module built by ouserlves as part of hardhat-utils.
Something like this should be enough:
export type SemverVersion = [major: number, minor: number, patch: number];
export function parseVersion(version: string): SemverVersion | undefined;
// A comparator following the the Array#sort's compareFn interface: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description
export function compare(a: SemverVersion, b: SemverVersion): number;
Note that we don't need to support prerelease tags.
We can also add utility methods because the compartor interface can be confusing:
export function equals(a: SemverVersion, b: SemverVersion ): boolean;
export function lowerThan(compared: SemverVersion, comparator: SemverVersion): boolean;
export function greaterThan(compared: SemverVersion, comparator: SemverVersion): boolean;
Once that's implemented, we should use replace all our usages of semver with it, except the onces I mentioned above.
We use
semverin multiple parts of the build system, including the config validation/resolution.This package is notoriously slow to load, so we should only use it when needed.
The only places where we need the full power of
semverare:packages/hardhat/src/internal/core/plugins/detect-plugin-npm-dependency-problems.tspackages/hardhat/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.tspackages/hardhat/src/internal/cli/init— This is less important to answer though, as that part of the codebase is not present in any hot-path.In every other case, we only do basic comparisons, and we can get away with a much simpler module built by ouserlves as part of
hardhat-utils.Something like this should be enough:
Note that we don't need to support prerelease tags.
We can also add utility methods because the compartor interface can be confusing:
Once that's implemented, we should use replace all our usages of
semverwith it, except the onces I mentioned above.