Skip to content

Commit b9df707

Browse files
Smaller fixes based on the PR's comments
1 parent 39a1511 commit b9df707

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

v-next/hardhat/src/internal/cli/telemetry/analytics/analytics.ts

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ async function sendAnalytics(
7979
async function createSubprocessToSendAnalytics(
8080
payload: TelemetryConsentPayload | Payload,
8181
): Promise<void> {
82+
// The HARDHAT_TEST_SUBPROCESS_RESULT_PATH env variable is used in the tests to instruct the subprocess to write the payload to a file
83+
// instead of sending it.
84+
// During testing, the subprocess file is a ts file, whereas in production, it is a js file (compiled code).
85+
// The following lines adjust the file extension based on whether the environment is for testing or production.
8286
const fileExt =
8387
process.env.HARDHAT_TEST_SUBPROCESS_RESULT_PATH !== undefined ? "ts" : "js";
8488
const subprocessFile = `${import.meta.dirname}/subprocess.${fileExt}`;

v-next/hardhat/src/internal/cli/telemetry/analytics/subprocess.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@ import { writeJsonFile } from "@ignored/hardhat-vnext-utils/fs";
22
import { postJsonRequest } from "@ignored/hardhat-vnext-utils/request";
33

44
// These keys are expected to be public
5+
// TODO: replace with prod values
56
const ANALYTICS_URL = "https://www.google-analytics.com/mp/collect";
67
const API_SECRET = "iXzTRik5RhahYpgiatSv1w";
78
const MEASUREMENT_ID = "G-ZFZWHGZ64H";
89

9-
async function main(): Promise<void> {
10-
const payload = JSON.parse(process.argv[2]);
11-
12-
if (process.env.HARDHAT_TEST_SUBPROCESS_RESULT_PATH === undefined) {
13-
await postJsonRequest(ANALYTICS_URL, payload, {
14-
queryParams: {
15-
api_secret: API_SECRET,
16-
measurement_id: MEASUREMENT_ID,
17-
},
18-
});
19-
20-
return;
21-
}
10+
const payload = JSON.parse(process.argv[2]);
2211

12+
if (process.env.HARDHAT_TEST_SUBPROCESS_RESULT_PATH === undefined) {
13+
await postJsonRequest(ANALYTICS_URL, payload, {
14+
queryParams: {
15+
api_secret: API_SECRET,
16+
measurement_id: MEASUREMENT_ID,
17+
},
18+
});
19+
} else {
2320
// ATTENTION: only for testing
2421
await writeJsonFile(process.env.HARDHAT_TEST_SUBPROCESS_RESULT_PATH, payload);
2522
}
26-
27-
await main();

v-next/hardhat/src/internal/cli/telemetry/telemetry-permissions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function isTelemetryAllowed(): Promise<boolean> {
6262
/**
6363
* Determines if telemetry is allowed in the current environment.
6464
* This function checks various environmental factors to decide if telemetry data can be collected.
65-
* It verifies that the environment is not a continuous integration (CI) environment, that the terminal is interactive,
65+
* It verifies that the environment is not a CI environment, that the terminal is interactive,
6666
* and that telemetry has not been explicitly disabled through an environment variable.
6767
*
6868
* @returns True if telemetry is allowed in the environment, false otherwise.

v-next/hardhat/test/fixture-projects/cli/telemetry/analytics/analytics-subprocess.js

-20
This file was deleted.

0 commit comments

Comments
 (0)