Skip to content

Commit 9632d21

Browse files
committed
refactor: move tasks out to lazy loaded files
Move the task actions into files that are lazy loaded avoiding import overheads in `index.ts` for the plugin.
1 parent d7e8ee4 commit 9632d21

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

Diff for: v-next/hardhat-keystore/src/index.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins";
22

33
import { ArgumentType, task } from "@ignored/hardhat-vnext/config";
44

5-
import { get, list, remove, set } from "./methods.js";
6-
75
export const PLUGIN_ID = "hardhat-keystore";
86

97
const hardhatKeystorePlugin: HardhatPlugin = {
@@ -31,10 +29,7 @@ const hardhatKeystorePlugin: HardhatPlugin = {
3129
name: "force",
3230
description: "Forces overwrite if the key already exists.",
3331
})
34-
.setAction(async ({ key, force }) => {
35-
// await set(key, hre);
36-
await set(key, force);
37-
})
32+
.setAction(import.meta.resolve("./tasks/set.js"))
3833
.build(),
3934

4035
task(["keystore", "get"], "Get a value given a key")
@@ -43,15 +38,11 @@ const hardhatKeystorePlugin: HardhatPlugin = {
4338
type: ArgumentType.STRING,
4439
description: "Specifies the key to retrieve the value for",
4540
})
46-
.setAction(async ({ key }) => {
47-
await get(key);
48-
})
41+
.setAction(import.meta.resolve("./tasks/get.js"))
4942
.build(),
5043

5144
task(["keystore", "list"], "List all keys in the keystore")
52-
.setAction(async () => {
53-
await list();
54-
})
45+
.setAction(import.meta.resolve("./tasks/list.js"))
5546
.build(),
5647

5748
task(["keystore", "delete"], "Delete a key from the keystore")
@@ -60,9 +51,7 @@ const hardhatKeystorePlugin: HardhatPlugin = {
6051
type: ArgumentType.STRING,
6152
description: "Specifies the key to delete from the keystore",
6253
})
63-
.setAction(async ({ key }) => {
64-
await remove(key);
65-
})
54+
.setAction(import.meta.resolve("./tasks/delete.js"))
6655
.build(),
6756
],
6857
};

Diff for: v-next/hardhat-keystore/src/tasks/delete.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
2+
3+
import { remove } from "../methods.js";
4+
5+
interface TaskDeleteArguments {
6+
key: string;
7+
}
8+
9+
const taskDelete: NewTaskActionFunction<TaskDeleteArguments> = async ({
10+
key,
11+
}) => {
12+
await remove(key);
13+
};
14+
15+
export default taskDelete;

Diff for: v-next/hardhat-keystore/src/tasks/get.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
2+
3+
import { get } from "../methods.js";
4+
5+
interface TaskGetArguments {
6+
key: string;
7+
}
8+
9+
const taskGet: NewTaskActionFunction<TaskGetArguments> = async ({ key }) => {
10+
await get(key);
11+
};
12+
13+
export default taskGet;

Diff for: v-next/hardhat-keystore/src/tasks/list.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
2+
3+
import { list } from "../methods.js";
4+
5+
const taskList: NewTaskActionFunction = async () => {
6+
await list();
7+
};
8+
9+
export default taskList;

Diff for: v-next/hardhat-keystore/src/tasks/set.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
2+
3+
import { set } from "../methods.js";
4+
5+
interface TaskGetArguments {
6+
key: string;
7+
force: boolean;
8+
}
9+
10+
const taskSet: NewTaskActionFunction<TaskGetArguments> = async ({
11+
key,
12+
force,
13+
}) => {
14+
await set(key, force);
15+
};
16+
17+
export default taskSet;

0 commit comments

Comments
 (0)