diff --git a/.changeset/tender-beers-visit.md b/.changeset/tender-beers-visit.md new file mode 100644 index 0000000000..a0838696fe --- /dev/null +++ b/.changeset/tender-beers-visit.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Print warning when user tries to use solc remapping (#1877) diff --git a/packages/hardhat-core/src/internal/core/config/config-loading.ts b/packages/hardhat-core/src/internal/core/config/config-loading.ts index 607ce2ba40..c43ee1b556 100644 --- a/packages/hardhat-core/src/internal/core/config/config-loading.ts +++ b/packages/hardhat-core/src/internal/core/config/config-loading.ts @@ -92,6 +92,7 @@ export function loadConfigAndTasks( if (showSolidityConfigWarnings) { checkUnsupportedSolidityConfig(resolved); + checkUnsupportedRemappings(resolved); } return resolved; @@ -223,7 +224,7 @@ function checkMissingSolidityConfig(userConfig: any) { if (userConfig.solidity === undefined) { console.warn( chalk.yellow( - `Solidity compiler is not configured. Version ${DEFAULT_SOLC_VERSION} will be used by default. Add a 'solidity' entry to your configuration to supress this warning. + `Solidity compiler is not configured. Version ${DEFAULT_SOLC_VERSION} will be used by default. Add a 'solidity' entry to your configuration to suppress this warning. Learn more about compiler configuration at https://hardhat.org/config" ` @@ -261,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 +` + ) + ); + } +} diff --git a/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-list.js b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-list.js new file mode 100644 index 0000000000..5d3c4e67ef --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-list.js @@ -0,0 +1,15 @@ +module.exports = { + solidity: { + compilers: [ + { + version: "0.7.0", + settings: { + remappings: [":g=/dir"], + }, + }, + ], + overrides: { + "contracts/Foo.sol": { version: "0.7.0" }, + }, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-override.js b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-override.js new file mode 100644 index 0000000000..9d0db7e786 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-override.js @@ -0,0 +1,17 @@ +module.exports = { + solidity: { + compilers: [ + { + version: "0.7.0", + }, + ], + overrides: { + "contracts/Foo.sol": { + version: "0.7.0", + settings: { + remappings: [":g=/dir"], + }, + }, + }, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-settings.js b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-settings.js new file mode 100644 index 0000000000..e27dc9422a --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/solidity-config-warnings/remapping-in-settings.js @@ -0,0 +1,8 @@ +module.exports = { + solidity: { + version: "0.7.0", + settings: { + remappings: [":g=/dir"], + }, + }, +}; diff --git a/packages/hardhat-core/test/internal/core/config/config-loading.ts b/packages/hardhat-core/test/internal/core/config/config-loading.ts index 9076b038b3..24cbf74ead 100644 --- a/packages/hardhat-core/test/internal/core/config/config-loading.ts +++ b/packages/hardhat-core/test/internal/core/config/config-loading.ts @@ -423,5 +423,50 @@ Hardhat plugin instead.` assert.equal(consoleWarnStub.callCount, 1); assert.include(consoleWarnStub.args[0][0], "is not fully supported yet"); }); + + it("should emit a warning if there is a remapping in the compiler settings", function () { + loadConfigAndTasks( + { + config: "remapping-in-settings.js", + }, + { showSolidityConfigWarnings: true } + ); + + assert.equal(consoleWarnStub.callCount, 1); + assert.include( + consoleWarnStub.args[0][0], + "remappings are not currently supported" + ); + }); + + it("should emit a warning if there is a remapping in the list of compiler settings", function () { + loadConfigAndTasks( + { + config: "remapping-in-list.js", + }, + { showSolidityConfigWarnings: true } + ); + + assert.equal(consoleWarnStub.callCount, 1); + assert.include( + consoleWarnStub.args[0][0], + "remappings are not currently supported" + ); + }); + + it("should emit a warning if there is a remapping in the list of compiler overrides", function () { + loadConfigAndTasks( + { + config: "remapping-in-override.js", + }, + { showSolidityConfigWarnings: true } + ); + + assert.equal(consoleWarnStub.callCount, 1); + assert.include( + consoleWarnStub.args[0][0], + "remappings are not currently supported" + ); + }); }); });