hardhat 3.8.0 → 3.9.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 +36 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +6 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/hhu.d.ts +3 -0
- package/dist/src/hhu.d.ts.map +1 -0
- package/dist/src/hhu.js +14 -0
- package/dist/src/hhu.js.map +1 -0
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.js +4 -1
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/config.d.ts +6 -0
- package/dist/src/internal/builtin-plugins/coverage/config.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/config.js +18 -0
- package/dist/src/internal/builtin-plugins/coverage/config.js.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/config.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/config.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/config.js +15 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/config.js.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js +10 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/index.js +1 -0
- package/dist/src/internal/builtin-plugins/coverage/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/type-extensions.d.ts +20 -0
- package/dist/src/internal/builtin-plugins/coverage/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.d.ts +2 -2
- package/dist/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.js +21 -23
- package/dist/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts +2 -2
- 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 +21 -27
- 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 +3 -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 +18 -10
- package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/hhu/index.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/hhu/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/index.js +9 -0
- package/dist/src/internal/builtin-plugins/hhu/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/index.d.ts +3 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/index.js +8 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/zero-address.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/zero-address.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/zero-address.js +6 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/constants/zero-address.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/index.d.ts +3 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/index.js +27 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/pad.d.ts +10 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/pad.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/pad.js +31 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/convert/pad.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/block-number.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/block-number.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/block-number.js +17 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/block-number.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/index.d.ts +3 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/index.js +8 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/fetch/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/index.d.ts +11 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/index.js +20 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/utils-task.d.ts +13 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/utils-task.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/utils-task.js +17 -0
- package/dist/src/internal/builtin-plugins/hhu/tasks/utils-task.js.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/types.d.ts +45 -0
- package/dist/src/internal/builtin-plugins/hhu/types.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/hhu/types.js +2 -0
- package/dist/src/internal/builtin-plugins/hhu/types.js.map +1 -0
- package/dist/src/internal/builtin-plugins/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/index.js +5 -0
- package/dist/src/internal/builtin-plugins/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts +2 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js +13 -10
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.d.ts +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.js +17 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/index.js +2 -10
- package/dist/src/internal/builtin-plugins/network-manager/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-option.d.ts +9 -0
- package/dist/src/internal/builtin-plugins/network-manager/network-option.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/network-option.js +15 -0
- package/dist/src/internal/builtin-plugins/network-manager/network-option.js.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/automatic-sender-handler.d.ts +4 -2
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/automatic-sender-handler.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/automatic-sender-handler.js +28 -6
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/automatic-sender-handler.js.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 +10 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
- 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 +3 -0
- package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/source-names.d.ts +12 -0
- package/dist/src/internal/builtin-plugins/solidity/source-names.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/source-names.js +18 -0
- package/dist/src/internal/builtin-plugins/solidity/source-names.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.js +1 -4
- package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js +7 -12
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.js +3 -1
- package/dist/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.js.map +1 -1
- package/dist/src/internal/cli/help/get-global-help-string.d.ts +3 -1
- package/dist/src/internal/cli/help/get-global-help-string.d.ts.map +1 -1
- package/dist/src/internal/cli/help/get-global-help-string.js +3 -3
- package/dist/src/internal/cli/help/get-global-help-string.js.map +1 -1
- package/dist/src/internal/cli/help/get-help-string.d.ts +3 -1
- package/dist/src/internal/cli/help/get-help-string.d.ts.map +1 -1
- package/dist/src/internal/cli/help/get-help-string.js +4 -4
- package/dist/src/internal/cli/help/get-help-string.js.map +1 -1
- package/dist/src/internal/cli/help/utils.d.ts +3 -1
- package/dist/src/internal/cli/help/utils.d.ts.map +1 -1
- package/dist/src/internal/cli/help/utils.js +2 -2
- package/dist/src/internal/cli/help/utils.js.map +1 -1
- package/dist/src/internal/cli/hhu.d.ts +14 -0
- package/dist/src/internal/cli/hhu.d.ts.map +1 -0
- package/dist/src/internal/cli/hhu.js +184 -0
- package/dist/src/internal/cli/hhu.js.map +1 -0
- package/dist/src/internal/cli/main.d.ts +0 -25
- package/dist/src/internal/cli/main.d.ts.map +1 -1
- package/dist/src/internal/cli/main.js +23 -303
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/cli/parser.d.ts +25 -0
- package/dist/src/internal/cli/parser.d.ts.map +1 -0
- package/dist/src/internal/cli/parser.js +282 -0
- package/dist/src/internal/cli/parser.js.map +1 -0
- package/dist/src/internal/cli/telemetry/analytics/analytics.d.ts +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.js +2 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.js.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/types.d.ts +1 -0
- package/dist/src/internal/cli/telemetry/analytics/types.d.ts.map +1 -1
- package/dist/src/internal/edr/context.d.ts.map +1 -1
- package/dist/src/internal/edr/context.js +25 -7
- package/dist/src/internal/edr/context.js.map +1 -1
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts +2 -2
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts.map +1 -1
- package/dist/src/internal/using-hardhat2-plugin-errors.js +7 -3
- package/dist/src/internal/using-hardhat2-plugin-errors.js.map +1 -1
- package/dist/src/internal/{builtin-plugins/solidity-test/eip712 → utils}/glob.d.ts +4 -0
- package/dist/src/internal/utils/glob.d.ts.map +1 -0
- package/dist/src/internal/{builtin-plugins/solidity-test/eip712 → utils}/glob.js +3 -3
- package/dist/src/internal/utils/glob.js.map +1 -0
- package/dist/src/plugins.d.ts.map +1 -1
- package/dist/src/plugins.js +3 -2
- package/dist/src/plugins.js.map +1 -1
- package/package.json +4 -4
- package/src/config.ts +17 -5
- package/src/hhu.ts +18 -0
- package/src/internal/builtin-plugins/artifacts/hook-handlers/hre.ts +11 -3
- package/src/internal/builtin-plugins/coverage/config.ts +28 -0
- package/src/internal/builtin-plugins/coverage/hook-handlers/config.ts +30 -0
- package/src/internal/builtin-plugins/coverage/hook-handlers/solidity.ts +15 -2
- package/src/internal/builtin-plugins/coverage/index.ts +1 -0
- package/src/internal/builtin-plugins/coverage/type-extensions.ts +24 -0
- package/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.ts +32 -32
- package/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts +32 -36
- package/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts +22 -9
- package/src/internal/builtin-plugins/hhu/index.ts +13 -0
- package/src/internal/builtin-plugins/hhu/tasks/constants/index.ts +18 -0
- package/src/internal/builtin-plugins/hhu/tasks/constants/zero-address.ts +9 -0
- package/src/internal/builtin-plugins/hhu/tasks/convert/index.ts +40 -0
- package/src/internal/builtin-plugins/hhu/tasks/convert/pad.ts +61 -0
- package/src/internal/builtin-plugins/hhu/tasks/fetch/block-number.ts +28 -0
- package/src/internal/builtin-plugins/hhu/tasks/fetch/index.ts +18 -0
- package/src/internal/builtin-plugins/hhu/tasks/index.ts +36 -0
- package/src/internal/builtin-plugins/hhu/tasks/utils-task.ts +29 -0
- package/src/internal/builtin-plugins/hhu/types.ts +57 -0
- package/src/internal/builtin-plugins/index.ts +6 -0
- package/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts +22 -14
- package/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts +33 -0
- package/src/internal/builtin-plugins/network-manager/index.ts +3 -10
- package/src/internal/builtin-plugins/network-manager/network-option.ts +17 -0
- package/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/automatic-sender-handler.ts +39 -9
- package/src/internal/builtin-plugins/network-manager/type-validation.ts +14 -1
- package/src/internal/builtin-plugins/solidity/build-system/warning-suppression.ts +3 -0
- package/src/internal/builtin-plugins/solidity/source-names.ts +19 -0
- package/src/internal/builtin-plugins/solidity-test/config.ts +1 -4
- package/src/internal/builtin-plugins/solidity-test/eip712/index.ts +8 -16
- package/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts +6 -1
- package/src/internal/cli/help/get-global-help-string.ts +3 -2
- package/src/internal/cli/help/get-help-string.ts +4 -3
- package/src/internal/cli/help/utils.ts +2 -1
- package/src/internal/cli/hhu.ts +298 -0
- package/src/internal/cli/main.ts +41 -495
- package/src/internal/cli/parser.ts +472 -0
- package/src/internal/cli/telemetry/analytics/analytics.ts +5 -1
- package/src/internal/cli/telemetry/analytics/types.ts +3 -0
- package/src/internal/edr/context.ts +39 -23
- package/src/internal/using-hardhat2-plugin-errors.ts +12 -3
- package/src/internal/{builtin-plugins/solidity-test/eip712 → utils}/glob.ts +3 -3
- package/src/plugins.ts +5 -2
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +6 -6
- package/templates/hardhat-3/02-mocha-ethers/package.json +9 -9
- package/templates/hardhat-3/03-minimal/package.json +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.d.ts.map +0 -1
- package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.js.map +0 -1
package/src/internal/cli/main.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GlobalOptionDefinitions,
|
|
3
|
-
GlobalOptions,
|
|
4
|
-
} from "../../types/global-options.js";
|
|
5
|
-
import type { HardhatRuntimeEnvironment } from "../../types/hre.js";
|
|
6
|
-
import type { Task, TaskArguments } from "../../types/tasks.js";
|
|
7
1
|
import type { DebugLogger } from "@nomicfoundation/hardhat-utils/debug";
|
|
8
2
|
|
|
9
3
|
import { fileURLToPath } from "node:url";
|
|
10
4
|
|
|
11
|
-
import {
|
|
12
|
-
HardhatError,
|
|
13
|
-
assertHardhatInvariant,
|
|
14
|
-
} from "@nomicfoundation/hardhat-errors";
|
|
5
|
+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
|
15
6
|
import { isCi } from "@nomicfoundation/hardhat-utils/ci";
|
|
16
7
|
import { createDebug } from "@nomicfoundation/hardhat-utils/debug";
|
|
17
8
|
import { ensureError } from "@nomicfoundation/hardhat-utils/error";
|
|
@@ -21,14 +12,8 @@ import {
|
|
|
21
12
|
findDependencyPackageJson,
|
|
22
13
|
readClosestPackageJson,
|
|
23
14
|
} from "@nomicfoundation/hardhat-utils/package";
|
|
24
|
-
import { kebabToCamelCase } from "@nomicfoundation/hardhat-utils/string";
|
|
25
15
|
import { register } from "tsx/esm/api";
|
|
26
16
|
|
|
27
|
-
import {
|
|
28
|
-
ArgumentType,
|
|
29
|
-
type OptionDefinition,
|
|
30
|
-
type PositionalArgumentDefinition,
|
|
31
|
-
} from "../../types/arguments.js";
|
|
32
17
|
import { isResult } from "../../utils/result.js";
|
|
33
18
|
import { BUILTIN_GLOBAL_OPTIONS_DEFINITIONS } from "../builtin-global-options.js";
|
|
34
19
|
import { builtinPlugins } from "../builtin-plugins/index.js";
|
|
@@ -36,18 +21,23 @@ import {
|
|
|
36
21
|
importUserConfig,
|
|
37
22
|
resolveHardhatConfigPath,
|
|
38
23
|
} from "../config-loading.js";
|
|
39
|
-
import { parseArgumentValue } from "../core/arguments.js";
|
|
40
24
|
import { buildGlobalOptionDefinitions } from "../core/global-options.js";
|
|
41
25
|
import { resolveProjectRoot } from "../core/hre.js";
|
|
42
26
|
import { resolvePluginList } from "../core/plugins/resolve-plugin-list.js";
|
|
43
27
|
import { warnAboutUnusedLoadedPlugins } from "../core/plugins/unused-plugins-warning.js";
|
|
44
|
-
import { isArgumentRequired } from "../core/tasks/utils.js";
|
|
45
28
|
import { setGlobalHardhatRuntimeEnvironment } from "../global-hre-instance.js";
|
|
46
29
|
import { createHardhatRuntimeEnvironment } from "../hre-initialization.js";
|
|
47
30
|
|
|
48
31
|
import { printErrorMessages } from "./error-handler.js";
|
|
49
32
|
import { getGlobalHelpString } from "./help/get-global-help-string.js";
|
|
50
33
|
import { getHelpString } from "./help/get-help-string.js";
|
|
34
|
+
import {
|
|
35
|
+
parseBuiltinGlobalOptions,
|
|
36
|
+
parseGlobalOptions,
|
|
37
|
+
parseRawArguments,
|
|
38
|
+
parseTask,
|
|
39
|
+
parseTaskArguments,
|
|
40
|
+
} from "./parser.js";
|
|
51
41
|
import { sendTaskAnalytics } from "./telemetry/analytics/analytics.js";
|
|
52
42
|
import { setupGlobalUnhandledErrorHandlers } from "./telemetry/error-reporter/global-error-handlers.js";
|
|
53
43
|
import {
|
|
@@ -243,7 +233,11 @@ export async function main(
|
|
|
243
233
|
// This must be the first time we set it, otherwise we let it crash
|
|
244
234
|
setGlobalHardhatRuntimeEnvironment(hre);
|
|
245
235
|
|
|
246
|
-
const taskOrId = parseTask(
|
|
236
|
+
const taskOrId = parseTask(
|
|
237
|
+
cliArguments,
|
|
238
|
+
usedCliArguments,
|
|
239
|
+
hre.tasks.rootTasks,
|
|
240
|
+
);
|
|
247
241
|
|
|
248
242
|
if (Array.isArray(taskOrId)) {
|
|
249
243
|
if (taskOrId.length === 0) {
|
|
@@ -293,7 +287,7 @@ export async function main(
|
|
|
293
287
|
|
|
294
288
|
const [taskResult] = await Promise.all([
|
|
295
289
|
task.run(taskArguments),
|
|
296
|
-
sendTaskAnalytics(task.id),
|
|
290
|
+
sendTaskAnalytics(task.id, "hardhat"),
|
|
297
291
|
]);
|
|
298
292
|
|
|
299
293
|
if (isResult(taskResult) && !taskResult.success) {
|
|
@@ -341,480 +335,6 @@ export async function main(
|
|
|
341
335
|
}
|
|
342
336
|
}
|
|
343
337
|
|
|
344
|
-
export async function parseBuiltinGlobalOptions(
|
|
345
|
-
cliArguments: string[],
|
|
346
|
-
usedCliArguments: boolean[],
|
|
347
|
-
): Promise<{
|
|
348
|
-
init: boolean;
|
|
349
|
-
configPath: string | undefined;
|
|
350
|
-
showStackTraces: boolean;
|
|
351
|
-
help: boolean;
|
|
352
|
-
version: boolean;
|
|
353
|
-
}> {
|
|
354
|
-
let configPath: string | undefined;
|
|
355
|
-
let showStackTraces: boolean = isCi();
|
|
356
|
-
let help: boolean = false;
|
|
357
|
-
let version: boolean = false;
|
|
358
|
-
let init: boolean = false;
|
|
359
|
-
|
|
360
|
-
// TODO: Use parseGlobalOptions(BUILTIN_GLOBAL_OPTIONS_DEFINITIONS, ...) instead
|
|
361
|
-
for (let i = 0; i < cliArguments.length; i++) {
|
|
362
|
-
const arg = cliArguments[i];
|
|
363
|
-
|
|
364
|
-
if (arg === "--init") {
|
|
365
|
-
usedCliArguments[i] = true;
|
|
366
|
-
init = true;
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (arg === "--config") {
|
|
371
|
-
usedCliArguments[i] = true;
|
|
372
|
-
|
|
373
|
-
if (configPath !== undefined) {
|
|
374
|
-
throw new HardhatError(
|
|
375
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.DUPLICATED_NAME,
|
|
376
|
-
{
|
|
377
|
-
name: "--config",
|
|
378
|
-
},
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
usedCliArguments[i + 1] === undefined ||
|
|
384
|
-
usedCliArguments[i + 1] === true
|
|
385
|
-
) {
|
|
386
|
-
throw new HardhatError(
|
|
387
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.MISSING_CONFIG_FILE,
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
configPath = cliArguments[i + 1];
|
|
392
|
-
i++;
|
|
393
|
-
|
|
394
|
-
usedCliArguments[i] = true;
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (arg === "--show-stack-traces") {
|
|
399
|
-
usedCliArguments[i] = true;
|
|
400
|
-
showStackTraces = true;
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (arg === "--help" || arg === "-h") {
|
|
405
|
-
usedCliArguments[i] = true;
|
|
406
|
-
help = true;
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (arg === "--version") {
|
|
411
|
-
usedCliArguments[i] = true;
|
|
412
|
-
version = true;
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (init && configPath !== undefined) {
|
|
418
|
-
throw new HardhatError(
|
|
419
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.CANNOT_COMBINE_INIT_AND_CONFIG_PATH,
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return { init, configPath, showStackTraces, help, version };
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
export async function parseGlobalOptions(
|
|
427
|
-
globalOptionDefinitions: GlobalOptionDefinitions,
|
|
428
|
-
cliArguments: string[],
|
|
429
|
-
usedCliArguments: boolean[],
|
|
430
|
-
): Promise<Partial<GlobalOptions>> {
|
|
431
|
-
const globalOptions: Partial<GlobalOptions> = {};
|
|
432
|
-
|
|
433
|
-
const optionDefinitions = new Map(
|
|
434
|
-
[...globalOptionDefinitions].map(([key, value]) => [key, value.option]),
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
parseOptions(
|
|
438
|
-
cliArguments,
|
|
439
|
-
usedCliArguments,
|
|
440
|
-
optionDefinitions,
|
|
441
|
-
globalOptions,
|
|
442
|
-
true,
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
return globalOptions;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Parses the task from the cli args.
|
|
450
|
-
*
|
|
451
|
-
* @returns The task, or an array with the unrecognized task id.
|
|
452
|
-
* If no task id is provided, an empty array is returned.
|
|
453
|
-
*/
|
|
454
|
-
export function parseTask(
|
|
455
|
-
cliArguments: string[],
|
|
456
|
-
usedCliArguments: boolean[],
|
|
457
|
-
hre: HardhatRuntimeEnvironment,
|
|
458
|
-
): Task | string[] {
|
|
459
|
-
const taskOrId = getTaskFromCliArguments(cliArguments, usedCliArguments, hre);
|
|
460
|
-
|
|
461
|
-
return taskOrId;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
function getTaskFromCliArguments(
|
|
465
|
-
cliArguments: string[],
|
|
466
|
-
usedCliArguments: boolean[],
|
|
467
|
-
hre: HardhatRuntimeEnvironment,
|
|
468
|
-
): string[] | Task {
|
|
469
|
-
const taskId = [];
|
|
470
|
-
let task: Task | undefined;
|
|
471
|
-
|
|
472
|
-
for (let i = 0; i < cliArguments.length; i++) {
|
|
473
|
-
if (usedCliArguments[i]) {
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const arg = cliArguments[i];
|
|
478
|
-
|
|
479
|
-
if (arg.startsWith("-")) {
|
|
480
|
-
/* A standalone '--' is ok because it is used to separate CLI tool arguments
|
|
481
|
-
* from task arguments, ensuring the tool passes subsequent options directly
|
|
482
|
-
* to the task. Everything after "--" should be considered as a positional
|
|
483
|
-
* argument. */
|
|
484
|
-
if (arg === "--" || task !== undefined) {
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/* At this point in the code, the global options have already been parsed, so
|
|
489
|
-
* the remaining options starting with '--' are task options. Hence, if no task
|
|
490
|
-
* is defined, it means that the option is not assigned to any task, and it's
|
|
491
|
-
* an error. */
|
|
492
|
-
throw new HardhatError(
|
|
493
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.UNRECOGNIZED_OPTION,
|
|
494
|
-
{
|
|
495
|
-
option: arg,
|
|
496
|
-
},
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (task === undefined) {
|
|
501
|
-
try {
|
|
502
|
-
task = hre.tasks.getTask(arg);
|
|
503
|
-
} catch (_error) {
|
|
504
|
-
return [arg]; // No task found
|
|
505
|
-
}
|
|
506
|
-
} else {
|
|
507
|
-
const subtask = task.subtasks.get(arg);
|
|
508
|
-
|
|
509
|
-
if (subtask === undefined) {
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
task = subtask;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
usedCliArguments[i] = true;
|
|
517
|
-
taskId.push(arg);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (task === undefined) {
|
|
521
|
-
return taskId;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
return task;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
export function parseTaskArguments(
|
|
528
|
-
cliArguments: string[],
|
|
529
|
-
usedCliArguments: boolean[],
|
|
530
|
-
task: Task,
|
|
531
|
-
): TaskArguments {
|
|
532
|
-
const taskArguments: TaskArguments = {};
|
|
533
|
-
|
|
534
|
-
// Parse options
|
|
535
|
-
parseOptions(cliArguments, usedCliArguments, task.options, taskArguments);
|
|
536
|
-
|
|
537
|
-
parsePositionalAndVariadicArguments(
|
|
538
|
-
cliArguments,
|
|
539
|
-
usedCliArguments,
|
|
540
|
-
task,
|
|
541
|
-
taskArguments,
|
|
542
|
-
);
|
|
543
|
-
|
|
544
|
-
const unusedIndex = usedCliArguments.indexOf(false);
|
|
545
|
-
|
|
546
|
-
if (unusedIndex !== -1) {
|
|
547
|
-
throw new HardhatError(HardhatError.ERRORS.CORE.ARGUMENTS.UNUSED_ARGUMENT, {
|
|
548
|
-
value: cliArguments[unusedIndex],
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return taskArguments;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Parses the raw arguments from the command line, returning an array of
|
|
557
|
-
* arguments. If an argument starts with "--" and contains "=" (i.e. "--option=123")
|
|
558
|
-
* it is split into two separate arguments: the option name and the option value.
|
|
559
|
-
*/
|
|
560
|
-
export function parseRawArguments(rawArguments: string[]): string[] {
|
|
561
|
-
return rawArguments.flatMap((arg) => {
|
|
562
|
-
if (arg.startsWith("--") && arg.includes("=")) {
|
|
563
|
-
const index = arg.indexOf("=");
|
|
564
|
-
const optionName = arg.substring(0, index);
|
|
565
|
-
const optionValue = arg.substring(index + 1);
|
|
566
|
-
|
|
567
|
-
return [optionName, optionValue];
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
return arg;
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function parseOptions(
|
|
575
|
-
cliArguments: string[],
|
|
576
|
-
usedCliArguments: boolean[],
|
|
577
|
-
optionDefinitions: Map<string, OptionDefinition>,
|
|
578
|
-
providedArguments: TaskArguments,
|
|
579
|
-
ignoreUnknownOption = false,
|
|
580
|
-
) {
|
|
581
|
-
const optionDefinitionsByShortName = new Map<string, OptionDefinition>();
|
|
582
|
-
for (const optionDefinition of optionDefinitions.values()) {
|
|
583
|
-
if (optionDefinition.shortName !== undefined) {
|
|
584
|
-
optionDefinitionsByShortName.set(
|
|
585
|
-
optionDefinition.shortName,
|
|
586
|
-
optionDefinition,
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
for (let i = 0; i < cliArguments.length; i++) {
|
|
592
|
-
if (usedCliArguments[i]) {
|
|
593
|
-
continue;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
if (cliArguments[i] === "--") {
|
|
597
|
-
/* A standalone '--' is ok because it is used to separate CLI tool arguments
|
|
598
|
-
* from task arguments, ensuring the tool passes subsequent options directly
|
|
599
|
-
* to the task. Everything after "--" should be considered as a positional
|
|
600
|
-
* argument. */
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
const arg = cliArguments[i];
|
|
605
|
-
|
|
606
|
-
let optionDefinition: OptionDefinition | undefined;
|
|
607
|
-
|
|
608
|
-
const providedByName = arg.startsWith("--");
|
|
609
|
-
const providedByShortName = !providedByName && arg.startsWith("-");
|
|
610
|
-
|
|
611
|
-
if (providedByName) {
|
|
612
|
-
const name = kebabToCamelCase(arg.substring(2));
|
|
613
|
-
optionDefinition = optionDefinitions.get(name);
|
|
614
|
-
} else if (providedByShortName) {
|
|
615
|
-
const shortName = arg[1];
|
|
616
|
-
|
|
617
|
-
// Check if the short name is valid
|
|
618
|
-
if (Array.from(arg.substring(1)).some((c) => c !== shortName)) {
|
|
619
|
-
throw new HardhatError(
|
|
620
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.CANNOT_GROUP_OPTIONS,
|
|
621
|
-
{
|
|
622
|
-
option: arg,
|
|
623
|
-
},
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
optionDefinition = optionDefinitionsByShortName.get(shortName);
|
|
628
|
-
} else {
|
|
629
|
-
continue;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
if (optionDefinition === undefined) {
|
|
633
|
-
if (ignoreUnknownOption === true) {
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// Only throw an error when the argument is not a global option, because
|
|
638
|
-
// it might be a option related to a task
|
|
639
|
-
throw new HardhatError(
|
|
640
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.UNRECOGNIZED_OPTION,
|
|
641
|
-
{
|
|
642
|
-
option: arg,
|
|
643
|
-
},
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (optionDefinition.hidden === true) {
|
|
648
|
-
throw new HardhatError(
|
|
649
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.NO_HIDDEN_OPTION_CLI,
|
|
650
|
-
{
|
|
651
|
-
option: arg,
|
|
652
|
-
},
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
const optionName = optionDefinition.name;
|
|
657
|
-
|
|
658
|
-
// Check if the short name is valid again now that we know its type
|
|
659
|
-
// E.g. --flag --flag
|
|
660
|
-
const optionAlreadyProvided = providedArguments[optionName] !== undefined;
|
|
661
|
-
// E.g. -ff
|
|
662
|
-
const shortOptionGroupedAndRepeated = providedByShortName && arg.length > 2;
|
|
663
|
-
const isLevelOption = optionDefinition.type === ArgumentType.LEVEL;
|
|
664
|
-
if (
|
|
665
|
-
optionAlreadyProvided ||
|
|
666
|
-
(shortOptionGroupedAndRepeated && !isLevelOption)
|
|
667
|
-
) {
|
|
668
|
-
throw new HardhatError(
|
|
669
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.CANNOT_REPEAT_OPTIONS,
|
|
670
|
-
{
|
|
671
|
-
option: arg,
|
|
672
|
-
type: optionDefinition.type,
|
|
673
|
-
},
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
usedCliArguments[i] = true;
|
|
678
|
-
|
|
679
|
-
if (optionDefinition.type === ArgumentType.FLAG) {
|
|
680
|
-
providedArguments[optionName] = true;
|
|
681
|
-
continue;
|
|
682
|
-
} else if (
|
|
683
|
-
optionDefinition.type === ArgumentType.LEVEL &&
|
|
684
|
-
providedByShortName
|
|
685
|
-
) {
|
|
686
|
-
providedArguments[optionName] = arg.length - 1;
|
|
687
|
-
continue;
|
|
688
|
-
} else if (
|
|
689
|
-
usedCliArguments[i + 1] !== undefined &&
|
|
690
|
-
usedCliArguments[i + 1] === false
|
|
691
|
-
) {
|
|
692
|
-
i++;
|
|
693
|
-
|
|
694
|
-
providedArguments[optionName] = parseArgumentValue(
|
|
695
|
-
cliArguments[i],
|
|
696
|
-
optionDefinition.type,
|
|
697
|
-
optionName,
|
|
698
|
-
);
|
|
699
|
-
|
|
700
|
-
usedCliArguments[i] = true;
|
|
701
|
-
|
|
702
|
-
continue;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
throw new HardhatError(
|
|
706
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.MISSING_VALUE_FOR_ARGUMENT,
|
|
707
|
-
{
|
|
708
|
-
argument: arg,
|
|
709
|
-
},
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
function parsePositionalAndVariadicArguments(
|
|
715
|
-
cliArguments: string[],
|
|
716
|
-
usedCliArguments: boolean[],
|
|
717
|
-
task: Task,
|
|
718
|
-
providedArguments: TaskArguments,
|
|
719
|
-
) {
|
|
720
|
-
let argIndex = 0;
|
|
721
|
-
|
|
722
|
-
for (let i = 0; i < cliArguments.length; i++) {
|
|
723
|
-
if (usedCliArguments[i] === true) {
|
|
724
|
-
continue;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
if (cliArguments[i] === "--") {
|
|
728
|
-
/* A standalone '--' is ok because it is used to separate CLI tool arguments
|
|
729
|
-
* from task arguments, ensuring the tool passes subsequent options directly
|
|
730
|
-
* to the task. Everything after "--" should be considered as a positional
|
|
731
|
-
* argument. */
|
|
732
|
-
usedCliArguments[i] = true;
|
|
733
|
-
continue;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
const argumentDefinition = task.positionalArguments[argIndex];
|
|
737
|
-
|
|
738
|
-
if (argumentDefinition === undefined) {
|
|
739
|
-
break;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
usedCliArguments[i] = true;
|
|
743
|
-
|
|
744
|
-
const formattedValue = parseArgumentValue(
|
|
745
|
-
cliArguments[i],
|
|
746
|
-
argumentDefinition.type,
|
|
747
|
-
argumentDefinition.name,
|
|
748
|
-
);
|
|
749
|
-
|
|
750
|
-
if (argumentDefinition.isVariadic === false) {
|
|
751
|
-
providedArguments[argumentDefinition.name] = formattedValue;
|
|
752
|
-
argIndex++;
|
|
753
|
-
continue;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// Handle variadic arguments. No longer increment "argIndex" because there can
|
|
757
|
-
// only be one variadic argument, and it will consume all remaining arguments.
|
|
758
|
-
providedArguments[argumentDefinition.name] =
|
|
759
|
-
providedArguments[argumentDefinition.name] ?? [];
|
|
760
|
-
const variadicTaskArg = providedArguments[argumentDefinition.name];
|
|
761
|
-
assertHardhatInvariant(
|
|
762
|
-
Array.isArray(variadicTaskArg),
|
|
763
|
-
"Variadic argument values should be an array",
|
|
764
|
-
);
|
|
765
|
-
variadicTaskArg.push(formattedValue);
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// Check if all the required arguments have been used
|
|
769
|
-
validateRequiredArguments(task.positionalArguments, providedArguments);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
function validateRequiredArguments(
|
|
773
|
-
argumentDefinitions: PositionalArgumentDefinition[],
|
|
774
|
-
taskArguments: TaskArguments,
|
|
775
|
-
) {
|
|
776
|
-
const missingRequiredArgument = argumentDefinitions.find(
|
|
777
|
-
({ defaultValue, name, type }) =>
|
|
778
|
-
isArgumentRequired(type, defaultValue) &&
|
|
779
|
-
taskArguments[name] === undefined,
|
|
780
|
-
);
|
|
781
|
-
|
|
782
|
-
if (missingRequiredArgument === undefined) {
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
throw new HardhatError(
|
|
787
|
-
HardhatError.ERRORS.CORE.ARGUMENTS.MISSING_VALUE_FOR_ARGUMENT,
|
|
788
|
-
{ argument: missingRequiredArgument.name },
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
* Prints an error message if the user is running Hardhat on CJS mode, returning
|
|
794
|
-
* `true` if the message was printed.
|
|
795
|
-
*/
|
|
796
|
-
async function printEsmErrorMessageIfNecessary(
|
|
797
|
-
projectRoot: string,
|
|
798
|
-
print: (message: string) => void,
|
|
799
|
-
): Promise<boolean> {
|
|
800
|
-
const packageJson = await readClosestPackageJson(projectRoot);
|
|
801
|
-
|
|
802
|
-
if (packageJson.type !== "module") {
|
|
803
|
-
print(`Hardhat only supports ESM projects.
|
|
804
|
-
|
|
805
|
-
Please make sure you have \`"type": "module"\` in your package.json.
|
|
806
|
-
|
|
807
|
-
You can set it automatically by running:
|
|
808
|
-
|
|
809
|
-
npm pkg set type="module"
|
|
810
|
-
`);
|
|
811
|
-
|
|
812
|
-
return true;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
return false;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
338
|
/**
|
|
819
339
|
* Returns true if Hardhat is installed locally or linked from its repository,
|
|
820
340
|
* by looking for it using the node module resolution logic.
|
|
@@ -825,7 +345,7 @@ npm pkg set type="module"
|
|
|
825
345
|
async function isHardhatInstalledLocallyOrLinked(
|
|
826
346
|
configPath: string,
|
|
827
347
|
log: DebugLogger,
|
|
828
|
-
) {
|
|
348
|
+
): Promise<boolean> {
|
|
829
349
|
try {
|
|
830
350
|
// Based on Node.js resolution algorithm find the real path
|
|
831
351
|
// of the project's version of Hardhat
|
|
@@ -856,3 +376,29 @@ async function isHardhatInstalledLocallyOrLinked(
|
|
|
856
376
|
return false;
|
|
857
377
|
}
|
|
858
378
|
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Prints an error message if the user is running Hardhat on CJS mode, returning
|
|
382
|
+
* `true` if the message was printed.
|
|
383
|
+
*/
|
|
384
|
+
async function printEsmErrorMessageIfNecessary(
|
|
385
|
+
projectRoot: string,
|
|
386
|
+
print: (message: string) => void,
|
|
387
|
+
): Promise<boolean> {
|
|
388
|
+
const packageJson = await readClosestPackageJson(projectRoot);
|
|
389
|
+
|
|
390
|
+
if (packageJson.type !== "module") {
|
|
391
|
+
print(`Hardhat only supports ESM projects.
|
|
392
|
+
|
|
393
|
+
Please make sure you have \`"type": "module"\` in your package.json.
|
|
394
|
+
|
|
395
|
+
You can set it automatically by running:
|
|
396
|
+
|
|
397
|
+
npm pkg set type="module"
|
|
398
|
+
`);
|
|
399
|
+
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return false;
|
|
404
|
+
}
|