Skip to content

Commit ffc1468

Browse files
authored
Merge pull request #5417 from NomicFoundation/refactor-options
Rename `globalArgument` and `namedParameters`
2 parents 594c4c5 + 1cfcf75 commit ffc1468

35 files changed

+489
-505
lines changed

v-next/core/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This package contains the new core of Hardhat, which includes:
55
- The config system
66
- The configuration variables system
77
- The plugin system
8-
- The global arguments system
8+
- The global options system
99
- The hooks system
1010
- The tasks system
1111
- The user interruptions system

v-next/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"./types/cli": "./dist/src/types/cli.js",
1515
"./types/common": "./dist/src/types/common.js",
1616
"./types/config": "./dist/src/types/config.js",
17-
"./types/global-parameters": "./dist/src/types/global-parameters.js",
17+
"./types/global-options": "./dist/src/types/global-options.js",
1818
"./types/hooks": "./dist/src/types/hooks.js",
1919
"./types/hre": "./dist/src/types/hre.js",
2020
"./types/plugins": "./dist/src/types/plugins.js",

v-next/core/scripts/api-extractor.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export * from "./types/common.js";
1616
export type * from "./types/common.js";
1717
export * from "./types/config.js";
1818
export type * from "./types/config.js";
19-
export * from "./types/global-parameters.js";
20-
export type * from "./types/global-parameters.js";
19+
export * from "./types/global-options.js";
20+
export type * from "./types/global-options.js";
2121
export * from "./types/hooks.js";
2222
export type * from "./types/hooks.js";
2323
export * from "./types/hre.js";

v-next/core/src/config.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { ParameterTypeToValueType } from "./types/common.js";
22
import type { ConfigurationVariable } from "./types/config.js";
3-
import type { GlobalParameter } from "./types/global-parameters.js";
3+
import type { GlobalOption } from "./types/global-options.js";
44
import type {
55
EmptyTaskDefinitionBuilder,
66
NewTaskDefinitionBuilder,
77
TaskOverrideDefinitionBuilder,
88
} from "./types/tasks.js";
99

10-
import { buildGlobalParameterDefinition } from "./internal/global-parameters.js";
10+
import { buildGlobalOptionDefinition } from "./internal/global-options.js";
1111
import {
1212
EmptyTaskDefinitionBuilderImplementation,
1313
NewTaskDefinitionBuilderImplementation,
@@ -56,15 +56,15 @@ export function overrideTask(
5656
}
5757

5858
/**
59-
* Defines a global parameter.
59+
* Defines a global option.
6060
*/
61-
export function globalParameter<T extends ParameterType>(options: {
61+
export function globalOption<T extends ParameterType>(options: {
6262
name: string;
6363
description: string;
6464
parameterType?: T;
6565
defaultValue: ParameterTypeToValueType<T>;
66-
}): GlobalParameter {
67-
return buildGlobalParameterDefinition(options);
66+
}): GlobalOption {
67+
return buildGlobalOptionDefinition(options);
6868
}
6969

7070
/**
@@ -73,8 +73,8 @@ export function globalParameter<T extends ParameterType>(options: {
7373
export function globalFlag(options: {
7474
name: string;
7575
description: string;
76-
}): GlobalParameter {
77-
return buildGlobalParameterDefinition({
76+
}): GlobalOption {
77+
return buildGlobalOptionDefinition({
7878
...options,
7979
parameterType: ParameterType.BOOLEAN,
8080
defaultValue: false,

v-next/core/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "./types/cli.js";
22
import type { HardhatUserConfig } from "./types/config.js";
3-
import type { GlobalArguments } from "./types/global-parameters.js";
3+
import type { GlobalOptions } from "./types/global-options.js";
44
import type { HardhatRuntimeEnvironment } from "./types/hre.js";
55

66
import { HardhatRuntimeEnvironmentImplementation } from "./internal/hre.js";
@@ -9,23 +9,23 @@ import { HardhatRuntimeEnvironmentImplementation } from "./internal/hre.js";
99
* Creates an instances of the Hardhat Runtime Environment.
1010
*
1111
* @param config - The user's Hardhat configuration.
12-
* @param userProvidedGlobalArguments - The global arguments provided by the
12+
* @param userProvidedGlobalOptions - The global options provided by the
1313
* user.
1414
* @param unsafeOptions - Options used to bypass some initialization, to avoid
1515
* redoing it in the CLI. Should only be used in the official CLI.
1616
* @returns The Hardhat Runtime Environment.
1717
*/
1818
export async function createHardhatRuntimeEnvironment(
1919
config: HardhatUserConfig,
20-
userProvidedGlobalArguments: Partial<GlobalArguments> = {},
20+
userProvidedGlobalOptions: Partial<GlobalOptions> = {},
2121
unsafeOptions?: UnsafeHardhatRuntimeEnvironmentOptions,
2222
): Promise<HardhatRuntimeEnvironment> {
2323
return HardhatRuntimeEnvironmentImplementation.create(
2424
config,
25-
userProvidedGlobalArguments,
25+
userProvidedGlobalOptions,
2626
unsafeOptions,
2727
);
2828
}
2929

3030
export { resolvePluginList } from "./internal/plugins/resolve-plugin-list.js";
31-
export { buildGlobalParametersMap } from "./internal/global-parameters.js";
31+
export { buildGlobalOptionsMap } from "./internal/global-options.js";

v-next/core/src/internal/global-parameters.ts v-next/core/src/internal/global-options.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ParameterTypeToValueType } from "../types/common.js";
22
import type {
3-
GlobalArguments,
4-
GlobalParameter,
5-
GlobalParametersMap,
6-
} from "../types/global-parameters.js";
3+
GlobalOptions,
4+
GlobalOption,
5+
GlobalOptionsMap,
6+
} from "../types/global-options.js";
77
import type { HardhatPlugin } from "../types/plugins.js";
88

