Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename globalArgument and namedParameters #5417

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v-next/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This package contains the new core of Hardhat, which includes:
- The config system
- The configuration variables system
- The plugin system
- The global arguments system
- The global options system
- The hooks system
- The tasks system
- The user interruptions system
Expand Down
2 changes: 1 addition & 1 deletion v-next/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"./types/cli": "./dist/src/types/cli.js",
"./types/common": "./dist/src/types/common.js",
"./types/config": "./dist/src/types/config.js",
"./types/global-parameters": "./dist/src/types/global-parameters.js",
"./types/global-options": "./dist/src/types/global-options.js",
"./types/hooks": "./dist/src/types/hooks.js",
"./types/hre": "./dist/src/types/hre.js",
"./types/plugins": "./dist/src/types/plugins.js",
Expand Down
4 changes: 2 additions & 2 deletions v-next/core/scripts/api-extractor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export * from "./types/common.js";
export type * from "./types/common.js";
export * from "./types/config.js";
export type * from "./types/config.js";
export * from "./types/global-parameters.js";
export type * from "./types/global-parameters.js";
export * from "./types/global-options.js";
export type * from "./types/global-options.js";
export * from "./types/hooks.js";
export type * from "./types/hooks.js";
export * from "./types/hre.js";
Expand Down
16 changes: 8 additions & 8 deletions v-next/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ParameterTypeToValueType } from "./types/common.js";
import type { ConfigurationVariable } from "./types/config.js";
import type { GlobalParameter } from "./types/global-parameters.js";
import type { GlobalOption } from "./types/global-options.js";
import type {
EmptyTaskDefinitionBuilder,
NewTaskDefinitionBuilder,
TaskOverrideDefinitionBuilder,
} from "./types/tasks.js";

import { buildGlobalParameterDefinition } from "./internal/global-parameters.js";
import { buildGlobalOptionDefinition } from "./internal/global-options.js";
import {
EmptyTaskDefinitionBuilderImplementation,
NewTaskDefinitionBuilderImplementation,
Expand Down Expand Up @@ -56,15 +56,15 @@ export function overrideTask(
}

/**
* Defines a global parameter.
* Defines a global option.
*/
export function globalParameter<T extends ParameterType>(options: {
export function globalOption<T extends ParameterType>(options: {
name: string;
description: string;
parameterType?: T;
defaultValue: ParameterTypeToValueType<T>;
}): GlobalParameter {
return buildGlobalParameterDefinition(options);
}): GlobalOption {
return buildGlobalOptionDefinition(options);
}

/**
Expand All @@ -73,8 +73,8 @@ export function globalParameter<T extends ParameterType>(options: {
export function globalFlag(options: {
name: string;
description: string;
}): GlobalParameter {
return buildGlobalParameterDefinition({
}): GlobalOption {
return buildGlobalOptionDefinition({
...options,
parameterType: ParameterType.BOOLEAN,
defaultValue: false,
Expand Down
10 changes: 5 additions & 5 deletions v-next/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "./types/cli.js";
import type { HardhatUserConfig } from "./types/config.js";
import type { GlobalArguments } from "./types/global-parameters.js";
import type { GlobalOptions } from "./types/global-options.js";
import type { HardhatRuntimeEnvironment } from "./types/hre.js";

import { HardhatRuntimeEnvironmentImplementation } from "./internal/hre.js";
Expand All @@ -9,23 +9,23 @@ import { HardhatRuntimeEnvironmentImplementation } from "./internal/hre.js";
* Creates an instances of the Hardhat Runtime Environment.
*
* @param config - The user's Hardhat configuration.
* @param userProvidedGlobalArguments - The global arguments provided by the
* @param userProvidedGlobalOptions - The global options provided by the
* user.
* @param unsafeOptions - Options used to bypass some initialization, to avoid
* redoing it in the CLI. Should only be used in the official CLI.
* @returns The Hardhat Runtime Environment.
*/
export async function createHardhatRuntimeEnvironment(
config: HardhatUserConfig,
userProvidedGlobalArguments: Partial<GlobalArguments> = {},
userProvidedGlobalOptions: Partial<GlobalOptions> = {},
unsafeOptions?: UnsafeHardhatRuntimeEnvironmentOptions,
): Promise<HardhatRuntimeEnvironment> {
return HardhatRuntimeEnvironmentImplementation.create(
config,
userProvidedGlobalArguments,
userProvidedGlobalOptions,
unsafeOptions,
);
}

export { resolvePluginList } from "./internal/plugins/resolve-plugin-list.js";
export { buildGlobalParametersMap } from "./internal/global-parameters.js";
export { buildGlobalOptionsMap } from "./internal/global-options.js";
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ParameterTypeToValueType } from "../types/common.js";
import type {
GlobalArguments,
GlobalParameter,
GlobalParametersMap,
} from "../types/global-parameters.js";
GlobalOptions,
GlobalOption,
GlobalOptionsMap,
} from "../types/global-options.js";
import type { HardhatPlugin } from "../types/plugins.js";

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

