Skip to content

Commit e47d968

Browse files
committed
Improve version notifier output
1 parent aa7fc3b commit e47d968

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

docs/redirects.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ const customRedirects = [
309309
destination: "/hardhat-runner/plugins/nomicfoundation-hardhat-ethers",
310310
permanent: false,
311311
},
312+
{
313+
source: "/release/:version",
314+
destination: "https://github.com/NomicFoundation/hardhat/releases/tag/hardhat%40:version",
315+
permanent: false,
316+
},
312317
...loadErrorRedirects(),
313318
];
314319

packages/hardhat-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"adm-zip": "^0.4.16",
116116
"aggregate-error": "^3.0.0",
117117
"ansi-escapes": "^4.3.0",
118+
"boxen": "^5.1.2",
118119
"chalk": "^2.4.2",
119120
"chokidar": "^3.4.0",
120121
"ci-info": "^2.0.0",

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

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { request as RequestT } from "undici";
22

3+
import boxen from "boxen";
4+
import chalk from "chalk";
35
import { join } from "node:path";
46
import { mkdir, readFile, writeFile } from "node:fs/promises";
57
import semver from "semver";
@@ -14,28 +16,34 @@ const V3_RELEASE_TAG = "[email protected]";
1416
const V3_RELEASE_VERSION_NOTIFIER_ASSET_NAME = "version-notifier-message.txt";
1517
const V3_RELEASE_MAX_TIMES_SHOWN = 5;
1618

19+
const boxenOptions = {
20+
padding: 1,
21+
borderStyle: "round",
22+
borderColor: "yellow",
23+
} as const;
24+
1725
interface VersionNotifierCache {
1826
lastCheck: string | 0;
1927
v3TimesShown: number;
2028
v3Release?: Release;
2129
v3ReleaseMessage?: string;
2230
}
2331

32+
/* eslint-disable @typescript-eslint/naming-convention */
2433
interface Release {
2534
name: string;
26-
// eslint-disable-next-line @typescript-eslint/naming-convention
2735
tag_name: string;
2836
draft: boolean;
2937
prerelease: boolean;
30-
// eslint-disable-next-line @typescript-eslint/naming-convention
3138
published_at: string;
39+
html_url: string;
3240
assets: Array<{
3341
name: string;
34-
// eslint-disable-next-line @typescript-eslint/naming-convention
3542
browser_download_url: string;
3643
}>;
3744
body: string; // release notes
3845
}
46+
/* eslint-enable @typescript-eslint/naming-convention */
3947

4048
export async function showNewVersionNotification() {
4149
const cache = await readCache();
@@ -78,7 +86,16 @@ export async function showNewVersionNotification() {
7886

7987
if (releaseVersion !== null && semver.gt(releaseVersion, hardhatVersion)) {
8088
console.log(
81-
`There's a new version of ${GITHUB_REPO} available: ${releaseVersion}! Run "npm i ${GITHUB_REPO}@${releaseVersion}" to update.\n`
89+
boxen(
90+
`New Hardhat release available! ${chalk.red(
91+
hardhatVersion
92+
)} -> ${chalk.green(releaseVersion)}.
93+
94+
Changelog: https://hardhat.org/release/${releaseVersion}
95+
96+
Run "npm install hardhat@latest" to update.`,
97+
boxenOptions
98+
)
8299
);
83100
}
84101
}
@@ -91,7 +108,7 @@ export async function showNewVersionNotification() {
91108
cache.v3ReleaseMessage =
92109
cache.v3ReleaseMessage ?? (await getV3ReleaseMessage(v3Release));
93110
if (cache.v3ReleaseMessage !== undefined) {
94-
console.log(cache.v3ReleaseMessage);
111+
console.log(boxen(cache.v3ReleaseMessage, boxenOptions));
95112
cache.v3TimesShown++;
96113
}
97114
}

pnpm-lock.yaml

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)