99
import { HardhatError } from "@nomicfoundation/hardhat-errors";
@@ -17,50 +17,50 @@ import {
1717
} from "./parameters.js";
1818

1919
/**
20-
* Builds a map of the global parameters, validating them.
20+
* Builds a map of the global options, validating them.
2121
*
2222
* Note: this function can be used before initializing the HRE, so the plugins
2323
* shouldn't be consider validated. Hence, we should validate the global
2424
* parameters.
2525
*/
26-
export function buildGlobalParametersMap(
26+
export function buildGlobalOptionsMap(
2727
resolvedPlugins: HardhatPlugin[],
28-
): GlobalParametersMap {
29-
const globalParametersMap: GlobalParametersMap = new Map();
28+
): GlobalOptionsMap {
29+
const globalOptionsMap: GlobalOptionsMap = new Map();
3030

3131
for (const plugin of resolvedPlugins) {
32-
if (plugin.globalParameters === undefined) {
32+
if (plugin.globalOptions === undefined) {
3333
continue;
3434
}
3535

36-
for (const param of plugin.globalParameters) {
37-
const existingByName = globalParametersMap.get(param.name);
36+
for (const option of plugin.globalOptions) {
37+
const existingByName = globalOptionsMap.get(option.name);
3838
if (existingByName !== undefined) {
3939
throw new HardhatError(
40-
HardhatError.ERRORS.GENERAL.GLOBAL_PARAMETER_ALREADY_DEFINED,
40+
HardhatError.ERRORS.GENERAL.GLOBAL_OPTION_ALREADY_DEFINED,
4141
{
4242
plugin: plugin.id,
43-
globalParameter: param.name,
43+
globalOption: option.name,
4444
definedByPlugin: existingByName.pluginId,
4545
},
4646
);
4747
}
4848

49-
const validatedGlobalParam = buildGlobalParameterDefinition(param);
49+
const validatedGlobalOption = buildGlobalOptionDefinition(option);
5050

5151
const mapEntry = {
5252
pluginId: plugin.id,
53-
param: validatedGlobalParam,
53+
option: validatedGlobalOption,
5454
};
5555

56-
globalParametersMap.set(validatedGlobalParam.name, mapEntry);
56+
globalOptionsMap.set(validatedGlobalOption.name, mapEntry);
5757
}
5858
}
5959

60-
return globalParametersMap;
60+
return globalOptionsMap;
6161
}
6262

63-
export function buildGlobalParameterDefinition<T extends ParameterType>({
63+
export function buildGlobalOptionDefinition<T extends ParameterType>({
6464
name,
6565
description,
6666
parameterType,
@@ -70,7 +70,7 @@ export function buildGlobalParameterDefinition<T extends ParameterType>({
7070
description: string;
7171
parameterType?: T;
7272
defaultValue: ParameterTypeToValueType<T>;
73-
}): GlobalParameter {
73+
}): GlobalOption {
7474
const type = parameterType ?? ParameterType.STRING;
7575

7676
if (!isValidParamNameCasing(name)) {
@@ -104,13 +104,13 @@ export function buildGlobalParameterDefinition<T extends ParameterType>({
104104
};
105105
}
106106

107-
export function resolveGlobalArguments(
108-
userProvidedGlobalArguments: Partial<GlobalArguments>,
109-
_globalParametersMap: GlobalParametersMap,
110-
): GlobalArguments {
111-
// TODO: Validate the userProvidedGlobalArguments and get the remaining ones
107+
export function resolveGlobalOptions(
108+
userProvidedGlobalOptions: Partial<GlobalOptions>,
109+
_globalOptionsMap: GlobalOptionsMap,
110+
): GlobalOptions {
111+
// TODO: Validate the userProvidedGlobalOptions and get the remaining ones
112112
// from env variables
113113

114114
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TODO
115-
return userProvidedGlobalArguments as GlobalArguments;
115+
return userProvidedGlobalOptions as GlobalOptions;
116116
}

v-next/core/src/internal/hre.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "../types/cli.js";
22
import type { HardhatUserConfig, HardhatConfig } from "../types/config.js";
33
import type {
4-
GlobalArguments,
5-
GlobalParametersMap,
6-
} from "../types/global-parameters.js";
4+
GlobalOptions,
5+
GlobalOptionsMap,
6+
} from "../types/global-options.js";
77
import type {
88
HardhatUserConfigValidationError,
99
HookContext,
@@ -16,9 +16,9 @@ import type { UserInterruptionManager } from "../types/user-interruptions.js";
1616

1717
import { ResolvedConfigurationVariableImplementation } from "./configuration-variables.js";
1818
import {
19-
buildGlobalParametersMap,
20-
resolveGlobalArguments,
21-
} from "./global-parameters.js";
19+
buildGlobalOptionsMap,
20+
resolveGlobalOptions,
21+
} from "./global-options.js";
2222
import { HookManagerImplementation } from "./hook-manager.js";
2323
import { resolvePluginList } from "./plugins/resolve-plugin-list.js";
2424
import { TaskManagerImplementation } from "./tasks/task-manager.js";
@@ -29,7 +29,7 @@ export class HardhatRuntimeEnvironmentImplementation
2929
{
3030
public static async create(
3131
inputUserConfig: HardhatUserConfig,
32-
userProvidedGlobalArguments: Partial<GlobalArguments>,
32+
userProvidedGlobalOptions: Partial<GlobalOptions>,
3333
unsafeOptions?: UnsafeHardhatRuntimeEnvironmentOptions,
3434
): Promise<HardhatRuntimeEnvironmentImplementation> {
3535
// TODO: Clone with lodash or https://github.com/davidmarkclements/rfdc
@@ -85,13 +85,12 @@ export class HardhatRuntimeEnvironmentImplementation
8585
plugins: resolvedPlugins,
8686
};
8787

88-
const globalParametersMap =
89-
unsafeOptions?.globalParametersMap ??
90-
buildGlobalParametersMap(resolvedPlugins);
88+
const globalOptionsMap =
89+
unsafeOptions?.globalOptionsMap ?? buildGlobalOptionsMap(resolvedPlugins);
9190

92-
const globalArguments = resolveGlobalArguments(
93-
userProvidedGlobalArguments,
94-
globalParametersMap,
91+
const globalOptions = resolveGlobalOptions(
92+
userProvidedGlobalOptions,
93+
globalOptionsMap,
9594
);
9695

9796
// Set the HookContext in the hook manager so that non-config hooks can
@@ -102,7 +101,7 @@ export class HardhatRuntimeEnvironmentImplementation
102101
const hookContext: HookContext = {
103102
hooks,
104103
config,
105-
globalArguments,
104+
globalOptions,
106105
interruptions,
107106
};
108107

@@ -113,8 +112,8 @@ export class HardhatRuntimeEnvironmentImplementation
113112
config,
114113
hooks,
115114
interruptions,
116-
globalArguments,
117-
globalParametersMap,
115+
globalOptions,
116+
globalOptionsMap,
118117
);
119118

120119
await hooks.runSequentialHandlers("hre", "created", [hre]);
@@ -129,10 +128,10 @@ export class HardhatRuntimeEnvironmentImplementation
129128
public readonly config: HardhatConfig,
130129
public readonly hooks: HookManager,
131130
public readonly interruptions: UserInterruptionManager,
132-
public readonly globalArguments: GlobalArguments,
133-
globalParametersMap: GlobalParametersMap,
131+
public readonly globalOptions: GlobalOptions,
132+
globalOptionsMap: GlobalOptionsMap,
134133
) {
135-
this.tasks = new TaskManagerImplementation(this, globalParametersMap);
134+
this.tasks = new TaskManagerImplementation(this, globalOptionsMap);
136135
}
137136
}
138137

0 commit comments

Comments
 (0)