Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/smooth-socks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@nomicfoundation/hardhat-errors": patch
"@nomicfoundation/hardhat-verify": patch
"hardhat": patch
---

Added support for `inline actions` in tasks [7851](https://github.com/NomicFoundation/hardhat/pull/7851).
16 changes: 16 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,22 @@ Please double check your arguments.`,

Please check you have the correct subtask.`,
},
INLINE_ACTION_CANNOT_BE_USED_IN_PLUGINS: {
number: 417,
messageTemplate: `The task "{task}" defines an "inlineAction", which is not allowed in plugins.`,
websiteTitle: "Inline action not allowed in plugins",
websiteDescription: `Plugins are not allowed to use inline actions for tasks.

Please define the action in a separate file and reference it.`,
},
ACTION_AND_INLINE_ACTION_CONFLICT: {
number: 418,
messageTemplate: `The definition for task "{task}" contains conflicting properties: "action" and "inlineAction". You must remove one of them.`,
websiteTitle: `Task definition cannot use both "action" and "inlineAction"`,
websiteDescription: `A task cannot define both "action" and "inlineAction" properties at the same time.

Please remove one of the properties.`,
},
},
ARGUMENTS: {
INVALID_VALUE_FOR_TYPE: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { NewTaskDefinition } from "hardhat/types/tasks";
import type { PluginSafeTaskDefinition } from "hardhat/types/plugins";

import { task } from "hardhat/config";

import { extendWithVerificationArgs } from "../utils.js";

const verifyBlockscoutTask: NewTaskDefinition = extendWithVerificationArgs(
task(["verify", "blockscout"], "Verify a contract on Blockscout"),
)
.setAction(() => import("./task-action.js"))
.build();
const verifyBlockscoutTask: PluginSafeTaskDefinition =
extendWithVerificationArgs(
task(["verify", "blockscout"], "Verify a contract on Blockscout"),
)
.setAction(() => import("./task-action.js"))
.build();

export default verifyBlockscoutTask;
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { NewTaskDefinition } from "hardhat/types/tasks";
import type { PluginSafeTaskDefinition } from "hardhat/types/plugins";

import { task } from "hardhat/config";

import { extendWithVerificationArgs } from "../utils.js";

const verifyEtherscanTask: NewTaskDefinition = extendWithVerificationArgs(
task(["verify", "etherscan"], "Verify a contract on Etherscan"),
)
.setAction(() => import("./task-action.js"))
.build();
const verifyEtherscanTask: PluginSafeTaskDefinition =
extendWithVerificationArgs(
task(["verify", "etherscan"], "Verify a contract on Etherscan"),
)
.setAction(() => import("./task-action.js"))
.build();

export default verifyEtherscanTask;
4 changes: 2 additions & 2 deletions v-next/hardhat-verify/src/internal/tasks/verify/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { NewTaskDefinition } from "hardhat/types/tasks";
import type { PluginSafeTaskDefinition } from "hardhat/types/plugins";

import { task } from "hardhat/config";

import { extendWithSourcifyArgs, extendWithVerificationArgs } from "./utils.js";

const verifyTask: NewTaskDefinition = extendWithSourcifyArgs(
const verifyTask: PluginSafeTaskDefinition = extendWithSourcifyArgs(
extendWithVerificationArgs(
task("verify", "Verify a contract on all supported explorers"),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NewTaskDefinition } from "hardhat/types/tasks";
import type { PluginSafeTaskDefinition } from "hardhat/types/plugins";

import { task } from "hardhat/config";

Expand All @@ -7,7 +7,7 @@ import {
extendWithVerificationArgs,
} from "../utils.js";

const verifySourcifyTask: NewTaskDefinition = extendWithSourcifyArgs(
const verifySourcifyTask: PluginSafeTaskDefinition = extendWithSourcifyArgs(
extendWithVerificationArgs(
task(["verify", "sourcify"], "Verify a contract on Sourcify"),
),
Expand Down
48 changes: 35 additions & 13 deletions v-next/hardhat/src/internal/core/config-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
} from "../../types/arguments.js";
import {
type EmptyTaskDefinition,
TaskDefinitionType,
type NewTaskDefinition,
type TaskDefinition,
TaskDefinitionType,
type TaskOverrideDefinition,
} from "../../types/tasks.js";

Expand Down Expand Up @@ -272,12 +272,23 @@ export function validateNewTask(
});
}

if (typeof task.action !== "function") {
validationErrors.push({
path: [...path, "action"],
message:
"task action must be a lazy import function returning a module with a default export",
});
// Either action or inlineAction must be defined
if (task.action !== undefined) {
if (typeof task.action !== "function") {
validationErrors.push({
path: [...path, "action"],
message:
"task action must be a lazy import function returning a module with a default export",
});
}
} else {
if (typeof task.inlineAction !== "function") {
validationErrors.push({
path: [...path, "inlineAction"],
message:
"task inlineAction must be a function implementing the task's behavior",
});
}
}

if (isObject(task.options)) {
Expand Down Expand Up @@ -328,12 +339,23 @@ export function validateTaskOverride(
});
}

if (typeof task.action !== "function") {
validationErrors.push({
path: [...path, "action"],
message:
"task action must be a lazy import function returning a module with a default export",
});
// Either action or inlineAction must be defined
if (task.action !== undefined) {
if (typeof task.action !== "function") {
validationErrors.push({
path: [...path, "action"],
message:
"task action must be a lazy import function returning a module with a default export",
});
}
} else {
if (typeof task.inlineAction !== "function") {
validationErrors.push({
path: [...path, "inlineAction"],
message:
"task inlineAction must be a function implementing the task's behavior",
});
}
}

if (isObject(task.options)) {
Expand Down
Loading
Loading