Skip to content

Commit 34f171f

Browse files
committed
Make #resolveFileAction use the action pluginId instead of the task pluginId
1 parent c1c9718 commit 34f171f

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

v-next/core/src/internal/tasks/resolved-task.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ export class ResolvedTask implements Task {
130130
): Promise<any> => {
131131
// The first action may be empty if the task was originally an empty task
132132
const currentAction = this.actions[currentIndex].action ?? (() => {});
133-
134133
const actionFn =
135134
typeof currentAction === "function"
136135
? currentAction
137-
: await this.#resolveFileAction(currentAction);
136+
: await this.#resolveFileAction(
137+
currentAction,
138+
this.actions[currentIndex].pluginId,
139+
);
138140

139141
if (currentIndex === 0) {
140142
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
@@ -241,21 +243,22 @@ export class ResolvedTask implements Task {
241243
*/
242244
async #resolveFileAction(
243245
actionFileUrl: string,
246+
actionPluginId?: string,
244247
): Promise<NewTaskActionFunction | TaskOverrideActionFunction> {
245248
let resolvedActionFn;
246249
try {
247250
resolvedActionFn = await import(actionFileUrl);
248251
} catch (error) {
249252
ensureError(error);
250253

251-
if (this.pluginId !== undefined) {
254+
if (actionPluginId !== undefined) {
252255
const plugin = this.#hre.config.plugins.find(
253-
(p) => p.id === this.pluginId,
256+
(p) => p.id === actionPluginId,
254257
);
255258

256259
assertHardhatInvariant(
257260
plugin !== undefined,
258-
`Plugin with id ${this.pluginId} not found.`,
261+
`Plugin with id ${actionPluginId} not found.`,
259262
);
260263

261264
await detectPluginNpmDependencyProblems(plugin);

v-next/core/test/internal/tasks/task-manager.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,8 @@ describe("TaskManagerImplementation", () => {
15301530
"./fixture-projects/not-installed-package/index.js",
15311531
);
15321532

1533-
const hre = await createHardhatRuntimeEnvironment({
1533+
// the missing dependency is used in the NEW_TASK action
1534+
let hre = await createHardhatRuntimeEnvironment({
15341535
plugins: [
15351536
{
15361537
id: "plugin1",
@@ -1544,13 +1545,42 @@ describe("TaskManagerImplementation", () => {
15441545
],
15451546
});
15461547

1547-
const task1 = hre.tasks.getTask("task1");
15481548
await assert.rejects(
1549-
task1.run({}),
1549+
hre.tasks.getTask("task1").run({}),
15501550
new HardhatError(HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, {
15511551
pluginId: "plugin1",
15521552
}),
15531553
);
1554+
1555+
// the missing dependency is used in the TASK_OVERRIDE action
1556+
hre = await createHardhatRuntimeEnvironment({
1557+
plugins: [
1558+
{
1559+
id: "plugin1",
1560+
tasks: [
1561+
new NewTaskDefinitionBuilderImplementation("task1")
1562+
.setAction(() => {})
1563+
.build(),
1564+
],
1565+
},
1566+
{
1567+
id: "plugin2",
1568+
npmPackage: "non-installed-package",
1569+
tasks: [
1570+
new TaskOverrideDefinitionBuilderImplementation("task1")
1571+
.setAction(nonInstalledPackageActionUrl)
1572+
.build(),
1573+
],
1574+
},
1575+
],
1576+
});
1577+
1578+
await assert.rejects(
1579+
hre.tasks.getTask("task1").run({}),
1580+
new HardhatError(HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, {
1581+
pluginId: "plugin2",
1582+
}),
1583+
);
15541584
});
15551585

15561586
it("should throw if an action url is provided and the corresponding module doesn't have a default export", async () => {

0 commit comments

Comments
 (0)