hardhat 3.4.5 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/src/config.d.ts +0 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/hre.d.ts +0 -1
- package/dist/src/hre.d.ts.map +1 -1
- package/dist/src/hre.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/builtin-global-options.d.ts.map +1 -1
- package/dist/src/internal/builtin-global-options.js +1 -1
- package/dist/src/internal/builtin-global-options.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts +21 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js +49 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.d.ts +2 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.js +12 -2
- package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/config-resolution.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js +9 -2
- package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js +25 -5
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts +16 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js +28 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js +2 -6
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-extensions/config.d.ts +5 -3
- package/dist/src/internal/builtin-plugins/network-manager/type-extensions/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js +3 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.d.ts +18 -0
- package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.js +27 -0
- package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.js.map +1 -0
- package/dist/src/internal/builtin-plugins/node/json-rpc/handler.js +6 -5
- package/dist/src/internal/builtin-plugins/node/json-rpc/handler.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +1 -4
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +1 -11
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.d.ts +6 -10
- package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.js +54 -43
- package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/constants.d.ts +10 -0
- package/dist/src/internal/builtin-plugins/solidity/constants.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/constants.js +10 -0
- package/dist/src/internal/builtin-plugins/solidity/constants.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js +2 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.js +1 -0
- package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/compile.d.ts +9 -0
- package/dist/src/internal/builtin-plugins/solidity/tasks/compile.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/tasks/compile.js +10 -0
- package/dist/src/internal/builtin-plugins/solidity/tasks/compile.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts +4 -3
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.js +55 -8
- package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.d.ts +58 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.js +226 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.d.ts +29 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.js +244 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.d.ts +7 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.js +204 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.d.ts +21 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js +77 -0
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts +4 -3
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js +20 -3
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +5 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.d.ts +2 -0
- package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.js +2 -0
- package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts +91 -32
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/cli/error-handler.d.ts +11 -2
- package/dist/src/internal/cli/error-handler.d.ts.map +1 -1
- package/dist/src/internal/cli/error-handler.js +72 -46
- package/dist/src/internal/cli/error-handler.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts +31 -6
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +126 -13
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/init/package-manager.d.ts +7 -1
- package/dist/src/internal/cli/init/package-manager.d.ts.map +1 -1
- package/dist/src/internal/cli/init/package-manager.js +14 -2
- package/dist/src/internal/cli/init/package-manager.js.map +1 -1
- package/dist/src/internal/cli/main.d.ts.map +1 -1
- package/dist/src/internal/cli/main.js +42 -2
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/cli/telemetry/error-classification/classifier.d.ts +2 -1
- package/dist/src/internal/cli/telemetry/error-classification/classifier.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/error-classification/classifier.js +2 -1
- package/dist/src/internal/cli/telemetry/error-classification/classifier.js.map +1 -1
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts.map +1 -1
- package/dist/src/internal/using-hardhat2-plugin-errors.js +8 -11
- package/dist/src/internal/using-hardhat2-plugin-errors.js.map +1 -1
- package/dist/src/types/arguments.d.ts +1 -0
- package/dist/src/types/arguments.d.ts.map +1 -1
- package/dist/src/types/arguments.js +1 -0
- package/dist/src/types/arguments.js.map +1 -1
- package/dist/src/types/artifacts.d.ts +1 -0
- package/dist/src/types/artifacts.d.ts.map +1 -1
- package/dist/src/types/artifacts.js +1 -1
- package/dist/src/types/artifacts.js.map +1 -1
- package/dist/src/types/builtin-plugin-type-extensions.d.ts +2 -0
- package/dist/src/types/builtin-plugin-type-extensions.d.ts.map +1 -0
- package/dist/src/types/builtin-plugin-type-extensions.js +2 -0
- package/dist/src/types/builtin-plugin-type-extensions.js.map +1 -0
- package/dist/src/types/config.d.ts +1 -0
- package/dist/src/types/config.d.ts.map +1 -1
- package/dist/src/types/config.js +1 -1
- package/dist/src/types/config.js.map +1 -1
- package/dist/src/types/global-options.d.ts +1 -0
- package/dist/src/types/global-options.d.ts.map +1 -1
- package/dist/src/types/global-options.js +1 -1
- package/dist/src/types/global-options.js.map +1 -1
- package/dist/src/types/hooks.d.ts +1 -0
- package/dist/src/types/hooks.d.ts.map +1 -1
- package/dist/src/types/hooks.js +1 -1
- package/dist/src/types/hooks.js.map +1 -1
- package/dist/src/types/hre.d.ts +1 -0
- package/dist/src/types/hre.d.ts.map +1 -1
- package/dist/src/types/hre.js +1 -1
- package/dist/src/types/hre.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/network.d.ts +1 -0
- package/dist/src/types/network.d.ts.map +1 -1
- package/dist/src/types/network.js +1 -1
- package/dist/src/types/network.js.map +1 -1
- package/dist/src/types/plugins.d.ts +1 -1
- package/dist/src/types/plugins.d.ts.map +1 -1
- package/dist/src/types/plugins.js +1 -1
- package/dist/src/types/plugins.js.map +1 -1
- package/dist/src/types/providers.d.ts +1 -0
- package/dist/src/types/providers.d.ts.map +1 -1
- package/dist/src/types/providers.js +1 -1
- package/dist/src/types/providers.js.map +1 -1
- package/dist/src/types/solidity.d.ts +1 -0
- package/dist/src/types/solidity.d.ts.map +1 -1
- package/dist/src/types/solidity.js +1 -0
- package/dist/src/types/solidity.js.map +1 -1
- package/dist/src/types/tasks.d.ts +1 -0
- package/dist/src/types/tasks.d.ts.map +1 -1
- package/dist/src/types/tasks.js +1 -0
- package/dist/src/types/tasks.js.map +1 -1
- package/dist/src/types/test.d.ts +1 -0
- package/dist/src/types/test.d.ts.map +1 -1
- package/dist/src/types/test.js +1 -1
- package/dist/src/types/test.js.map +1 -1
- package/dist/src/types/user-interruptions.d.ts +1 -0
- package/dist/src/types/user-interruptions.d.ts.map +1 -1
- package/dist/src/types/user-interruptions.js +1 -1
- package/dist/src/types/user-interruptions.js.map +1 -1
- package/package.json +12 -11
- package/src/config.ts +0 -2
- package/src/hre.ts +0 -3
- package/src/index.ts +0 -3
- package/src/internal/builtin-global-options.ts +2 -1
- package/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts +90 -1
- package/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts +24 -2
- package/src/internal/builtin-plugins/network-manager/config-resolution.ts +11 -3
- package/src/internal/builtin-plugins/network-manager/edr/edr-constants.ts +2 -0
- package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +38 -8
- package/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts +43 -1
- package/src/internal/builtin-plugins/network-manager/network-manager.ts +5 -6
- package/src/internal/builtin-plugins/network-manager/type-extensions/config.ts +5 -3
- package/src/internal/builtin-plugins/network-manager/type-validation.ts +7 -1
- package/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.ts +32 -0
- package/src/internal/builtin-plugins/node/json-rpc/handler.ts +7 -5
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +2 -15
- package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +1 -2
- package/src/internal/builtin-plugins/solidity/build-system/warning-suppression.ts +81 -59
- package/src/internal/builtin-plugins/solidity/constants.ts +11 -0
- package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +2 -1
- package/src/internal/builtin-plugins/solidity/index.ts +1 -0
- package/src/internal/builtin-plugins/solidity/tasks/compile.ts +12 -0
- package/src/internal/builtin-plugins/solidity-test/config.ts +85 -12
- package/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.ts +324 -0
- package/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.ts +317 -0
- package/src/internal/builtin-plugins/solidity-test/eip712/glob.ts +225 -0
- package/src/internal/builtin-plugins/solidity-test/eip712/index.ts +120 -0
- package/src/internal/builtin-plugins/solidity-test/helpers.ts +28 -4
- package/src/internal/builtin-plugins/solidity-test/task-action.ts +12 -1
- package/src/internal/builtin-plugins/solidity-test/test-profiles.ts +1 -0
- package/src/internal/builtin-plugins/solidity-test/type-extensions.ts +100 -33
- package/src/internal/cli/error-handler.ts +103 -72
- package/src/internal/cli/init/init.ts +203 -16
- package/src/internal/cli/init/package-manager.ts +18 -1
- package/src/internal/cli/main.ts +65 -2
- package/src/internal/cli/telemetry/error-classification/classifier.ts +2 -1
- package/src/internal/using-hardhat2-plugin-errors.ts +8 -11
- package/src/types/arguments.ts +2 -0
- package/src/types/artifacts.ts +2 -0
- package/src/types/builtin-plugin-type-extensions.ts +15 -0
- package/src/types/config.ts +2 -0
- package/src/types/global-options.ts +2 -0
- package/src/types/hooks.ts +2 -0
- package/src/types/hre.ts +2 -0
- package/src/types/index.ts +2 -0
- package/src/types/network.ts +2 -0
- package/src/types/plugins.ts +1 -2
- package/src/types/providers.ts +2 -0
- package/src/types/solidity.ts +2 -0
- package/src/types/tasks.ts +2 -0
- package/src/types/test.ts +2 -0
- package/src/types/user-interruptions.ts +2 -0
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +11 -11
- package/templates/hardhat-3/01-node-test-runner-viem/tsconfig.json +4 -7
- package/templates/hardhat-3/02-mocha-ethers/package.json +13 -13
- package/templates/hardhat-3/02-mocha-ethers/tsconfig.json +4 -7
- package/templates/hardhat-3/03-minimal/package.json +2 -2
- package/templates/hardhat-3/03-minimal/tsconfig.json +4 -7
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type * as ClassifierT from "./telemetry/error-classification/classifier.js";
|
|
2
|
+
|
|
1
3
|
import { styleText } from "node:util";
|
|
2
4
|
|
|
3
5
|
import {
|
|
@@ -6,19 +8,24 @@ import {
|
|
|
6
8
|
} from "@nomicfoundation/hardhat-errors";
|
|
7
9
|
|
|
8
10
|
import { HARDHAT_NAME, HARDHAT_WEBSITE_URL } from "../constants.js";
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
// The classifier may import many unrelated things top-level to do its job, so
|
|
13
|
+
// we load it lazily.
|
|
14
|
+
let classifierModule: typeof ClassifierT | undefined;
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* The different categories of errors that can be handled by hardhat cli.
|
|
13
18
|
* Each category has a different way of being formatted and displayed.
|
|
14
19
|
* To add new categories, add a new entry to this enum and update the
|
|
15
|
-
* {@link getErrorWithCategory} and
|
|
16
|
-
* accordingly.
|
|
20
|
+
* {@link getErrorWithCategory} function and the switch inside
|
|
21
|
+
* {@link printErrorMessages} accordingly.
|
|
17
22
|
*/
|
|
18
23
|
enum ErrorCategory {
|
|
19
24
|
HARDHAT = "HARDHAT",
|
|
20
25
|
PLUGIN = "PLUGIN",
|
|
21
26
|
COMMUNITY_PLUGIN = "COMMUNITY_PLUGIN",
|
|
27
|
+
HH2_TO_HH3_MIGRATION = "HH2_TO_HH3_MIGRATION",
|
|
28
|
+
CJS_TO_ESM_MIGRATION = "CJS_TO_ESM_MIGRATION",
|
|
22
29
|
OTHER = "OTHER",
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -35,55 +42,91 @@ type ErrorWithCategory =
|
|
|
35
42
|
category: ErrorCategory.COMMUNITY_PLUGIN;
|
|
36
43
|
categorizedError: HardhatPluginError;
|
|
37
44
|
}
|
|
45
|
+
| {
|
|
46
|
+
category: ErrorCategory.HH2_TO_HH3_MIGRATION;
|
|
47
|
+
categorizedError: Error;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
category: ErrorCategory.CJS_TO_ESM_MIGRATION;
|
|
51
|
+
categorizedError: Error;
|
|
52
|
+
}
|
|
38
53
|
| {
|
|
39
54
|
category: ErrorCategory.OTHER;
|
|
40
55
|
categorizedError: unknown;
|
|
41
56
|
};
|
|
42
57
|
|
|
43
|
-
/**
|
|
44
|
-
* The different messages that can be displayed for each category of errors.
|
|
45
|
-
* - `formattedErrorMessage`: the main error message that is always displayed.
|
|
46
|
-
* - `showMoreInfoMessage`: an optional message that can be displayed to
|
|
47
|
-
* provide more information about the error. It is only displayed when stack
|
|
48
|
-
* traces are hidden.
|
|
49
|
-
* - `postErrorStackTraceMessage` an optional message that can be displayed
|
|
50
|
-
* after the stack trace. It is only displayed when stack traces are shown.
|
|
51
|
-
*/
|
|
52
|
-
interface ErrorMessages {
|
|
53
|
-
formattedErrorMessage: string;
|
|
54
|
-
showMoreInfoMessage?: string;
|
|
55
|
-
postErrorStackTraceMessage?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
58
|
/**
|
|
59
59
|
* Formats and logs error messages based on the category the error belongs to.
|
|
60
60
|
*
|
|
61
|
+
* For each category, we produce up to three pieces:
|
|
62
|
+
* - `formattedErrorMessage`: the main error message that is always displayed.
|
|
63
|
+
* - `showMoreInfoMessage`: an optional message that points the user at more
|
|
64
|
+
* info. It is only displayed when the stack trace is hidden.
|
|
65
|
+
* - `postErrorStackTraceMessage`: an optional message that is displayed after
|
|
66
|
+
* the stack trace.
|
|
67
|
+
*
|
|
61
68
|
* @param error the error to handle. Supported categories are defined in
|
|
62
69
|
* {@link ErrorCategory}.
|
|
63
70
|
* @param shouldShowStackTraces whether to show stack traces or not. If true,
|
|
64
71
|
* the stack trace is always shown. If false, the stack trace is only shown for
|
|
65
|
-
* errors of category {@link ErrorCategory.OTHER}
|
|
72
|
+
* errors of category {@link ErrorCategory.OTHER},
|
|
73
|
+
* {@link ErrorCategory.HH2_TO_HH3_MIGRATION}, and
|
|
74
|
+
* {@link ErrorCategory.CJS_TO_ESM_MIGRATION}.
|
|
66
75
|
* @param print the function used to print the error message, defaults to
|
|
67
76
|
* `console.error`. Useful for testing to capture error messages.
|
|
68
77
|
*/
|
|
69
|
-
export function printErrorMessages(
|
|
78
|
+
export async function printErrorMessages(
|
|
70
79
|
error: Error,
|
|
71
80
|
shouldShowStackTraces: boolean = false,
|
|
72
81
|
print: (message: string | Error) => void = console.error,
|
|
73
|
-
): void {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
): Promise<void> {
|
|
83
|
+
const { category, categorizedError } = await getErrorWithCategory(error);
|
|
84
|
+
|
|
85
|
+
let formattedErrorMessage: string;
|
|
86
|
+
let showMoreInfoMessage: string | undefined;
|
|
87
|
+
let postErrorStackTraceMessage: string | undefined;
|
|
88
|
+
|
|
89
|
+
switch (category) {
|
|
90
|
+
case ErrorCategory.HARDHAT:
|
|
91
|
+
formattedErrorMessage = `${styleText(["red", "bold"], `Error ${categorizedError.errorCode}:`)} ${categorizedError.formattedMessage}`;
|
|
92
|
+
showMoreInfoMessage = `For more info go to ${HARDHAT_WEBSITE_URL}${categorizedError.errorCode} or run ${HARDHAT_NAME} with --show-stack-traces`;
|
|
93
|
+
break;
|
|
94
|
+
case ErrorCategory.PLUGIN:
|
|
95
|
+
formattedErrorMessage = `${styleText(["red", "bold"], `Error ${categorizedError.errorCode} in plugin ${categorizedError.pluginId}:`)} ${categorizedError.formattedMessage}`;
|
|
96
|
+
showMoreInfoMessage = `For more info go to ${HARDHAT_WEBSITE_URL}${categorizedError.errorCode} or run ${HARDHAT_NAME} with --show-stack-traces`;
|
|
97
|
+
break;
|
|
98
|
+
case ErrorCategory.COMMUNITY_PLUGIN:
|
|
99
|
+
formattedErrorMessage = `${styleText(["red", "bold"], `Error in community plugin ${categorizedError.pluginId}:`)} ${categorizedError.message}`;
|
|
100
|
+
showMoreInfoMessage = `For more info run ${HARDHAT_NAME} with --show-stack-traces`;
|
|
101
|
+
break;
|
|
102
|
+
case ErrorCategory.HH2_TO_HH3_MIGRATION:
|
|
103
|
+
formattedErrorMessage = styleText(
|
|
104
|
+
["red", "bold"],
|
|
105
|
+
`Hardhat 3 migration error:`,
|
|
106
|
+
);
|
|
107
|
+
postErrorStackTraceMessage = `It looks like you are migrating from Hardhat 2 to Hardhat 3. The following error often shows up during this kind of migration.\nPlease read https://hardhat.org/migrate-from-hardhat2 to learn how to migrate your project to Hardhat 3.`;
|
|
108
|
+
break;
|
|
109
|
+
case ErrorCategory.CJS_TO_ESM_MIGRATION:
|
|
110
|
+
formattedErrorMessage = styleText(
|
|
111
|
+
["red", "bold"],
|
|
112
|
+
`Hardhat 3 migration error:`,
|
|
113
|
+
);
|
|
114
|
+
postErrorStackTraceMessage = `It looks like you are migrating from CommonJS to ESM. The following error often shows up during this kind of migration.\nPlease read https://hardhat.org/migrate-to-esm to learn how to migrate your project to ESM.`;
|
|
115
|
+
break;
|
|
116
|
+
case ErrorCategory.OTHER:
|
|
117
|
+
formattedErrorMessage = styleText(
|
|
118
|
+
["red", "bold"],
|
|
119
|
+
`An unexpected error occurred:`,
|
|
120
|
+
);
|
|
121
|
+
postErrorStackTraceMessage = `If you think this is a bug in Hardhat, please report it here: ${HARDHAT_WEBSITE_URL}report-bug`;
|
|
122
|
+
break;
|
|
77
123
|
}
|
|
78
124
|
|
|
79
125
|
const showStackTraces =
|
|
80
126
|
shouldShowStackTraces ||
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
showMoreInfoMessage,
|
|
85
|
-
postErrorStackTraceMessage,
|
|
86
|
-
} = getErrorMessages(error);
|
|
127
|
+
category === ErrorCategory.OTHER ||
|
|
128
|
+
category === ErrorCategory.HH2_TO_HH3_MIGRATION ||
|
|
129
|
+
category === ErrorCategory.CJS_TO_ESM_MIGRATION;
|
|
87
130
|
|
|
88
131
|
print(formattedErrorMessage);
|
|
89
132
|
|
|
@@ -100,7 +143,7 @@ export function printErrorMessages(
|
|
|
100
143
|
}
|
|
101
144
|
}
|
|
102
145
|
|
|
103
|
-
function getErrorWithCategory(error: Error): ErrorWithCategory {
|
|
146
|
+
async function getErrorWithCategory(error: Error): Promise<ErrorWithCategory> {
|
|
104
147
|
if (HardhatError.isHardhatError(error)) {
|
|
105
148
|
if (error.pluginId === undefined) {
|
|
106
149
|
return {
|
|
@@ -122,49 +165,37 @@ function getErrorWithCategory(error: Error): ErrorWithCategory {
|
|
|
122
165
|
};
|
|
123
166
|
}
|
|
124
167
|
|
|
168
|
+
if (classifierModule === undefined) {
|
|
169
|
+
classifierModule = await import(
|
|
170
|
+
"./telemetry/error-classification/classifier.js"
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Pass `ignoreDevelopmentTimeFilter=true` so the migration footer also shows
|
|
175
|
+
// when hardhat is run from inside its own monorepo — the dev-time filter is
|
|
176
|
+
// a telemetry concern (don't report to Sentry), unrelated to display routing.
|
|
177
|
+
const classifierCategory = classifierModule.classifyError(error, true);
|
|
178
|
+
if (
|
|
179
|
+
classifierCategory ===
|
|
180
|
+
classifierModule.ErrorCategory.HH2_TO_HH3_MIGRATION_ERROR
|
|
181
|
+
) {
|
|
182
|
+
return {
|
|
183
|
+
category: ErrorCategory.HH2_TO_HH3_MIGRATION,
|
|
184
|
+
categorizedError: error,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (
|
|
188
|
+
classifierCategory ===
|
|
189
|
+
classifierModule.ErrorCategory.CJS_TO_ESM_MIGRATION_ERROR
|
|
190
|
+
) {
|
|
191
|
+
return {
|
|
192
|
+
category: ErrorCategory.CJS_TO_ESM_MIGRATION,
|
|
193
|
+
categorizedError: error,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
125
197
|
return {
|
|
126
198
|
category: ErrorCategory.OTHER,
|
|
127
199
|
categorizedError: error,
|
|
128
200
|
};
|
|
129
201
|
}
|
|
130
|
-
|
|
131
|
-
function getErrorMessages(error: Error): ErrorMessages {
|
|
132
|
-
const { category, categorizedError } = getErrorWithCategory(error);
|
|
133
|
-
switch (category) {
|
|
134
|
-
case ErrorCategory.HARDHAT:
|
|
135
|
-
return {
|
|
136
|
-
formattedErrorMessage: `${styleText(["red", "bold"], `Error ${categorizedError.errorCode}:`)} ${categorizedError.formattedMessage}`,
|
|
137
|
-
showMoreInfoMessage: `For more info go to ${HARDHAT_WEBSITE_URL}${categorizedError.errorCode} or run ${HARDHAT_NAME} with --show-stack-traces`,
|
|
138
|
-
};
|
|
139
|
-
case ErrorCategory.PLUGIN:
|
|
140
|
-
return {
|
|
141
|
-
formattedErrorMessage: `${styleText(["red", "bold"], `Error ${categorizedError.errorCode} in plugin ${categorizedError.pluginId}:`)} ${categorizedError.formattedMessage}`,
|
|
142
|
-
showMoreInfoMessage: `For more info go to ${HARDHAT_WEBSITE_URL}${categorizedError.errorCode} or run ${HARDHAT_NAME} with --show-stack-traces`,
|
|
143
|
-
};
|
|
144
|
-
case ErrorCategory.COMMUNITY_PLUGIN:
|
|
145
|
-
return {
|
|
146
|
-
formattedErrorMessage: `${styleText(["red", "bold"], `Error in community plugin ${categorizedError.pluginId}:`)} ${categorizedError.message}`,
|
|
147
|
-
showMoreInfoMessage: `For more info run ${HARDHAT_NAME} with --show-stack-traces`,
|
|
148
|
-
};
|
|
149
|
-
case ErrorCategory.OTHER:
|
|
150
|
-
return {
|
|
151
|
-
formattedErrorMessage: styleText(
|
|
152
|
-
["red", "bold"],
|
|
153
|
-
`An unexpected error occurred:`,
|
|
154
|
-
),
|
|
155
|
-
postErrorStackTraceMessage: `If you think this is a bug in Hardhat, please report it here: ${HARDHAT_WEBSITE_URL}report-bug`,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function printUsingHardhat2Error(
|
|
160
|
-
error: UsingHardhat2PluginError,
|
|
161
|
-
print: (message: string | Error) => void = console.error,
|
|
162
|
-
): void {
|
|
163
|
-
print(styleText(["red", "bold"], `Hardhat 3 installation error:`));
|
|
164
|
-
print("");
|
|
165
|
-
if (error.callerRelativePath !== undefined) {
|
|
166
|
-
print(error.message);
|
|
167
|
-
} else {
|
|
168
|
-
print(error.stack);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -35,6 +35,7 @@ import { sendErrorTelemetry } from "../telemetry/error-reporter/reporter.js";
|
|
|
35
35
|
import {
|
|
36
36
|
getDevDependenciesInstallationCommand,
|
|
37
37
|
getPackageManager,
|
|
38
|
+
getVersion,
|
|
38
39
|
installsPeerDependenciesByDefault,
|
|
39
40
|
} from "./package-manager.js";
|
|
40
41
|
import {
|
|
@@ -49,6 +50,10 @@ import {
|
|
|
49
50
|
import { spawn } from "./subprocess.js";
|
|
50
51
|
import { getTemplates } from "./template.js";
|
|
51
52
|
|
|
53
|
+
export interface NonInteractiveInitHardhat3Options {
|
|
54
|
+
template: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
export interface InitHardhatOptions {
|
|
53
58
|
hardhatVersion?: "hardhat-2" | "hardhat-3";
|
|
54
59
|
workspace?: string;
|
|
@@ -60,6 +65,61 @@ export interface InitHardhatOptions {
|
|
|
60
65
|
|
|
61
66
|
const log = createDebug("hardhat:core:cli:init");
|
|
62
67
|
|
|
68
|
+
export async function initHardhat3NonInteractive(
|
|
69
|
+
options: NonInteractiveInitHardhat3Options,
|
|
70
|
+
): Promise<void> {
|
|
71
|
+
const [template, projectTypeAnalyticsPromise] = await getTemplate(
|
|
72
|
+
"hardhat-3",
|
|
73
|
+
options.template,
|
|
74
|
+
true,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const workspace = process.cwd();
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const configFilePath = await findClosestHardhatConfig(workspace);
|
|
81
|
+
|
|
82
|
+
throw new HardhatError(
|
|
83
|
+
HardhatError.ERRORS.CORE.GENERAL.HARDHAT_PROJECT_ALREADY_CREATED,
|
|
84
|
+
{
|
|
85
|
+
hardhatProjectRootPath: configFilePath,
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
if (
|
|
90
|
+
!HardhatError.isHardhatError(
|
|
91
|
+
err,
|
|
92
|
+
HardhatError.ERRORS.CORE.GENERAL.NO_CONFIG_FILE_FOUND,
|
|
93
|
+
)
|
|
94
|
+
) {
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await assertNoNonInteractiveClashes(workspace, template);
|
|
100
|
+
|
|
101
|
+
console.log("Initializing project...");
|
|
102
|
+
|
|
103
|
+
await validatePackageJson(workspace, template.packageJson, true);
|
|
104
|
+
|
|
105
|
+
await copyProjectFilesNonInteractive(workspace, template);
|
|
106
|
+
|
|
107
|
+
console.log("Installing dependencies...");
|
|
108
|
+
|
|
109
|
+
await Promise.all([
|
|
110
|
+
installProjectDependencies({
|
|
111
|
+
workspace,
|
|
112
|
+
template,
|
|
113
|
+
install: true,
|
|
114
|
+
update: true,
|
|
115
|
+
formatSuccessMessage: false,
|
|
116
|
+
}),
|
|
117
|
+
projectTypeAnalyticsPromise,
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
console.log("Project initialized");
|
|
121
|
+
}
|
|
122
|
+
|
|
63
123
|
/**
|
|
64
124
|
* initHardhat implements the project initialization wizard flow.
|
|
65
125
|
*
|
|
@@ -126,7 +186,11 @@ export async function initHardhat(options?: InitHardhatOptions): Promise<void> {
|
|
|
126
186
|
// Run them only if the user opts-in to it
|
|
127
187
|
// Concurrently, await the analytics hit
|
|
128
188
|
await Promise.all([
|
|
129
|
-
installProjectDependencies(
|
|
189
|
+
installProjectDependencies({
|
|
190
|
+
workspace,
|
|
191
|
+
template,
|
|
192
|
+
install: options?.install,
|
|
193
|
+
}),
|
|
130
194
|
projectTypeAnalyticsPromise,
|
|
131
195
|
]);
|
|
132
196
|
|
|
@@ -270,12 +334,17 @@ export async function getWorkspace(workspace?: string): Promise<string> {
|
|
|
270
334
|
*
|
|
271
335
|
* NOTE: This function is exported for testing purposes
|
|
272
336
|
*
|
|
337
|
+
* @param hardhatVersion The version of Hardhat whose templates should be considered.
|
|
273
338
|
* @param template The name of the template to use for the project initialization.
|
|
339
|
+
* @param includeAvailableTemplatesInErrors When true, a missing template throws
|
|
340
|
+
* `TEMPLATE_NOT_FOUND_WITH_LIST_OF_OPTIONS` (which lists the available
|
|
341
|
+
* templates) instead of the bare `TEMPLATE_NOT_FOUND`.
|
|
274
342
|
* @returns A tuple with two elements: the template and a promise with the analytics hit.
|
|
275
343
|
*/
|
|
276
344
|
export async function getTemplate(
|
|
277
345
|
hardhatVersion: "hardhat-2" | "hardhat-3",
|
|
278
346
|
template?: string,
|
|
347
|
+
includeAvailableTemplatesInErrors = false,
|
|
279
348
|
): Promise<[Template, Promise<boolean>]> {
|
|
280
349
|
const templates = await getTemplates(hardhatVersion);
|
|
281
350
|
|
|
@@ -299,9 +368,38 @@ export async function getTemplate(
|
|
|
299
368
|
// we wait for the GA hit before throwing
|
|
300
369
|
await projectTypeAnalyticsPromise;
|
|
301
370
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
371
|
+
if (!includeAvailableTemplatesInErrors) {
|
|
372
|
+
throw new HardhatError(
|
|
373
|
+
HardhatError.ERRORS.CORE.GENERAL.TEMPLATE_NOT_FOUND,
|
|
374
|
+
{
|
|
375
|
+
template,
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const availableTemplates = templates.map((t) => ` - ${t.name}`).join("\n");
|
|
381
|
+
throw new HardhatError(
|
|
382
|
+
HardhatError.ERRORS.CORE.GENERAL.TEMPLATE_NOT_FOUND_WITH_LIST_OF_OPTIONS,
|
|
383
|
+
{
|
|
384
|
+
template,
|
|
385
|
+
availableTemplates,
|
|
386
|
+
},
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Prints the list of available templates for the specified Hardhat version.
|
|
392
|
+
*
|
|
393
|
+
* @param hardhatVersion The version of Hardhat whose templates should be
|
|
394
|
+
* printed.
|
|
395
|
+
*/
|
|
396
|
+
export async function printTemplatesList(
|
|
397
|
+
hardhatVersion: "hardhat-2" | "hardhat-3",
|
|
398
|
+
print: (message: string) => void = console.log,
|
|
399
|
+
): Promise<void> {
|
|
400
|
+
const templates = await getTemplates(hardhatVersion);
|
|
401
|
+
const lines = templates.map((t) => ` - ${t.name}`).join("\n");
|
|
402
|
+
print(`Available templates:\n${lines}`);
|
|
305
403
|
}
|
|
306
404
|
|
|
307
405
|
/**
|
|
@@ -496,23 +594,100 @@ export async function copyProjectFiles(
|
|
|
496
594
|
console.log(`✨ ${styleText("cyan", `Template files copied`)} ✨`);
|
|
497
595
|
}
|
|
498
596
|
|
|
597
|
+
// NOTE: This function is exported for testing purposes
|
|
598
|
+
export async function assertNoNonInteractiveClashes(
|
|
599
|
+
workspace: string,
|
|
600
|
+
template: Template,
|
|
601
|
+
): Promise<void> {
|
|
602
|
+
const clashes: string[] = [];
|
|
603
|
+
|
|
604
|
+
for (const relativeTemplatePath of template.files) {
|
|
605
|
+
const relativeWorkspacePath =
|
|
606
|
+
relativeTemplateToWorkspacePath(relativeTemplatePath);
|
|
607
|
+
|
|
608
|
+
if (
|
|
609
|
+
relativeWorkspacePath === "package.json" ||
|
|
610
|
+
relativeWorkspacePath === "README.md" ||
|
|
611
|
+
path.basename(relativeWorkspacePath) === ".gitignore"
|
|
612
|
+
) {
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (await exists(path.join(workspace, relativeWorkspacePath))) {
|
|
617
|
+
clashes.push(relativeWorkspacePath);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (clashes.length === 0) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
throw new HardhatError(
|
|
626
|
+
HardhatError.ERRORS.CORE.GENERAL.NON_INTERACTIVE_INIT_WOULD_OVERWRITE_FILES,
|
|
627
|
+
{
|
|
628
|
+
files: clashes.map((f) => ` - ${f}`).join("\n"),
|
|
629
|
+
},
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// NOTE: This function is exported for testing purposes
|
|
634
|
+
export async function copyProjectFilesNonInteractive(
|
|
635
|
+
workspace: string,
|
|
636
|
+
template: Template,
|
|
637
|
+
): Promise<void> {
|
|
638
|
+
for (const relativeTemplatePath of template.files) {
|
|
639
|
+
const relativeWorkspacePath =
|
|
640
|
+
relativeTemplateToWorkspacePath(relativeTemplatePath);
|
|
641
|
+
let absoluteWorkspacePath = path.join(workspace, relativeWorkspacePath);
|
|
642
|
+
|
|
643
|
+
if (path.basename(relativeWorkspacePath) === ".gitignore") {
|
|
644
|
+
if (await exists(absoluteWorkspacePath)) {
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
} else if (
|
|
648
|
+
relativeWorkspacePath === "README.md" &&
|
|
649
|
+
(await exists(absoluteWorkspacePath))
|
|
650
|
+
) {
|
|
651
|
+
absoluteWorkspacePath = path.join(workspace, "HARDHAT.md");
|
|
652
|
+
if (await exists(absoluteWorkspacePath)) {
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
await ensureDir(path.dirname(absoluteWorkspacePath));
|
|
658
|
+
await copy(
|
|
659
|
+
path.join(template.path, relativeTemplatePath),
|
|
660
|
+
absoluteWorkspacePath,
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
499
665
|
/**
|
|
500
666
|
* installProjectDependencies prints the commands to install the project dependencies
|
|
501
667
|
* and runs them if the install option is true or if the user opts-in to it.
|
|
502
668
|
*
|
|
503
669
|
* NOTE: This function is exported for testing purposes
|
|
504
670
|
*
|
|
505
|
-
* @param
|
|
506
|
-
* @param
|
|
507
|
-
* @param
|
|
508
|
-
* @param
|
|
671
|
+
* @param options The installation options.
|
|
672
|
+
* @param options.workspace The path to the workspace to initialize the project in.
|
|
673
|
+
* @param options.template The template to use for the project initialization.
|
|
674
|
+
* @param options.install Whether to install the project dependencies.
|
|
675
|
+
* @param options.update Whether to update the project dependencies.
|
|
676
|
+
* @param options.formatSuccessMessage Whether to format the success message or not.
|
|
509
677
|
*/
|
|
510
|
-
export async function installProjectDependencies(
|
|
511
|
-
workspace
|
|
512
|
-
template
|
|
513
|
-
install
|
|
514
|
-
update
|
|
515
|
-
|
|
678
|
+
export async function installProjectDependencies({
|
|
679
|
+
workspace,
|
|
680
|
+
template,
|
|
681
|
+
install,
|
|
682
|
+
update,
|
|
683
|
+
formatSuccessMessage = true,
|
|
684
|
+
}: {
|
|
685
|
+
workspace: string;
|
|
686
|
+
template: Template;
|
|
687
|
+
install?: boolean;
|
|
688
|
+
update?: boolean;
|
|
689
|
+
formatSuccessMessage?: boolean;
|
|
690
|
+
}): Promise<void> {
|
|
516
691
|
const pathToWorkspacePackageJson = path.join(workspace, "package.json");
|
|
517
692
|
|
|
518
693
|
const workspacePkg: PackageJson = await readJsonFile(
|
|
@@ -520,6 +695,8 @@ export async function installProjectDependencies(
|
|
|
520
695
|
);
|
|
521
696
|
|
|
522
697
|
const packageManager = getPackageManager();
|
|
698
|
+
const packageManagerVersion = await getVersion(workspace, packageManager);
|
|
699
|
+
const packageManagerMajorVersion = packageManagerVersion?.[0];
|
|
523
700
|
|
|
524
701
|
// Find the template dev dependencies that are not already installed
|
|
525
702
|
const templateDependencies = template.packageJson.devDependencies ?? {};
|
|
@@ -556,6 +733,7 @@ export async function installProjectDependencies(
|
|
|
556
733
|
const command = getDevDependenciesInstallationCommand(
|
|
557
734
|
packageManager,
|
|
558
735
|
dependenciesToInstall,
|
|
736
|
+
packageManagerMajorVersion,
|
|
559
737
|
);
|
|
560
738
|
const commandString = command.join(" ");
|
|
561
739
|
|
|
@@ -587,7 +765,11 @@ export async function installProjectDependencies(
|
|
|
587
765
|
);
|
|
588
766
|
}
|
|
589
767
|
|
|
590
|
-
|
|
768
|
+
if (formatSuccessMessage) {
|
|
769
|
+
console.log(`✨ ${styleText("cyan", `Dependencies installed`)} ✨`);
|
|
770
|
+
} else {
|
|
771
|
+
console.log(`Dependencies installed`);
|
|
772
|
+
}
|
|
591
773
|
}
|
|
592
774
|
}
|
|
593
775
|
|
|
@@ -610,6 +792,7 @@ export async function installProjectDependencies(
|
|
|
610
792
|
const command = getDevDependenciesInstallationCommand(
|
|
611
793
|
packageManager,
|
|
612
794
|
dependenciesToUpdate,
|
|
795
|
+
packageManagerMajorVersion,
|
|
613
796
|
);
|
|
614
797
|
const commandString = command.join(" ");
|
|
615
798
|
|
|
@@ -640,7 +823,11 @@ export async function installProjectDependencies(
|
|
|
640
823
|
);
|
|
641
824
|
}
|
|
642
825
|
|
|
643
|
-
|
|
826
|
+
if (formatSuccessMessage) {
|
|
827
|
+
console.log(`✨ ${styleText("cyan", `Dependencies updated`)} ✨`);
|
|
828
|
+
} else {
|
|
829
|
+
console.log("Dependencies updated");
|
|
830
|
+
}
|
|
644
831
|
}
|
|
645
832
|
}
|
|
646
833
|
}
|
|
@@ -104,11 +104,16 @@ export function getPackageManager(): PackageManager {
|
|
|
104
104
|
*
|
|
105
105
|
* @param packageManager The package manager to use.
|
|
106
106
|
* @param dependencies The dependencies to install.
|
|
107
|
+
* @param packageManagerMajorVersion The major version of the package manager,
|
|
108
|
+
* if known. Used to opt into version-specific flags (e.g. pnpm 11's
|
|
109
|
+
* `--allow-build=esbuild`, required because `tsx` ships `esbuild` whose
|
|
110
|
+
* postinstall script is otherwise blocked).
|
|
107
111
|
* @returns The installation command.
|
|
108
112
|
*/
|
|
109
113
|
export function getDevDependenciesInstallationCommand(
|
|
110
114
|
packageManager: PackageManager,
|
|
111
115
|
dependencies: string[],
|
|
116
|
+
packageManagerMajorVersion?: number,
|
|
112
117
|
): string[] {
|
|
113
118
|
const packageManagerToCommand: Record<PackageManager, string[]> = {
|
|
114
119
|
npm: ["npm", "install", "--save-dev"],
|
|
@@ -118,6 +123,18 @@ export function getDevDependenciesInstallationCommand(
|
|
|
118
123
|
bun: ["bun", "add", "--dev"],
|
|
119
124
|
};
|
|
120
125
|
const command = packageManagerToCommand[packageManager];
|
|
126
|
+
|
|
127
|
+
// NOTE: adding an unnecessary flag doesn't result in an error
|
|
128
|
+
// nor warning, so we don't check if hardhat or tsx are being
|
|
129
|
+
// installed.
|
|
130
|
+
if (
|
|
131
|
+
packageManager === "pnpm" &&
|
|
132
|
+
packageManagerMajorVersion !== undefined &&
|
|
133
|
+
packageManagerMajorVersion >= 11
|
|
134
|
+
) {
|
|
135
|
+
command.push("--allow-build=esbuild");
|
|
136
|
+
}
|
|
137
|
+
|
|
121
138
|
// We quote all the dependency identifiers so that they can be run on a shell
|
|
122
139
|
// without semver symbols interfering with the command
|
|
123
140
|
command.push(
|
|
@@ -205,7 +222,7 @@ export async function installsPeerDependenciesByDefault(
|
|
|
205
222
|
}
|
|
206
223
|
}
|
|
207
224
|
|
|
208
|
-
async function getVersion(
|
|
225
|
+
export async function getVersion(
|
|
209
226
|
workspace: string,
|
|
210
227
|
packageManager: PackageManager,
|
|
211
228
|
version?: string,
|
package/src/internal/cli/main.ts
CHANGED
|
@@ -96,7 +96,70 @@ export async function main(
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
if (builtinGlobalOptions.init) {
|
|
99
|
-
const { initHardhat } =
|
|
99
|
+
const { initHardhat, initHardhat3NonInteractive, printTemplatesList } =
|
|
100
|
+
await import("./init/init.js");
|
|
101
|
+
|
|
102
|
+
let templateName: string | undefined;
|
|
103
|
+
let listTemplates = false;
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < cliArguments.length; i++) {
|
|
106
|
+
if (usedCliArguments[i]) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (cliArguments[i] === "--templates") {
|
|
111
|
+
usedCliArguments[i] = true;
|
|
112
|
+
listTemplates = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < cliArguments.length; i++) {
|
|
117
|
+
if (usedCliArguments[i]) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (cliArguments[i] === "--template") {
|
|
122
|
+
usedCliArguments[i] = true;
|
|
123
|
+
|
|
124
|
+
if (templateName !== undefined) {
|
|
125
|
+
throw new HardhatError(
|
|
126
|
+
HardhatError.ERRORS.CORE.ARGUMENTS.DUPLICATED_NAME,
|
|
127
|
+
{ name: "--template" },
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (listTemplates) {
|
|
132
|
+
throw new HardhatError(
|
|
133
|
+
HardhatError.ERRORS.CORE.ARGUMENTS.CANNOT_COMBINE_TEMPLATE_AND_TEMPLATES,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (
|
|
138
|
+
usedCliArguments[i + 1] === undefined ||
|
|
139
|
+
usedCliArguments[i + 1] === true ||
|
|
140
|
+
cliArguments[i + 1] === undefined ||
|
|
141
|
+
cliArguments[i + 1].startsWith("-")
|
|
142
|
+
) {
|
|
143
|
+
throw new HardhatError(
|
|
144
|
+
HardhatError.ERRORS.CORE.ARGUMENTS.MISSING_VALUE_FOR_ARGUMENT,
|
|
145
|
+
{ argument: "--template" },
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
templateName = cliArguments[i + 1];
|
|
150
|
+
i++;
|
|
151
|
+
usedCliArguments[i] = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (listTemplates) {
|
|
156
|
+
return await printTemplatesList("hardhat-3", print);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (templateName !== undefined) {
|
|
160
|
+
return await initHardhat3NonInteractive({ template: templateName });
|
|
161
|
+
}
|
|
162
|
+
|
|
100
163
|
return await initHardhat();
|
|
101
164
|
}
|
|
102
165
|
|
|
@@ -255,7 +318,7 @@ export async function main(
|
|
|
255
318
|
}
|
|
256
319
|
} catch (error) {
|
|
257
320
|
ensureError(error);
|
|
258
|
-
printErrorMessages(error, builtinGlobalOptions?.showStackTraces);
|
|
321
|
+
await printErrorMessages(error, builtinGlobalOptions?.showStackTraces);
|
|
259
322
|
|
|
260
323
|
try {
|
|
261
324
|
await sendErrorTelemetry(error);
|
|
@@ -70,7 +70,8 @@ import {
|
|
|
70
70
|
* @param error The error to classify.
|
|
71
71
|
* @param ignoreDevelopmentTimeFilter If true, the classifier will ignore the
|
|
72
72
|
* development-time filter, which is used to exclude errors that happen during
|
|
73
|
-
* development of Hardhat itself.
|
|
73
|
+
* development of Hardhat itself. Set this from display-side callers (where the
|
|
74
|
+
* dev-time skip is irrelevant) and from tests.
|
|
74
75
|
* @returns The error category.
|
|
75
76
|
*/
|
|
76
77
|
export function classifyError(
|