Skip to content

Commit 665a755

Browse files
committed
Parse only env vars
1 parent 22abbd5 commit 665a755

File tree

2 files changed

+14
-39
lines changed

2 files changed

+14
-39
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,21 @@ export function resolveGlobalOptions(
145145
-- GlobalOptions is empty for user extension, so we need to cast it to
146146
assign the value. */
147147
(userProvidedGlobalOptions as Record<string, string | undefined>)[name];
148-
if (value === undefined) {
149-
value = process.env[`HARDHAT_${camelToSnakeCase(name).toUpperCase()}`];
150-
}
151148

152149
let parsedValue: ParameterValue;
150+
// if the value is provided in the user options, it's already parsed
151+
// and it takes precedence over env vars
153152
if (value !== undefined) {
154-
parsedValue = parseParameterValue(value, option.parameterType, name);
153+
parsedValue = value;
155154
} else {
156-
parsedValue = option.defaultValue;
155+
value = process.env[`HARDHAT_${camelToSnakeCase(name).toUpperCase()}`];
156+
if (value !== undefined) {
157+
// if the value is provided via an env var, it needs to be parsed
158+
parsedValue = parseParameterValue(value, option.parameterType, name);
159+
} else {
160+
// if the value is not provided by the user or env var, use the default
161+
parsedValue = option.defaultValue;
162+
}
157163
}
158164

159165
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions

v-next/core/test/internal/global-options.ts

+3-34
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe("Global Options", () => {
303303

304304
const globalOptions = resolveGlobalOptions(
305305
{
306-
param1: "false",
306+
param1: false,
307307
param2: "user",
308308
},
309309
globalOptionsMap,
@@ -340,7 +340,7 @@ describe("Global Options", () => {
340340

341341
const globalOptions = resolveGlobalOptions(
342342
{
343-
param1: "false",
343+
param1: false,
344344
param2: "user",
345345
},
346346
globalOptionsMap,
@@ -371,7 +371,7 @@ describe("Global Options", () => {
371371

372372
const globalOptions = resolveGlobalOptions(
373373
{
374-
param1: "false",
374+
param1: false,
375375
param2: "user",
376376
},
377377
globalOptionsMap,
@@ -382,37 +382,6 @@ describe("Global Options", () => {
382382
});
383383
});
384384

385-
it("should throw if the provided option is not valid", () => {
386-
const globalOptionsMap = buildGlobalOptionsMap([
387-
{
388-
id: "plugin1",
389-
globalOptions: [
390-
buildGlobalOptionDefinition({
391-
name: "param1",
392-
description: "param1 description",
393-
parameterType: ParameterType.BOOLEAN,
394-
defaultValue: true,
395-
}),
396-
],
397-
},
398-
]);
399-
400-
assert.throws(
401-
() =>
402-
resolveGlobalOptions(
403-
{
404-
param1: "not a boolean",
405-
},
406-
globalOptionsMap,
407-
),
408-
new HardhatError(HardhatError.ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
409-
value: "not a boolean",
410-
name: "param1",
411-
type: ParameterType.BOOLEAN,
412-
}),
413-
);
414-
});
415-
416385
it("should throw if the environment variable is not valid", () => {
417386
const globalOptionsMap = buildGlobalOptionsMap([
418387
{

0 commit comments

Comments
 (0)