Skip to content

Commit aa7fc3b

Browse files
committed
Compare latest version with current version
1 parent 125cbad commit aa7fc3b

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

packages/hardhat-core/src/internal/cli/version-notifier.ts

+9-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { request as RequestT } from "undici";
22

3-
import { join, resolve } from "node:path";
3+
import { join } from "node:path";
44
import { mkdir, readFile, writeFile } from "node:fs/promises";
55
import semver from "semver";
66

77
import { getCacheDir } from "../util/global-dir";
8+
import { getHardhatVersion } from "../util/packageInfo";
89

910
const GITHUB_API_URL = "https://api.github.com";
10-
const GITHUB_OWNER = "schaable"; // CHANGEME: "NomicFoundation";
11-
const GITHUB_REPO = "fake-hh"; // CHANGEME: "hardhat";
12-
const V3_RELEASE_TAG = "[email protected]"; // CHANGEME: "[email protected]";
11+
const GITHUB_OWNER = "NomicFoundation";
12+
const GITHUB_REPO = "hardhat";
13+
const V3_RELEASE_TAG = "[email protected]";
1314
const V3_RELEASE_VERSION_NOTIFIER_ASSET_NAME = "version-notifier-message.txt";
1415
const V3_RELEASE_MAX_TIMES_SHOWN = 5;
1516

@@ -47,11 +48,7 @@ export async function showNewVersionNotification() {
4748
return;
4849
}
4950

50-
const projectVersion = await getProjectHardhatVersion();
51-
52-
if (projectVersion === null) {
53-
return;
54-
}
51+
const hardhatVersion = getHardhatVersion();
5552

5653
const releases = await getReleases();
5754

@@ -65,7 +62,7 @@ export async function showNewVersionNotification() {
6562
return (
6663
packageName === GITHUB_REPO &&
6764
semver.valid(packageVersion) !== null &&
68-
semver.major(packageVersion) === 0 // CHANGEME: 2
65+
semver.major(packageVersion) === 2
6966
);
7067
});
7168

@@ -79,7 +76,7 @@ export async function showNewVersionNotification() {
7976
if (latestV2Release !== undefined) {
8077
const releaseVersion = semver.valid(latestV2Release.tag_name.split("@")[1]);
8178

82-
if (releaseVersion !== null && semver.gt(releaseVersion, projectVersion)) {
79+
if (releaseVersion !== null && semver.gt(releaseVersion, hardhatVersion)) {
8380
console.log(
8481
`There's a new version of ${GITHUB_REPO} available: ${releaseVersion}! Run "npm i ${GITHUB_REPO}@${releaseVersion}" to update.\n`
8582
);
@@ -89,7 +86,7 @@ export async function showNewVersionNotification() {
8986
if (v3Release !== undefined) {
9087
const releaseVersion = semver.valid(v3Release.tag_name.split("@")[1]);
9188

92-
if (releaseVersion !== null && semver.gt(releaseVersion, projectVersion)) {
89+
if (releaseVersion !== null) {
9390
if (cache.v3TimesShown < V3_RELEASE_MAX_TIMES_SHOWN) {
9491
cache.v3ReleaseMessage =
9592
cache.v3ReleaseMessage ?? (await getV3ReleaseMessage(v3Release));
@@ -143,26 +140,6 @@ async function writeCache(cache: VersionNotifierCache) {
143140
}
144141
}
145142

146-
async function getProjectHardhatVersion(): Promise<string | null> {
147-
const packageJsonPath = resolve(__dirname, "../../../..", "package.json");
148-
let packageJson: {
149-
dependencies?: Record<string, string>;
150-
devDependencies?: Record<string, string>;
151-
} = {};
152-
try {
153-
packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
154-
} catch (error) {
155-
return null;
156-
}
157-
158-
const versionRange =
159-
packageJson?.dependencies?.["fake-hh"] ??
160-
packageJson?.devDependencies?.["fake-hh"];
161-
// CHANGEME: packageJson?.dependencies?.hardhat ?? packageJson?.devDependencies?.hardhat;
162-
163-
return semver.valid(semver.coerce(versionRange));
164-
}
165-
166143
async function getReleases(): Promise<Release[]> {
167144
const { request } = (await import("undici")) as { request: typeof RequestT };
168145
let releases: Release[] = [];

0 commit comments

Comments
 (0)