hardhat 3.1.8 → 3.1.10
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 +23 -0
- package/dist/src/config.d.ts +20 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +31 -0
- package/dist/src/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.js +33 -21
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.js.map +1 -1
- 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 +7 -8
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/instrumentation.d.ts +27 -0
- package/dist/src/internal/builtin-plugins/coverage/instrumentation.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/instrumentation.js +27 -0
- package/dist/src/internal/builtin-plugins/coverage/instrumentation.js.map +1 -0
- package/dist/src/internal/builtin-plugins/flatten/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.js +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.d.ts +0 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.js +4 -8
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/config.js +58 -20
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/config.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 +8 -0
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.js +1 -2
- package/dist/src/internal/builtin-plugins/node/task-action.js.map +1 -1
- 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 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts +0 -3
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js +8 -10
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.d.ts +2 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.js +4 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts +3 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.js +8 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.js +19 -5
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts +8 -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 +54 -20
- 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/type-extensions.d.ts +22 -0
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts.map +1 -1
- 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 -0
- package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/cli/error-handler.d.ts.map +1 -1
- package/dist/src/internal/cli/error-handler.js +15 -0
- package/dist/src/internal/cli/error-handler.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.js +4 -0
- package/dist/src/internal/cli/telemetry/sentry/reporter.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/transport.js +1 -0
- package/dist/src/internal/cli/telemetry/sentry/transport.js.map +1 -1
- package/dist/src/internal/core/config-validation.d.ts +3 -3
- package/dist/src/internal/core/config-validation.d.ts.map +1 -1
- package/dist/src/internal/core/config-validation.js +48 -18
- package/dist/src/internal/core/config-validation.js.map +1 -1
- package/dist/src/internal/core/tasks/builders.d.ts +26 -16
- package/dist/src/internal/core/tasks/builders.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/builders.js +65 -6
- package/dist/src/internal/core/tasks/builders.js.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.d.ts +2 -2
- package/dist/src/internal/core/tasks/resolved-task.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.js +23 -9
- package/dist/src/internal/core/tasks/resolved-task.js.map +1 -1
- package/dist/src/internal/core/tasks/task-manager.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/task-manager.js +14 -6
- package/dist/src/internal/core/tasks/task-manager.js.map +1 -1
- package/dist/src/internal/core/tasks/validations.d.ts +2 -0
- package/dist/src/internal/core/tasks/validations.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/validations.js +11 -0
- package/dist/src/internal/core/tasks/validations.js.map +1 -1
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.d.ts +2 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.d.ts.map +1 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.js +12 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.js.map +1 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts +35 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts.map +1 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.js +98 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.js.map +1 -0
- package/dist/src/plugins.d.ts +8 -0
- package/dist/src/plugins.d.ts.map +1 -1
- package/dist/src/plugins.js +13 -0
- package/dist/src/plugins.js.map +1 -1
- package/dist/src/types/index.d.ts +15 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +15 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/plugins.d.ts +2 -2
- package/dist/src/types/solidity/errors.d.ts +18 -0
- package/dist/src/types/solidity/errors.d.ts.map +1 -1
- package/dist/src/types/solidity/errors.js.map +1 -1
- package/dist/src/types/tasks.d.ts +95 -34
- package/dist/src/types/tasks.d.ts.map +1 -1
- package/package.json +10 -6
- package/src/config.ts +37 -0
- package/src/internal/builtin-plugins/coverage/coverage-manager.ts +57 -50
- package/src/internal/builtin-plugins/coverage/hook-handlers/solidity.ts +6 -17
- package/src/internal/builtin-plugins/coverage/instrumentation.ts +52 -0
- package/src/internal/builtin-plugins/flatten/task-action.ts +1 -0
- package/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts +6 -11
- package/src/internal/builtin-plugins/network-manager/hook-handlers/config.ts +65 -21
- package/src/internal/builtin-plugins/network-manager/type-validation.ts +9 -0
- package/src/internal/builtin-plugins/node/task-action.ts +2 -2
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +1 -0
- package/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.ts +14 -11
- package/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.ts +23 -1
- package/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts +16 -2
- package/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.ts +19 -5
- package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +103 -29
- package/src/internal/builtin-plugins/solidity/type-extensions.ts +28 -0
- package/src/internal/builtin-plugins/solidity-test/config.ts +1 -0
- package/src/internal/builtin-plugins/solidity-test/type-extensions.ts +1 -0
- package/src/internal/cli/error-handler.ts +18 -0
- package/src/internal/cli/telemetry/sentry/reporter.ts +5 -0
- package/src/internal/cli/telemetry/sentry/transport.ts +1 -0
- package/src/internal/core/config-validation.ts +67 -18
- package/src/internal/core/tasks/builders.ts +174 -30
- package/src/internal/core/tasks/resolved-task.ts +31 -13
- package/src/internal/core/tasks/task-manager.ts +23 -5
- package/src/internal/core/tasks/validations.ts +40 -0
- package/src/internal/deprecated-module-imported-from-hardhat2-plugin.ts +12 -0
- package/src/internal/using-hardhat2-plugin-errors.ts +108 -0
- package/src/plugins.ts +16 -0
- package/src/types/index.ts +14 -0
- package/src/types/plugins.ts +2 -2
- package/src/types/solidity/errors.ts +22 -0
- package/src/types/tasks.ts +133 -36
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +10 -10
- package/templates/hardhat-3/02-mocha-ethers/package.json +16 -16
- package/templates/hardhat-3/03-minimal/package.json +1 -1
|
@@ -19,6 +19,7 @@ import { TaskDefinitionType } from "../../../types/tasks.js";
|
|
|
19
19
|
import { ResolvedTask } from "./resolved-task.js";
|
|
20
20
|
import { formatTaskId, getActorFragment } from "./utils.js";
|
|
21
21
|
import {
|
|
22
|
+
validateAction,
|
|
22
23
|
validateId,
|
|
23
24
|
validateOption,
|
|
24
25
|
validatePositionalArgument,
|
|
@@ -41,7 +42,7 @@ export class TaskManagerImplementation implements TaskManager {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
for (const taskDefinition of plugin.tasks) {
|
|
44
|
-
this.#validateTaskDefinition(taskDefinition);
|
|
45
|
+
this.#validateTaskDefinition(taskDefinition, true);
|
|
45
46
|
this.#reduceTaskDefinition(
|
|
46
47
|
globalOptionDefinitions,
|
|
47
48
|
taskDefinition,
|
|
@@ -52,7 +53,7 @@ export class TaskManagerImplementation implements TaskManager {
|
|
|
52
53
|
|
|
53
54
|
// reduce global user defined tasks
|
|
54
55
|
for (const taskDefinition of this.#hre.config.tasks) {
|
|
55
|
-
this.#validateTaskDefinition(taskDefinition);
|
|
56
|
+
this.#validateTaskDefinition(taskDefinition, false);
|
|
56
57
|
this.#reduceTaskDefinition(globalOptionDefinitions, taskDefinition);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -171,7 +172,9 @@ export class TaskManagerImplementation implements TaskManager {
|
|
|
171
172
|
this.#hre,
|
|
172
173
|
taskDefinition.id,
|
|
173
174
|
taskDefinition.description,
|
|
174
|
-
taskDefinition.action
|
|
175
|
+
taskDefinition.action !== undefined
|
|
176
|
+
? { action: taskDefinition.action }
|
|
177
|
+
: { inlineAction: taskDefinition.inlineAction },
|
|
175
178
|
taskDefinition.options,
|
|
176
179
|
taskDefinition.positionalArguments,
|
|
177
180
|
pluginId,
|
|
@@ -278,10 +281,18 @@ export class TaskManagerImplementation implements TaskManager {
|
|
|
278
281
|
task.description = taskDefinition.description;
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
task.actions.push({
|
|
284
|
+
task.actions.push({
|
|
285
|
+
pluginId,
|
|
286
|
+
...(taskDefinition.action !== undefined
|
|
287
|
+
? { action: taskDefinition.action }
|
|
288
|
+
: { inlineAction: taskDefinition.inlineAction }),
|
|
289
|
+
});
|
|
282
290
|
}
|
|
283
291
|
|
|
284
|
-
#validateTaskDefinition(
|
|
292
|
+
#validateTaskDefinition(
|
|
293
|
+
taskDefinition: TaskDefinition,
|
|
294
|
+
isPlugin: boolean,
|
|
295
|
+
): void {
|
|
285
296
|
validateId(taskDefinition.id);
|
|
286
297
|
|
|
287
298
|
// Empty tasks don't have actions, options, or positional arguments
|
|
@@ -289,6 +300,13 @@ export class TaskManagerImplementation implements TaskManager {
|
|
|
289
300
|
return;
|
|
290
301
|
}
|
|
291
302
|
|
|
303
|
+
validateAction(
|
|
304
|
+
taskDefinition.action,
|
|
305
|
+
taskDefinition.inlineAction,
|
|
306
|
+
taskDefinition.id,
|
|
307
|
+
isPlugin,
|
|
308
|
+
);
|
|
309
|
+
|
|
292
310
|
const usedNames = new Set<string>();
|
|
293
311
|
|
|
294
312
|
Object.values(taskDefinition.options).forEach((optionDefinition) =>
|
|
@@ -4,6 +4,12 @@ import type {
|
|
|
4
4
|
OptionDefinition,
|
|
5
5
|
PositionalArgumentDefinition,
|
|
6
6
|
} from "../../../types/arguments.js";
|
|
7
|
+
import type {
|
|
8
|
+
LazyActionObject,
|
|
9
|
+
NewTaskActionFunction,
|
|
10
|
+
TaskArguments,
|
|
11
|
+
TaskOverrideActionFunction,
|
|
12
|
+
} from "../../../types/tasks.js";
|
|
7
13
|
|
|
8
14
|
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
|
9
15
|
|
|
@@ -23,6 +29,40 @@ export function validateId(id: string | string[]): void {
|
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
|
|
32
|
+
export function validateAction(
|
|
33
|
+
action:
|
|
34
|
+
| LazyActionObject<NewTaskActionFunction<TaskArguments>>
|
|
35
|
+
| LazyActionObject<TaskOverrideActionFunction<TaskArguments>>
|
|
36
|
+
| undefined,
|
|
37
|
+
inlineAction:
|
|
38
|
+
| NewTaskActionFunction<TaskArguments>
|
|
39
|
+
| TaskOverrideActionFunction<TaskArguments>
|
|
40
|
+
| undefined,
|
|
41
|
+
taskId: string[],
|
|
42
|
+
isPlugin: boolean,
|
|
43
|
+
): void {
|
|
44
|
+
if (isPlugin && inlineAction !== undefined) {
|
|
45
|
+
throw new HardhatError(
|
|
46
|
+
HardhatError.ERRORS.CORE.TASK_DEFINITIONS.INLINE_ACTION_CANNOT_BE_USED_IN_PLUGINS,
|
|
47
|
+
{ task: formatTaskId(taskId) },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (action !== undefined && inlineAction !== undefined) {
|
|
52
|
+
throw new HardhatError(
|
|
53
|
+
HardhatError.ERRORS.CORE.TASK_DEFINITIONS.ACTION_AND_INLINE_ACTION_SET,
|
|
54
|
+
{ task: formatTaskId(taskId) },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (action === undefined && inlineAction === undefined) {
|
|
59
|
+
throw new HardhatError(
|
|
60
|
+
HardhatError.ERRORS.CORE.TASK_DEFINITIONS.NO_ACTION,
|
|
61
|
+
{ task: formatTaskId(taskId) },
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
26
66
|
export function validateOption(
|
|
27
67
|
{ name, shortName, type, defaultValue }: OptionDefinition,
|
|
28
68
|
usedNames: Set<string>,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// This is an empty module that is used to exported it with a subpath that's
|
|
2
|
+
// commonly used by Hardhat 2 plugins. This is to avoid the plugins breaking
|
|
3
|
+
// when the `require` it, so that they have an opportunity to run a function
|
|
4
|
+
// that throws a better error message.
|
|
5
|
+
|
|
6
|
+
// The reason this module can be empty is that Hardhat 2 plugins are CJS modules
|
|
7
|
+
// so they can destructure the require and get `undefined` values, instead of
|
|
8
|
+
// a load-time error.
|
|
9
|
+
|
|
10
|
+
// We could also throw from this file, but if it gets imported by an ESM module
|
|
11
|
+
// you don't get an import-stack-trace, so you loose the possibility of figuring
|
|
12
|
+
// out which plugin is triggering the error.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
import { CustomError } from "@nomicfoundation/hardhat-utils/error";
|
|
4
|
+
import { shortenPath } from "@nomicfoundation/hardhat-utils/path";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
export class UsingHardhat2PluginError extends CustomError {
|
|
8
|
+
public readonly callerRelativePath: string | undefined;
|
|
9
|
+
constructor() {
|
|
10
|
+
const callerPath = getCallerRelativePath();
|
|
11
|
+
|
|
12
|
+
let message: string;
|
|
13
|
+
if (callerPath !== undefined) {
|
|
14
|
+
message = `You are trying to use a Hardhat 2 plugin in a Hardhat 3 project.
|
|
15
|
+
|
|
16
|
+
This file is part of a Hardhat 2 plugin calling an API that was removed in Hardhat 3: ${chalk.bold(callerPath)}
|
|
17
|
+
|
|
18
|
+
Please read https://hardhat.org/migrate-from-hardhat2 to learn how to migrate your project to Hardhat 3.
|
|
19
|
+
`;
|
|
20
|
+
} else {
|
|
21
|
+
message = `You are trying to use a Hardhat 2 plugin in a Hardhat 3 project.
|
|
22
|
+
|
|
23
|
+
Check the stack trace below to identify which plugin is causing this.
|
|
24
|
+
|
|
25
|
+
Please read https://hardhat.org/migrate-from-hardhat2 to learn how to migrate your project to Hardhat 3.
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
super(message);
|
|
30
|
+
this.callerRelativePath = callerPath;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns the relative path of the file that called a deprecated Hardhat
|
|
36
|
+
* plugin API, based on the stack trace. This helps identify which plugin
|
|
37
|
+
* file is triggering usage of Hardhat 2 APIs in a Hardhat 3 project.
|
|
38
|
+
*
|
|
39
|
+
* @param {number} [depth=5] The stack trace depth to locate the caller's
|
|
40
|
+
* source file. By default, depth 5 is used because:
|
|
41
|
+
* 0 = message
|
|
42
|
+
* 1 = getCallerRelativePath
|
|
43
|
+
* 2 = UsingHardhat2PluginError constructor
|
|
44
|
+
* 3 = throwUsingHardhat2PluginError
|
|
45
|
+
* 4 = deprecated function
|
|
46
|
+
* 5 = actual caller (the plugin file)
|
|
47
|
+
*
|
|
48
|
+
* @returns {string|undefined} The shortened relative path of the caller file,
|
|
49
|
+
* or undefined if not found.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* If the stack trace is:
|
|
53
|
+
* // Error
|
|
54
|
+
* // at getCallerRelativePath (src/internal/using-hardhat2-plugin-errors.ts:34:15)
|
|
55
|
+
* // at UsingHardhat2PluginError.constructor (src/internal/using-hardhat2-plugin-errors.ts:7:3)
|
|
56
|
+
* // at throwUsingHardhat2PluginError (src/internal/using-hardhat2-plugin-errors.ts:90:3)
|
|
57
|
+
* // at deprecatedFunction (plugins/example-plugin/deprecated.js:50:10)
|
|
58
|
+
* // at main (plugins/example-plugin/index.js:100:5)
|
|
59
|
+
* Calling getCallerRelativePath() returns 'plugins/example-plugin/index.js'
|
|
60
|
+
*/
|
|
61
|
+
export function getCallerRelativePath(depth: number = 5): string | undefined {
|
|
62
|
+
try {
|
|
63
|
+
const stack = new Error().stack;
|
|
64
|
+
if (stack === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const lines = stack.split("\n");
|
|
69
|
+
const callerLine = lines[depth];
|
|
70
|
+
if (callerLine === undefined) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Matches a single stack trace line:
|
|
76
|
+
*
|
|
77
|
+
* at FunctionName (path/to/file.ts:10:5)
|
|
78
|
+
* at path/to/file.ts:10:5
|
|
79
|
+
*
|
|
80
|
+
* Captures:
|
|
81
|
+
* - group 1: file location (without line/column)
|
|
82
|
+
*/
|
|
83
|
+
const STACK_TRACE_LINE_REGEX =
|
|
84
|
+
/^at (?:.+? \()?([^\(].*?)(?::\d+)?(?::\d+)?\)?$/;
|
|
85
|
+
|
|
86
|
+
const match = callerLine.trim().match(STACK_TRACE_LINE_REGEX);
|
|
87
|
+
if (match === null || match[1] === undefined) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let filePath = match[1];
|
|
92
|
+
|
|
93
|
+
// Handle file:// URLs from ESM stack traces
|
|
94
|
+
if (filePath.startsWith("file://")) {
|
|
95
|
+
filePath = fileURLToPath(filePath);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return shortenPath(filePath);
|
|
99
|
+
} catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function throwUsingHardhat2PluginError(): never {
|
|
105
|
+
/* eslint-disable-next-line no-restricted-syntax -- Intentionally throwing a
|
|
106
|
+
custom error here so that we always print the stack trace */
|
|
107
|
+
throw new UsingHardhat2PluginError();
|
|
108
|
+
}
|
package/src/plugins.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
export { HardhatPluginError } from "@nomicfoundation/hardhat-errors";
|
|
2
|
+
|
|
3
|
+
import { throwUsingHardhat2PluginError } from "./internal/using-hardhat2-plugin-errors.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated This function is part of the Hardhat 2 plugin API.
|
|
7
|
+
*/
|
|
8
|
+
export function lazyFunction(..._args: any): any {
|
|
9
|
+
throwUsingHardhat2PluginError();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated This function is part of the Hardhat 2 plugin API.
|
|
14
|
+
*/
|
|
15
|
+
export function lazyObject(..._args: any): any {
|
|
16
|
+
throwUsingHardhat2PluginError();
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./arguments.js";
|
|
2
|
+
export * from "./artifacts.js";
|
|
3
|
+
export * from "./config.js";
|
|
4
|
+
export * from "./global-options.js";
|
|
5
|
+
export * from "./hooks.js";
|
|
6
|
+
export * from "./hre.js";
|
|
7
|
+
export * from "./network.js";
|
|
8
|
+
export * from "./plugins.js";
|
|
9
|
+
export * from "./providers.js";
|
|
10
|
+
export * from "./solidity.js";
|
|
11
|
+
export * from "./tasks.js";
|
|
12
|
+
export * from "./test.js";
|
|
13
|
+
export * from "./user-interruptions.js";
|
|
14
|
+
export * from "./utils.js";
|
package/src/types/plugins.ts
CHANGED
|
@@ -65,8 +65,8 @@ export interface HardhatPlugin {
|
|
|
65
65
|
* returning an object with a handler for the `extendUserConfig` hook.
|
|
66
66
|
*
|
|
67
67
|
* You can define each factory in two ways:
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* - As an inline function.
|
|
69
|
+
* - As a string with the path to a file that exports the factory as `default`.
|
|
70
70
|
*
|
|
71
71
|
* The first option should only be used for development. You MUST use the second
|
|
72
72
|
* option for production.
|
|
@@ -91,6 +91,11 @@ export interface NpmRootFileOfUninstalledPackageError {
|
|
|
91
91
|
type: RootResolutionErrorType.NPM_ROOT_FILE_OF_UNINSTALLED_PACKAGE;
|
|
92
92
|
npmModule: string;
|
|
93
93
|
installationName: string;
|
|
94
|
+
/**
|
|
95
|
+
* A boolean indicating if the Hardhat project has a foundry.toml file in its
|
|
96
|
+
* root.
|
|
97
|
+
*/
|
|
98
|
+
projectHasFoundryToml?: boolean;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
export interface NpmRootResolutionWithRemappingErrors {
|
|
@@ -109,6 +114,10 @@ export interface NpmRootFileWithIncorrectCasingError
|
|
|
109
114
|
extends ResolvedFileReference {
|
|
110
115
|
type: RootResolutionErrorType.NPM_ROOT_FILE_WITH_INCORRECT_CASING;
|
|
111
116
|
npmModule: string;
|
|
117
|
+
/**
|
|
118
|
+
* The correct casing of the file, expressed as the relative fs path from the
|
|
119
|
+
* package's root, using forward slashes, and without a leading "./".
|
|
120
|
+
*/
|
|
112
121
|
correctCasing: string;
|
|
113
122
|
}
|
|
114
123
|
|
|
@@ -216,6 +225,10 @@ export interface ImportInvalidCasingError extends ResolvedFileReference {
|
|
|
216
225
|
type: ImportResolutionErrorType.IMPORT_INVALID_CASING;
|
|
217
226
|
fromFsPath: string;
|
|
218
227
|
importPath: string;
|
|
228
|
+
/**
|
|
229
|
+
* The correct casing of the file, expressed as the relative fs path from the
|
|
230
|
+
* package's root, using forward slashes, and without a leading "./".
|
|
231
|
+
*/
|
|
219
232
|
correctCasing: string;
|
|
220
233
|
}
|
|
221
234
|
|
|
@@ -230,6 +243,11 @@ export interface ImportOfUninstalledPackageError {
|
|
|
230
243
|
fromFsPath: string;
|
|
231
244
|
importPath: string;
|
|
232
245
|
installationName: string;
|
|
246
|
+
/**
|
|
247
|
+
* A boolean indicating weather the import is from a source file whose package
|
|
248
|
+
* has a foundry.toml file in its root.
|
|
249
|
+
*/
|
|
250
|
+
importerPackageHasFoundryToml?: boolean;
|
|
233
251
|
}
|
|
234
252
|
|
|
235
253
|
export interface ImportWithRemappingErrorsError {
|
|
@@ -348,10 +366,14 @@ export interface ResolvedFileReference {
|
|
|
348
366
|
// package's input source name root, after applying the user remapping.
|
|
349
367
|
// - For an npm import, it's the npm-subpath. i.e. the module identifier
|
|
350
368
|
// without the package name.
|
|
369
|
+
//
|
|
370
|
+
// This never includes a leading "./".
|
|
351
371
|
subpath: string;
|
|
352
372
|
|
|
353
373
|
// The subpath after resolving package.exports
|
|
354
374
|
//
|
|
355
375
|
// Only present when actually using package.exports.
|
|
376
|
+
//
|
|
377
|
+
// This never includes a leading "./".
|
|
356
378
|
packageExportsResolvedSubpath?: string;
|
|
357
379
|
}
|
package/src/types/tasks.ts
CHANGED
|
@@ -75,6 +75,17 @@ export enum TaskDefinitionType {
|
|
|
75
75
|
TASK_OVERRIDE = "TASK_OVERRIDE",
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
export type TaskAction =
|
|
79
|
+
| { action: LazyActionObject<NewTaskActionFunction>; inlineAction?: never }
|
|
80
|
+
| { inlineAction: NewTaskActionFunction; action?: never };
|
|
81
|
+
|
|
82
|
+
export type TaskOverrideAction =
|
|
83
|
+
| {
|
|
84
|
+
action: LazyActionObject<TaskOverrideActionFunction>;
|
|
85
|
+
inlineAction?: never;
|
|
86
|
+
}
|
|
87
|
+
| { inlineAction: TaskOverrideActionFunction; action?: never };
|
|
88
|
+
|
|
78
89
|
/**
|
|
79
90
|
* Empty task definition. It is meant to be used as a placeholder task that only
|
|
80
91
|
* prints information about its subtasks.
|
|
@@ -90,37 +101,44 @@ export interface EmptyTaskDefinition {
|
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
/**
|
|
93
|
-
* The definition of a new task.
|
|
104
|
+
* The base definition of a new task.
|
|
94
105
|
*/
|
|
95
|
-
export interface
|
|
106
|
+
export interface BaseTaskDefinition {
|
|
96
107
|
type: TaskDefinitionType.NEW_TASK;
|
|
97
108
|
|
|
98
109
|
id: string[];
|
|
99
110
|
|
|
100
111
|
description: string;
|
|
101
112
|
|
|
102
|
-
action: LazyActionObject<NewTaskActionFunction>;
|
|
103
|
-
|
|
104
113
|
options: Record<string, OptionDefinition>;
|
|
105
114
|
|
|
106
115
|
positionalArguments: PositionalArgumentDefinition[];
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
/**
|
|
110
|
-
*
|
|
119
|
+
* The definition of a new task.
|
|
111
120
|
*/
|
|
112
|
-
export
|
|
121
|
+
export type NewTaskDefinition = BaseTaskDefinition & TaskAction;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The base definition of an override of an existing task.
|
|
125
|
+
*/
|
|
126
|
+
export interface BaseTaskOverrideDefinition {
|
|
113
127
|
type: TaskDefinitionType.TASK_OVERRIDE;
|
|
114
128
|
|
|
115
129
|
id: string[];
|
|
116
130
|
|
|
117
131
|
description?: string;
|
|
118
132
|
|
|
119
|
-
action: LazyActionObject<TaskOverrideActionFunction>;
|
|
120
|
-
|
|
121
133
|
options: Record<string, OptionDefinition>;
|
|
122
134
|
}
|
|
123
135
|
|
|
136
|
+
/**
|
|
137
|
+
* An override of an existing task.
|
|
138
|
+
*/
|
|
139
|
+
export type TaskOverrideDefinition = BaseTaskOverrideDefinition &
|
|
140
|
+
TaskOverrideAction;
|
|
141
|
+
|
|
124
142
|
/**
|
|
125
143
|
* The definition of a task, as used in the plugins and user config. They are
|
|
126
144
|
* declarative descriptions of the task, which are later processed to create the
|
|
@@ -160,9 +178,16 @@ export interface EmptyTaskDefinitionBuilder {
|
|
|
160
178
|
|
|
161
179
|
/**
|
|
162
180
|
* A builder for creating NewTaskDefinitions.
|
|
181
|
+
*
|
|
182
|
+
* @template TaskArgumentsT The arguments of the task.
|
|
183
|
+
* @template ActionTypeT Tracks if the action is "LAZY_ACTION" (Plugin Safe) or "INLINE_ACTION".
|
|
163
184
|
*/
|
|
164
185
|
export interface NewTaskDefinitionBuilder<
|
|
165
186
|
TaskArgumentsT extends TaskArguments = TaskArguments,
|
|
187
|
+
ActionTypeT extends
|
|
188
|
+
| "LAZY_ACTION"
|
|
189
|
+
| "INLINE_ACTION"
|
|
190
|
+
| "MISSING_ACTION" = "MISSING_ACTION",
|
|
166
191
|
> {
|
|
167
192
|
/**
|
|
168
193
|
* Sets the description of the task.
|
|
@@ -172,15 +197,38 @@ export interface NewTaskDefinitionBuilder<
|
|
|
172
197
|
/**
|
|
173
198
|
* Sets the action of the task.
|
|
174
199
|
*
|
|
175
|
-
* It
|
|
176
|
-
*
|
|
200
|
+
* It must be provided as a lazy import function that returns a module with
|
|
201
|
+
* a default export, like `() => import("./my-action.js")`.
|
|
177
202
|
*
|
|
178
|
-
* Note that plugins
|
|
179
|
-
*
|
|
203
|
+
* Note that plugins cannot use inline actions (see {@link setInlineAction}).
|
|
204
|
+
* They must use this method with a lazy import.
|
|
205
|
+
*
|
|
206
|
+
* @remarks
|
|
207
|
+
* This method can only be called once per task definition. Calling it multiple
|
|
208
|
+
* times will result in a runtime error.
|
|
209
|
+
*
|
|
210
|
+
* This method cannot be used together with {@link setInlineAction} on the same
|
|
211
|
+
* task. Use one or the other.
|
|
180
212
|
*/
|
|
181
213
|
setAction(
|
|
182
214
|
action: LazyActionObject<NewTaskActionFunction<TaskArgumentsT>>,
|
|
183
|
-
):
|
|
215
|
+
): NewTaskDefinitionBuilder<TaskArgumentsT, "LAZY_ACTION">;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Sets the inline action of the task.
|
|
219
|
+
*
|
|
220
|
+
* It must be provided as a function.
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* This method can only be called once per task definition. Calling it multiple
|
|
224
|
+
* times will result in a runtime error.
|
|
225
|
+
*
|
|
226
|
+
* This method cannot be used together with {@link setAction} on the same
|
|
227
|
+
* task. Use one or the other.
|
|
228
|
+
*/
|
|
229
|
+
setInlineAction(
|
|
230
|
+
inlineAction: NewTaskActionFunction<TaskArgumentsT>,
|
|
231
|
+
): NewTaskDefinitionBuilder<TaskArgumentsT, "INLINE_ACTION">;
|
|
184
232
|
|
|
185
233
|
/**
|
|
186
234
|
* Adds an option to the task.
|
|
@@ -202,7 +250,8 @@ export interface NewTaskDefinitionBuilder<
|
|
|
202
250
|
defaultValue: ArgumentTypeToValueType<TypeT>;
|
|
203
251
|
hidden?: boolean;
|
|
204
252
|
}): NewTaskDefinitionBuilder<
|
|
205
|
-
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT
|
|
253
|
+
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT>,
|
|
254
|
+
ActionTypeT
|
|
206
255
|
>;
|
|
207
256
|
|
|
208
257
|
/**
|
|
@@ -214,7 +263,8 @@ export interface NewTaskDefinitionBuilder<
|
|
|
214
263
|
description?: string;
|
|
215
264
|
hidden?: boolean;
|
|
216
265
|
}): NewTaskDefinitionBuilder<
|
|
217
|
-
ExtendTaskArguments<NameT, ArgumentType.FLAG, TaskArgumentsT
|
|
266
|
+
ExtendTaskArguments<NameT, ArgumentType.FLAG, TaskArgumentsT>,
|
|
267
|
+
ActionTypeT
|
|
218
268
|
>;
|
|
219
269
|
|
|
220
270
|
/**
|
|
@@ -226,7 +276,8 @@ export interface NewTaskDefinitionBuilder<
|
|
|
226
276
|
description?: string;
|
|
227
277
|
defaultValue?: number;
|
|
228
278
|
}): NewTaskDefinitionBuilder<
|
|
229
|
-
ExtendTaskArguments<NameT, ArgumentType.LEVEL, TaskArgumentsT
|
|
279
|
+
ExtendTaskArguments<NameT, ArgumentType.LEVEL, TaskArgumentsT>,
|
|
280
|
+
ActionTypeT
|
|
230
281
|
>;
|
|
231
282
|
|
|
232
283
|
/**
|
|
@@ -254,7 +305,8 @@ export interface NewTaskDefinitionBuilder<
|
|
|
254
305
|
type?: TypeT;
|
|
255
306
|
defaultValue?: ArgumentTypeToValueType<TypeT>;
|
|
256
307
|
}): NewTaskDefinitionBuilder<
|
|
257
|
-
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT
|
|
308
|
+
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT>,
|
|
309
|
+
ActionTypeT
|
|
258
310
|
>;
|
|
259
311
|
|
|
260
312
|
/**
|
|
@@ -280,20 +332,35 @@ export interface NewTaskDefinitionBuilder<
|
|
|
280
332
|
type?: TypeT;
|
|
281
333
|
defaultValue?: Array<ArgumentTypeToValueType<TypeT>>;
|
|
282
334
|
}): NewTaskDefinitionBuilder<
|
|
283
|
-
ExtendTaskArguments<NameT, TypeT[], TaskArgumentsT
|
|
335
|
+
ExtendTaskArguments<NameT, TypeT[], TaskArgumentsT>,
|
|
336
|
+
ActionTypeT
|
|
284
337
|
>;
|
|
285
338
|
|
|
286
339
|
/**
|
|
287
340
|
* Builds the NewTaskDefinition.
|
|
288
341
|
*/
|
|
289
|
-
build():
|
|
342
|
+
build(): ActionTypeT extends "LAZY_ACTION"
|
|
343
|
+
? Extract<
|
|
344
|
+
NewTaskDefinition,
|
|
345
|
+
{ action: LazyActionObject<NewTaskActionFunction> }
|
|
346
|
+
>
|
|
347
|
+
: ActionTypeT extends "INLINE_ACTION"
|
|
348
|
+
? Extract<NewTaskDefinition, { inlineAction: NewTaskActionFunction }>
|
|
349
|
+
: never;
|
|
290
350
|
}
|
|
291
351
|
|
|
292
352
|
/**
|
|
293
|
-
* A builder for overriding existing tasks
|
|
353
|
+
* A builder for overriding existing tasks
|
|
354
|
+
*
|
|
355
|
+
* @template TaskArgumentsT The arguments of the task.
|
|
356
|
+
* @template ActionTypeT Tracks if the action is "LAZY_ACTION" (Plugin Safe) or "INLINE_ACTION".
|
|
294
357
|
*/
|
|
295
358
|
export interface TaskOverrideDefinitionBuilder<
|
|
296
359
|
TaskArgumentsT extends TaskArguments = TaskArguments,
|
|
360
|
+
ActionTypeT extends
|
|
361
|
+
| "LAZY_ACTION"
|
|
362
|
+
| "INLINE_ACTION"
|
|
363
|
+
| "MISSING_ACTION" = "MISSING_ACTION",
|
|
297
364
|
> {
|
|
298
365
|
/**
|
|
299
366
|
* Sets a new description for the task.
|
|
@@ -307,7 +374,16 @@ export interface TaskOverrideDefinitionBuilder<
|
|
|
307
374
|
*/
|
|
308
375
|
setAction(
|
|
309
376
|
action: LazyActionObject<TaskOverrideActionFunction<TaskArgumentsT>>,
|
|
310
|
-
):
|
|
377
|
+
): TaskOverrideDefinitionBuilder<TaskArgumentsT, "LAZY_ACTION">;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Sets a new inline action for the task.
|
|
381
|
+
*
|
|
382
|
+
* @see NewTaskDefinitionBuilder.setInlineAction
|
|
383
|
+
*/
|
|
384
|
+
setInlineAction(
|
|
385
|
+
inlineAction: TaskOverrideActionFunction<TaskArgumentsT>,
|
|
386
|
+
): TaskOverrideDefinitionBuilder<TaskArgumentsT, "INLINE_ACTION">;
|
|
311
387
|
|
|
312
388
|
/**
|
|
313
389
|
* Adds a new option to the task.
|
|
@@ -325,7 +401,8 @@ export interface TaskOverrideDefinitionBuilder<
|
|
|
325
401
|
defaultValue: ArgumentTypeToValueType<TypeT>;
|
|
326
402
|
hidden?: boolean;
|
|
327
403
|
}): TaskOverrideDefinitionBuilder<
|
|
328
|
-
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT
|
|
404
|
+
ExtendTaskArguments<NameT, TypeT, TaskArgumentsT>,
|
|
405
|
+
ActionTypeT
|
|
329
406
|
>;
|
|
330
407
|
|
|
331
408
|
/**
|
|
@@ -337,7 +414,8 @@ export interface TaskOverrideDefinitionBuilder<
|
|
|
337
414
|
description?: string;
|
|
338
415
|
hidden?: boolean;
|
|
339
416
|
}): TaskOverrideDefinitionBuilder<
|
|
340
|
-
ExtendTaskArguments<NameT, ArgumentType.FLAG, TaskArgumentsT
|
|
417
|
+
ExtendTaskArguments<NameT, ArgumentType.FLAG, TaskArgumentsT>,
|
|
418
|
+
ActionTypeT
|
|
341
419
|
>;
|
|
342
420
|
|
|
343
421
|
/**
|
|
@@ -349,36 +427,55 @@ export interface TaskOverrideDefinitionBuilder<
|
|
|
349
427
|
description?: string;
|
|
350
428
|
defaultValue?: number;
|
|
351
429
|
}): TaskOverrideDefinitionBuilder<
|
|
352
|
-
ExtendTaskArguments<NameT, ArgumentType.LEVEL, TaskArgumentsT
|
|
430
|
+
ExtendTaskArguments<NameT, ArgumentType.LEVEL, TaskArgumentsT>,
|
|
431
|
+
ActionTypeT
|
|
353
432
|
>;
|
|
354
433
|
|
|
355
434
|
/**
|
|
356
435
|
* Builds the TaskOverrideDefinition.
|
|
357
436
|
*/
|
|
358
|
-
build():
|
|
437
|
+
build(): ActionTypeT extends "LAZY_ACTION"
|
|
438
|
+
? Extract<
|
|
439
|
+
TaskOverrideDefinition,
|
|
440
|
+
{ action: LazyActionObject<TaskOverrideActionFunction> }
|
|
441
|
+
>
|
|
442
|
+
: ActionTypeT extends "INLINE_ACTION"
|
|
443
|
+
? Extract<
|
|
444
|
+
TaskOverrideDefinition,
|
|
445
|
+
{ inlineAction: TaskOverrideActionFunction }
|
|
446
|
+
>
|
|
447
|
+
: never;
|
|
359
448
|
}
|
|
360
449
|
|
|
361
450
|
/**
|
|
362
451
|
* The actions associated to the task, in order.
|
|
363
452
|
*
|
|
364
453
|
* Each of them has the pluginId of the plugin that defined it, if any, and the
|
|
365
|
-
* action itself.
|
|
454
|
+
* action itself. The action is stored either in `action` or `inlineAction`.
|
|
455
|
+
* Note that `inlineAction` is reserved for user tasks and is not allowed for plugins.
|
|
366
456
|
*
|
|
367
|
-
* Note that the first action is a `NewTaskActionFunction
|
|
368
|
-
* `undefined
|
|
457
|
+
* Note that the first action is a `NewTaskActionFunction` or undefined.
|
|
458
|
+
* `undefined` is only used for empty tasks.
|
|
369
459
|
*
|
|
370
|
-
* The rest of the actions always have a `TaskOverrideActionFunction
|
|
371
|
-
* `string`.
|
|
460
|
+
* The rest of the actions always have a `TaskOverrideActionFunction`.
|
|
372
461
|
*/
|
|
373
462
|
export type TaskActions = [
|
|
463
|
+
// The Task Definition
|
|
374
464
|
{
|
|
375
465
|
pluginId?: string;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
466
|
+
} & (
|
|
467
|
+
| TaskAction
|
|
468
|
+
| {
|
|
469
|
+
action?: undefined;
|
|
470
|
+
inlineAction?: undefined;
|
|
471
|
+
}
|
|
472
|
+
),
|
|
473
|
+
// The Task Overrides
|
|
474
|
+
...Array<
|
|
475
|
+
{
|
|
476
|
+
pluginId?: string;
|
|
477
|
+
} & TaskOverrideAction
|
|
478
|
+
>,
|
|
382
479
|
];
|
|
383
480
|
|
|
384
481
|
/**
|