/**
* Builds a map of the global parameters, validating them.
* Builds a map of the global options, validating them.
*
* Note: this function can be used before initializing the HRE, so the plugins
* shouldn't be consider validated. Hence, we should validate the global
* parameters.
*/
export function buildGlobalParametersMap(
export function buildGlobalOptionsMap(
resolvedPlugins: HardhatPlugin[],
): GlobalParametersMap {
const globalParametersMap: GlobalParametersMap = new Map();
): GlobalOptionsMap {
const globalOptionsMap: GlobalOptionsMap = new Map();

for (const plugin of resolvedPlugins) {
if (plugin.globalParameters === undefined) {
if (plugin.globalOptions === undefined) {
continue;
}

for (const param of plugin.globalParameters) {
const existingByName = globalParametersMap.get(param.name);
for (const option of plugin.globalOptions) {
const existingByName = globalOptionsMap.get(option.name);
if (existingByName !== undefined) {
throw new HardhatError(
HardhatError.ERRORS.GENERAL.GLOBAL_PARAMETER_ALREADY_DEFINED,
HardhatError.ERRORS.GENERAL.GLOBAL_OPTION_ALREADY_DEFINED,
{
plugin: plugin.id,
globalParameter: param.name,
globalOption: option.name,
definedByPlugin: existingByName.pluginId,
},
);
}

const validatedGlobalParam = buildGlobalParameterDefinition(param);
const validatedGlobalOption = buildGlobalOptionDefinition(option);

const mapEntry = {
pluginId: plugin.id,
param: validatedGlobalParam,
option: validatedGlobalOption,
};

globalParametersMap.set(validatedGlobalParam.name, mapEntry);
globalOptionsMap.set(validatedGlobalOption.name, mapEntry);
}
}

return globalParametersMap;
return globalOptionsMap;
}

export function buildGlobalParameterDefinition<T extends ParameterType>({
export function buildGlobalOptionDefinition<T extends ParameterType>({
name,
description,
parameterType,
Expand All @@ -70,7 +70,7 @@ export function buildGlobalParameterDefinition<T extends ParameterType>({
description: string;
parameterType?: T;
defaultValue: ParameterTypeToValueType<T>;
}): GlobalParameter {
}): GlobalOption {
const type = parameterType ?? ParameterType.STRING;

if (!isValidParamNameCasing(name)) {
Expand Down Expand Up @@ -104,13 +104,13 @@ export function buildGlobalParameterDefinition<T extends ParameterType>({
};
}

export function resolveGlobalArguments(
userProvidedGlobalArguments: Partial<GlobalArguments>,
_globalParametersMap: GlobalParametersMap,
): GlobalArguments {
// TODO: Validate the userProvidedGlobalArguments and get the remaining ones
export function resolveGlobalOptions(
userProvidedGlobalOptions: Partial<GlobalOptions>,
_globalOptionsMap: GlobalOptionsMap,
): GlobalOptions {
// TODO: Validate the userProvidedGlobalOptions and get the remaining ones
// from env variables

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TODO
return userProvidedGlobalArguments as GlobalArguments;
return userProvidedGlobalOptions as GlobalOptions;
}
37 changes: 18 additions & 19 deletions v-next/core/src/internal/hre.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "../types/cli.js";
import type { HardhatUserConfig, HardhatConfig } from "../types/config.js";
import type {
GlobalArguments,
GlobalParametersMap,
} from "../types/global-parameters.js";
GlobalOptions,
GlobalOptionsMap,
} from "../types/global-options.js";
import type {
HardhatUserConfigValidationError,
HookContext,
Expand All @@ -16,9 +16,9 @@ import type { UserInterruptionManager } from "../types/user-interruptions.js";

import { ResolvedConfigurationVariableImplementation } from "./configuration-variables.js";
import {
buildGlobalParametersMap,
resolveGlobalArguments,
} from "./global-parameters.js";
buildGlobalOptionsMap,
resolveGlobalOptions,
} from "./global-options.js";
import { HookManagerImplementation } from "./hook-manager.js";
import { resolvePluginList } from "./plugins/resolve-plugin-list.js";
import { TaskManagerImplementation } from "./tasks/task-manager.js";
Expand All @@ -29,7 +29,7 @@ export class HardhatRuntimeEnvironmentImplementation
{
public static async create(
inputUserConfig: HardhatUserConfig,
userProvidedGlobalArguments: Partial<GlobalArguments>,
userProvidedGlobalOptions: Partial<GlobalOptions>,
unsafeOptions?: UnsafeHardhatRuntimeEnvironmentOptions,
): Promise<HardhatRuntimeEnvironmentImplementation> {
// TODO: Clone with lodash or https://github.com/davidmarkclements/rfdc
Expand Down Expand Up @@ -85,13 +85,12 @@ export class HardhatRuntimeEnvironmentImplementation
plugins: resolvedPlugins,
};

const globalParametersMap =
unsafeOptions?.globalParametersMap ??
buildGlobalParametersMap(resolvedPlugins);
const globalOptionsMap =
unsafeOptions?.globalOptionsMap ?? buildGlobalOptionsMap(resolvedPlugins);

const globalArguments = resolveGlobalArguments(
userProvidedGlobalArguments,
globalParametersMap,
const globalOptions = resolveGlobalOptions(
userProvidedGlobalOptions,
globalOptionsMap,
);

// Set the HookContext in the hook manager so that non-config hooks can
Expand All @@ -102,7 +101,7 @@ export class HardhatRuntimeEnvironmentImplementation
const hookContext: HookContext = {
hooks,
config,
globalArguments,
globalOptions,
interruptions,
};

Expand All @@ -113,8 +112,8 @@ export class HardhatRuntimeEnvironmentImplementation
config,
hooks,
interruptions,
globalArguments,
globalParametersMap,
globalOptions,
globalOptionsMap,
);

await hooks.runSequentialHandlers("hre", "created", [hre]);
Expand All @@ -129,10 +128,10 @@ export class HardhatRuntimeEnvironmentImplementation
public readonly config: HardhatConfig,
public readonly hooks: HookManager,
public readonly interruptions: UserInterruptionManager,
public readonly globalArguments: GlobalArguments,
globalParametersMap: GlobalParametersMap,
public readonly globalOptions: GlobalOptions,
globalOptionsMap: GlobalOptionsMap,
) {
this.tasks = new TaskManagerImplementation(this, globalParametersMap);
this.tasks = new TaskManagerImplementation(this, globalOptionsMap);
}
}

Expand Down
Loading
Loading