Skip to content

Commit

Permalink
Merge pull request #14 from ItsNickBarry/disambiguate
Browse files Browse the repository at this point in the history
Prevent ambiguous output, replace `disambiguatePaths` option with `flat` option
  • Loading branch information
ItsNickBarry authored Feb 6, 2023
2 parents ae6ef68 + 428fcc3 commit 0209ef0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ Add configuration under the `contractSizer` key:
|-|-|-|
| `alphaSort` | whether to sort results table alphabetically (default sort is by contract size) | `false`
| `runOnCompile` | whether to output contract sizes automatically after compilation | `false` |
| `disambiguatePaths` | whether to output the full path to the compilation artifact (relative to the Hardhat root directory) | `false` |
| `flat` | whether to hide the full path to the compilation artifact and output only the contract name | `false` |
| `strict` | whether to throw an error if any contracts exceed the size limit (may cause compatibility issues with `solidity-coverage`) | `false` |
| `only` | `Array` of `String` matchers used to select included contracts, defaults to all contracts if `length` is 0 | `[]` |
| `except` | `Array` of `String` matchers used to exclude contracts | `[]` |

```javascript
contractSizer: {
alphaSort: true,
disambiguatePaths: false,
runOnCompile: true,
flat: true,
strict: true,
only: [':ERC20$'],
}
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ declare module 'hardhat/types/config' {
interface HardhatUserConfig {
contractSizer?: {
alphaSort?: boolean,
disambiguatePaths?: boolean,
runOnCompile?: boolean,
flat?: boolean,
strict?: boolean,
only?: string[],
except?: string[],
Expand All @@ -15,8 +15,8 @@ declare module 'hardhat/types/config' {
interface HardhatConfig {
contractSizer: {
alphaSort: boolean,
disambiguatePaths: boolean,
runOnCompile: boolean,
flat: boolean,
strict: boolean
only: string[],
except: string[],
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extendConfig(function (config, userConfig) {
config.contractSizer = Object.assign(
{
alphaSort: false,
disambiguatePaths: false,
flat: false,
runOnCompile: false,
strict: false,
only: [],
Expand Down
11 changes: 10 additions & 1 deletion tasks/size_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ task(

outputData.push({
fullName,
displayName: config.disambiguatePaths ? fullName : fullName.split(':').pop(),
displayName: config.flat ? fullName.split(':').pop() : fullName,
size,
previousSize: previousSizes[fullName] || null,
});
}));

outputData.reduce(function (acc, { displayName }) {
if (acc.has(displayName)) {
throw new HardhatPluginError(`ambiguous contract name: ${ displayName }`);
}

acc.add(displayName);
return acc;
}, new Set());

if (config.alphaSort) {
outputData.sort((a, b) => a.displayName.toUpperCase() > b.displayName.toUpperCase() ? 1 : -1);
} else {
Expand Down

0 comments on commit 0209ef0

Please sign in to comment.