🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a 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.3.1

10

package.json
{
"name": "hardhat-contract-sizer",
"version": "2.3.0",
"version": "2.3.1",
"license": "MIT",

@@ -26,9 +26,9 @@ "description": "Output Solidity contract sizes with Hardhat",

"devDependencies": {
"hardhat": "^2.0.0",
"eslint": "^7.6.0"
"eslint": "^7.6.0",
"hardhat": "^2.0.0"
},
"dependencies": {
"cli-table3": "^0.6.0",
"colors": "^1.4.0"
"chalk": "^4.0.0",
"cli-table3": "^0.6.0"
}
}

@@ -48,7 +48,6 @@ # Hardhat Contract Sizer

By default, the hardhat `compile` task is run before sizing contracts. You can disable
this behavior by specifying `--no-compile` when you run the command:
By default, the hardhat `compile` task is run before sizing contracts. This behavior can be disabled with the `--no-compile` flag:
```bash
yarn run hardhat size-contracts --compile false
yarn run hardhat size-contracts --no-compile
```

@@ -1,23 +0,28 @@

const colors = require('colors/safe');
const chalk = require('chalk');
const Table = require('cli-table3');
const { HardhatPluginError } = require('hardhat/plugins');
const {
TASK_COMPILE,
} = require('hardhat/builtin-tasks/task-names');
const SIZE_LIMIT = 24576;
task('size-contracts', 'Output the size of compiled contracts')
.addFlag('noCompile', 'Don\'t compile before running this task')
.setAction(sizeContracts);
task(
'size-contracts', 'Output the size of compiled contracts'
).addFlag(
'noCompile', 'Don\'t compile before running this task'
).setAction(async function (args, hre) {
if (!args.noCompile) {
await hre.run(TASK_COMPILE, { noSizeContracts: true });
}
async function sizeContracts(args, hre) {
const config = hre.config.contractSizer;
if (!args.noCompile) {
await hre.run('compile', { noSizeContracts: true });
}
const outputData = [];
const contracts = [];
const fullNames = await hre.artifacts.getAllFullyQualifiedNames();
for (let fullName of await hre.artifacts.getAllFullyQualifiedNames()) {
if (config.only.length && !config.only.some(m => fullName.match(m))) continue;
if (config.except.length && config.except.some(m => fullName.match(m))) continue;
await Promise.all(fullNames.map(async function (fullName) {
if (config.only.length && !config.only.some(m => fullName.match(m))) return;
if (config.except.length && config.except.some(m => fullName.match(m))) return;

@@ -34,13 +39,13 @@ const { deployedBytecode } = await hre.artifacts.readArtifact(fullName);

contracts.push({ name: fullName, size });
}
outputData.push({ name: fullName, size });
}));
if (config.alphaSort) {
contracts.sort((a, b) => a.name.toUpperCase() > b.name.toUpperCase() ? 1 : -1);
outputData.sort((a, b) => a.name.toUpperCase() > b.name.toUpperCase() ? 1 : -1);
} else {
contracts.sort((a, b) => a.size - b.size);
outputData.sort((a, b) => a.size - b.size);
}
const table = new Table({
head: [colors.bold('Contract Name'), 'Size (KB)'],
head: [chalk.bold('Contract Name'), chalk.bold('Size (KB)')],
style: { head: [], border: [], 'padding-left': 2, 'padding-right': 2 },

@@ -67,18 +72,18 @@ chars: {

for (let contract of contracts) {
if (!contract.size) {
for (let item of outputData) {
if (!item.size) {
continue;
}
let size = (contract.size / 1000).toFixed(3);
let size = (item.size / 1000).toFixed(3);
if (contract.size > SIZE_LIMIT) {
size = colors.red.bold(size);
if (item.size > SIZE_LIMIT) {
size = chalk.red.bold(size);
largeContracts++;
} else if (contract.size > SIZE_LIMIT * 0.9) {
size = colors.yellow.bold(size);
} else if (item.size > SIZE_LIMIT * 0.9) {
size = chalk.yellow.bold(size);
}
table.push([
{ content: contract.name },
{ content: item.name },
{ content: size, hAlign: 'right' },

@@ -98,5 +103,5 @@ ]);

} else {
console.log(colors.red(message));
console.log(chalk.red(message));
}
}
}
});