Skip to content

Commit b02caf9

Browse files
committedAug 10, 2024·
feat: add noCompile flag to the console task
·
1 parent 3533694 commit b02caf9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed
 

‎v-next/hardhat/src/internal/builtin-plugins/console/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const hardhatPlugin: HardhatPlugin = {
1212
description: "Path to a history file",
1313
defaultValue: "console-history.txt",
1414
})
15+
.addFlag({
16+
name: "noCompile",
17+
description: "Don't compile before running this task",
18+
})
1519
.addVariadicArgument({
1620
name: "commands",
1721
description: "Commands to run in the console",

‎v-next/hardhat/src/internal/builtin-plugins/console/task-action.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,30 @@ const log = debug("hardhat:core:tasks:console");
1212
interface ConsoleActionArguments {
1313
commands: string[];
1414
history: string;
15+
noCompile: boolean;
1516
// We accept ReplOptions as an argument to allow tests overriding the IO streams
1617
options?: repl.ReplOptions;
1718
}
1819

1920
const consoleAction: NewTaskActionFunction<ConsoleActionArguments> = async (
20-
{ commands, history, options },
21+
{ commands, history, noCompile, options },
2122
hre,
2223
) => {
23-
return new Promise<REPLServer>(async (resolve) => {
24-
// Resolve the history path if it is not empty
25-
let historyPath: string | undefined;
26-
if (history !== "") {
27-
const globalCacheDir = await getCacheDir();
28-
historyPath = path.isAbsolute(history)
29-
? history
30-
: path.resolve(globalCacheDir, history);
31-
}
24+
// Resolve the history path if it is not empty
25+
let historyPath: string | undefined;
26+
if (history !== "") {
27+
const globalCacheDir = await getCacheDir();
28+
historyPath = path.isAbsolute(history)
29+
? history
30+
: path.resolve(globalCacheDir, history);
31+
}
3232

33+
// If noCompile is false, run the compile task first
34+
if (!noCompile) {
35+
// todo: run compile task
36+
}
37+
38+
return new Promise<REPLServer>(async (resolve) => {
3339
// Start a new REPL server with the default options
3440
const replServer = repl.start(options);
3541

‎v-next/hardhat/test/internal/builtin-plugins/console/task-action.ts

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe("console/task-action", function () {
4040
{
4141
commands: ['await import("./scripts/non-existent.js");', ".exit"],
4242
history: "",
43+
noCompile: false,
4344
options,
4445
},
4546
hre,
@@ -52,6 +53,7 @@ describe("console/task-action", function () {
5253
{
5354
commands: [".help", 'await import("./scripts/success.js");', ".exit"],
5455
history: "",
56+
noCompile: false,
5557
options,
5658
},
5759
hre,
@@ -64,6 +66,7 @@ describe("console/task-action", function () {
6466
{
6567
commands: ['await import("./scripts/throws.js");', ".exit"],
6668
history: "",
69+
noCompile: false,
6770
options,
6871
},
6972
hre,
@@ -80,6 +83,7 @@ describe("console/task-action", function () {
8083
{
8184
commands: ['await import("./scripts/non-existent.ts");', ".exit"],
8285
history: "",
86+
noCompile: false,
8387
options,
8488
},
8589
hre,
@@ -92,6 +96,7 @@ describe("console/task-action", function () {
9296
{
9397
commands: ['await import("./scripts/success.ts");', ".exit"],
9498
history: "",
99+
noCompile: false,
95100
options,
96101
},
97102
hre,
@@ -104,6 +109,7 @@ describe("console/task-action", function () {
104109
{
105110
commands: ['await import("./scripts/throws.ts");', ".exit"],
106111
history: "",
112+
noCompile: false,
107113
options,
108114
},
109115
hre,
@@ -118,6 +124,7 @@ describe("console/task-action", function () {
118124
{
119125
commands: ["console.log(hre);", ".exit"],
120126
history: "",
127+
noCompile: false,
121128
options,
122129
},
123130
hre,
@@ -150,6 +157,7 @@ describe("console/task-action", function () {
150157
{
151158
commands: [".help", ".exit"],
152159
history,
160+
noCompile: false,
153161
options,
154162
},
155163
hre,

0 commit comments

Comments
 (0)
Please sign in to comment.