Skip to content

Commit

Permalink
refactor for resolved config
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Nov 8, 2021
1 parent b58a776 commit 33354e2
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions packages/hardhat-core/src/internal/core/config/config-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import path from "path";
import semver from "semver";
import type StackTraceParserT from "stacktrace-parser";

import {
HardhatArguments,
HardhatConfig,
HardhatUserConfig,
} from "../../../types";
import { HardhatArguments, HardhatConfig } from "../../../types";
import { HardhatContext } from "../../context";
import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "../../hardhat-network/stack-traces/solidityTracer";
import { findClosestPackageJson } from "../../util/packageInfo";
Expand Down Expand Up @@ -81,7 +77,6 @@ export function loadConfigAndTasks(

if (showSolidityConfigWarnings) {
checkMissingSolidityConfig(userConfig);
checkUnsupportedRemappings(userConfig);
}

// To avoid bad practices we remove the previously exported stuff
Expand All @@ -97,6 +92,7 @@ export function loadConfigAndTasks(

if (showSolidityConfigWarnings) {
checkUnsupportedSolidityConfig(resolved);
checkUnsupportedRemappings(resolved);
}

return resolved;
Expand Down Expand Up @@ -237,36 +233,6 @@ Learn more about compiler configuration at https://hardhat.org/config"
}
}

function checkUnsupportedRemappings(userConfig: HardhatUserConfig) {
if (typeof userConfig.solidity === "object") {
let remappings: boolean;
if ("compilers" in userConfig.solidity) {
remappings =
[
...userConfig.solidity.compilers.filter(
({ settings }) => settings?.remappings !== undefined
),
...Object.values(userConfig.solidity.overrides || {}).filter(
({ settings }) => settings?.remappings !== undefined
),
].length > 0;
} else {
remappings = userConfig.solidity.settings?.remappings !== undefined;
}

if (remappings) {
console.warn(
chalk.yellow(
`Solidity remappings are not currently supported; you may experience unexpected compilation results. Remove any 'remappings' fields from your configuration to suppress this warning.
Learn more about compiler configuration at https://hardhat.org/config
`
)
);
}
}
}

function checkUnsupportedSolidityConfig(resolvedConfig: HardhatConfig) {
const compilerVersions = resolvedConfig.solidity.compilers.map(
(x) => x.version
Expand Down Expand Up @@ -296,3 +262,24 @@ Learn more at https://hardhat.org/reference/solidity-support
);
}
}

function checkUnsupportedRemappings({ solidity }: HardhatConfig) {
const solcConfigs = [
...solidity.compilers,
...Object.values(solidity.overrides),
];
const remappings = solcConfigs.filter(
({ settings }) => settings.remappings !== undefined
);

if (remappings.length > 0) {
console.warn(
chalk.yellow(
`Solidity remappings are not currently supported; you may experience unexpected compilation results. Remove any 'remappings' fields from your configuration to suppress this warning.
Learn more about compiler configuration at https://hardhat.org/config
`
)
);
}
}

0 comments on commit 33354e2

Please sign in to comment.