🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

hardhat-contract-sizer

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat-contract-sizer - npm Package Compare versions

Comparing version

to
2.9.0

38

index.d.ts

@@ -1,14 +0,15 @@

import 'hardhat/types/config';
import "hardhat/types/config";
declare module 'hardhat/types/config' {
declare module "hardhat/types/config" {
interface HardhatUserConfig {
contractSizer?: {
alphaSort?: boolean,
disambiguatePaths?: boolean,
runOnCompile?: boolean,
strict?: boolean,
only?: string[],
except?: string[],
outputFile?: string,
}
alphaSort?: boolean;
disambiguatePaths?: boolean;
runOnCompile?: boolean;
strict?: boolean;
only?: string[];
except?: string[];
outputFile?: string;
unit?: 'B' | 'kB' | 'KiB';
};
}

@@ -18,11 +19,12 @@

contractSizer: {
alphaSort: boolean,
disambiguatePaths: boolean,
runOnCompile: boolean,
strict: boolean
only: string[],
except: string[],
outputFile: string
}
alphaSort: boolean;
disambiguatePaths: boolean;
runOnCompile: boolean;
strict: boolean;
only: string[];
except: string[];
outputFile: string;
unit: 'B' | 'kB' | 'KiB';
};
}
}

@@ -16,2 +16,3 @@ const { extendConfig } = require('hardhat/config');

outputFile: null,
unit: 'KiB',
},

@@ -18,0 +19,0 @@ userConfig.contractSizer

{
"name": "hardhat-contract-sizer",
"version": "2.8.0",
"version": "2.9.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Output Solidity contract sizes with Hardhat",

@@ -20,3 +20,3 @@ # Hardhat Contract Sizer

```javascript
require('hardhat-contract-sizer');
require("hardhat-contract-sizer");
```

@@ -26,11 +26,12 @@

| option | description | default |
|-|-|-|
| `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` |
| `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 | `[]` |
| `outputFile` | file path to write contract size report | `null` |
| option | description | default |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------- |
| `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` |
| `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 | `[]` |
| `outputFile` | file path to write contract size report | `null` |
| `unit` | unit of measurement for the size of contracts, which can be expressed in 'B' (bytes), 'kB' (kilobytes) or 'KiB' (kibibytes) | `KiB` |

@@ -55,3 +56,3 @@ ```javascript

By default, the hardhat `compile` task is run before sizing contracts. This behavior can be disabled with the `--no-compile` flag:
By default, the hardhat `compile` task is run before sizing contracts. This behavior can be disabled with the `--no-compile` flag:

@@ -58,0 +59,0 @@ ```bash

@@ -11,8 +11,2 @@ const fs = require('fs');

const SIZE_LIMIT = 24576;
const formatSize = function (size) {
return (size / 1024).toFixed(3);
};
task(

@@ -29,2 +23,14 @@ 'size-contracts', 'Output the size of compiled contracts'

// TODO: avoid hardcoding unit names
if (!['B', 'kB', 'KiB'].includes(config.unit)) {
throw new HardhatPluginError(`Invalid unit: ${ config.unit }`);
}
const SIZE_LIMIT = 24576;
const formatSize = function (size) {
const divisor = { 'B': 1, 'kB': 1000, 'KiB': 1024 }[config.unit];
return (size / divisor).toFixed(3);
};
const outputData = [];

@@ -99,9 +105,9 @@

{
content: chalk.gray(`Solc version: ${ compiler.version }`),
content: chalk.gray(`Solc version: ${compiler.version}`),
},
{
content: chalk.gray(`Optimizer enabled: ${ compiler.settings.optimizer.enabled }`),
content: chalk.gray(`Optimizer enabled: ${compiler.settings.optimizer.enabled}`),
},
{
content: chalk.gray(`Runs: ${ compiler.settings.optimizer.runs }`),
content: chalk.gray(`Runs: ${compiler.settings.optimizer.runs}`),
},

@@ -115,6 +121,6 @@ ]);

{
content: chalk.bold('Size (KiB)'),
content: chalk.bold(`Size (${config.unit})`),
},
{
content: chalk.bold('Change (KiB)'),
content: chalk.bold(`Change (${config.unit})`),
},

@@ -143,5 +149,5 @@ ]);

if (item.size < item.previousSize) {
diff = chalk.green(`-${ formatSize(item.previousSize - item.size) }`);
diff = chalk.green(`-${formatSize(item.previousSize - item.size)}`);
} else if (item.size > item.previousSize) {
diff = chalk.red(`+${ formatSize(item.size - item.previousSize) }`);
diff = chalk.red(`+${formatSize(item.size - item.previousSize)}`);
} else {

@@ -161,3 +167,3 @@ diff = chalk.yellow(formatSize(0));

if (config.outputFile)
fs.writeFileSync(config.outputFile, `${ stripAnsi(table.toString()) }\n`);
fs.writeFileSync(config.outputFile, `${stripAnsi(table.toString())}\n`);

@@ -167,3 +173,3 @@ if (oversizedContracts > 0) {

const message = `Warning: ${ oversizedContracts } contracts exceed the size limit for mainnet deployment (${ formatSize(SIZE_LIMIT)} KiB).`;
const message = `Warning: ${oversizedContracts} contracts exceed the size limit for mainnet deployment (${formatSize(SIZE_LIMIT)} ${config.unit}).`;

@@ -170,0 +176,0 @@ if (config.strict) {