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

Prevent ambiguous output, replace disambiguatePaths option with flat option #14

Merged
merged 6 commits into from
Feb 6, 2023
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
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