1
- import {
2
- buildGlobalParameterMap ,
3
- resolvePluginList ,
4
- } from "@nomicfoundation/hardhat-core" ;
5
- import { ParameterType } from "@nomicfoundation/hardhat-core/types/common" ;
6
- import {
1
+ import type { ParameterValue } from "@nomicfoundation/hardhat-core/types/common" ;
2
+ import type {
7
3
GlobalArguments ,
8
4
GlobalParameter ,
9
5
GlobalParameterMap ,
10
6
} from "@nomicfoundation/hardhat-core/types/global-parameters" ;
11
- import { HardhatRuntimeEnvironment } from "@nomicfoundation/hardhat-core/types/hre" ;
12
- import {
7
+ import type { HardhatRuntimeEnvironment } from "@nomicfoundation/hardhat-core/types/hre" ;
8
+ import type {
13
9
NamedTaskParameter ,
14
- PositionalTaskParameter ,
15
10
Task ,
11
+ TaskArguments ,
12
+ TaskParameter ,
16
13
} from "@nomicfoundation/hardhat-core/types/tasks" ;
14
+
17
15
import "tsx" ; // NOTE: This is important, it allows us to load .ts files form the CLI
18
- import { HardhatError } from "@nomicfoundation/hardhat-errors" ;
16
+
17
+ import {
18
+ buildGlobalParameterMap ,
19
+ resolvePluginList ,
20
+ } from "@nomicfoundation/hardhat-core" ;
21
+ import { ParameterType } from "@nomicfoundation/hardhat-core/types/common" ;
22
+ import {
23
+ HardhatError ,
24
+ assertHardhatInvariant ,
25
+ } from "@nomicfoundation/hardhat-errors" ;
19
26
import { isCi } from "@nomicfoundation/hardhat-utils/ci" ;
20
27
21
28
import { builtinPlugins } from "../builtin-plugins/index.js" ;
@@ -231,7 +238,7 @@ export function parseTaskAndArguments(
231
238
) :
232
239
| {
233
240
task : Task ;
234
- taskArguments : Record < string , any > ;
241
+ taskArguments : TaskArguments ;
235
242
}
236
243
| string [ ] {
237
244
const taskOrId = getTaskFromCliArguments ( cliArguments , usedCliArguments , hre ) ;
@@ -312,8 +319,8 @@ function parseTaskArguments(
312
319
cliArguments : string [ ] ,
313
320
usedCliArguments : boolean [ ] ,
314
321
task : Task ,
315
- ) : Record < string , any > {
316
- const taskArguments : Record < string , unknown > = { } ;
322
+ ) : TaskArguments {
323
+ const taskArguments : TaskArguments = { } ;
317
324
318
325
// Parse named parameters
319
326
parseDoubleDashArgs (
@@ -345,7 +352,7 @@ function parseDoubleDashArgs(
345
352
cliArguments : string [ ] ,
346
353
usedCliArguments : boolean [ ] ,
347
354
parametersMap : Map < string , NamedTaskParameter | GlobalParameter > ,
348
- argumentsMap : Record < string , any > ,
355
+ argumentsMap : TaskArguments ,
349
356
) {
350
357
for ( let i = 0 ; i < cliArguments . length ; i ++ ) {
351
358
if ( usedCliArguments [ i ] ) {
@@ -433,7 +440,7 @@ function parsePositionalAndVariadicParameters(
433
440
cliArguments : string [ ] ,
434
441
usedCliArguments : boolean [ ] ,
435
442
task : Task ,
436
- taskArguments : Record < string , any > ,
443
+ taskArguments : TaskArguments ,
437
444
) {
438
445
let paramI = 0 ;
439
446
@@ -472,16 +479,21 @@ function parsePositionalAndVariadicParameters(
472
479
// Handle variadic parameters. No longer increment "paramI" becuase there can only be one variadic parameter and it
473
480
// will consume all remaining arguments.
474
481
taskArguments [ paramInfo . name ] = taskArguments [ paramInfo . name ] ?? [ ] ;
475
- taskArguments [ paramInfo . name ] . push ( formattedValue ) ;
482
+ const variadicTaskArg = taskArguments [ paramInfo . name ] ;
483
+ assertHardhatInvariant (
484
+ Array . isArray ( variadicTaskArg ) ,
485
+ "Variadic parameter values should be an array" ,
486
+ ) ;
487
+ variadicTaskArg . push ( formattedValue ) ;
476
488
}
477
489
478
490
// Check if all the required parameters have been used
479
491
validateRequiredParameters ( task . positionalParameters , taskArguments ) ;
480
492
}
481
493
482
494
function validateRequiredParameters (
483
- parameters : PositionalTaskParameter [ ] | NamedTaskParameter [ ] ,
484
- taskArguments : Record < string , any > ,
495
+ parameters : TaskParameter [ ] ,
496
+ taskArguments : TaskArguments ,
485
497
) {
486
498
const missingRequiredParam = parameters . find (
487
499
( param ) =>
@@ -507,7 +519,7 @@ function parseParameterValue(
507
519
strValue : string ,
508
520
type : ParameterType ,
509
521
argName : string ,
510
- ) : any {
522
+ ) : ParameterValue {
511
523
switch ( type ) {
512
524
case ParameterType . STRING :
513
525
return validateAndParseString ( argName , strValue ) ;
0 commit comments