🚀 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.5.0

2

package.json
{
"name": "hardhat-contract-sizer",
"version": "2.4.0",
"version": "2.5.0",
"license": "MIT",

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

@@ -0,1 +1,3 @@

const fs = require('fs');
const path = require('path');
const chalk = require('chalk');

@@ -10,2 +12,6 @@ const Table = require('cli-table3');

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

@@ -26,2 +32,17 @@ 'size-contracts', 'Output the size of compiled contracts'

const outputPath = path.resolve(
hre.config.paths.cache,
'.hardhat_contract_sizer_output.json'
);
const previousSizes = {};
if (fs.existsSync(outputPath)) {
const previousOutput = await fs.promises.readFile(outputPath);
JSON.parse(previousOutput).forEach(function (el) {
previousSizes[el.fullName] = el.size;
});
}
await Promise.all(fullNames.map(async function (fullName) {

@@ -37,11 +58,12 @@ if (config.only.length && !config.only.some(m => fullName.match(m))) return;

if (!config.disambiguatePaths) {
fullName = fullName.split(':').pop();
}
outputData.push({ name: fullName, size });
outputData.push({
fullName,
displayName: config.disambiguatePaths ? fullName : fullName.split(':').pop(),
size,
previousSize: previousSizes[fullName] || null,
});
}));
if (config.alphaSort) {
outputData.sort((a, b) => a.name.toUpperCase() > b.name.toUpperCase() ? 1 : -1);
outputData.sort((a, b) => a.displayName.toUpperCase() > b.displayName.toUpperCase() ? 1 : -1);
} else {

@@ -51,4 +73,6 @@ outputData.sort((a, b) => a.size - b.size);

await fs.promises.writeFile(outputPath, JSON.stringify(outputData), { flag: 'w' });
const table = new Table({
head: [chalk.bold('Contract Name'), chalk.bold('Size (KB)')],
head: [chalk.bold('Contract Name'), chalk.bold('Size (KB)'), chalk.bold('Change (KB)')],
style: { head: [], border: [], 'padding-left': 2, 'padding-right': 2 },

@@ -80,3 +104,3 @@ chars: {

let size = (item.size / 1000).toFixed(3);
let size = formatSize(item.size);

@@ -90,5 +114,18 @@ if (item.size > SIZE_LIMIT) {

let diff;
if (item.size < item.previousSize) {
diff = chalk.green(formatSize(item.previousSize - item.size));
} else if (item.size > item.previousSize) {
diff = chalk.red(formatSize(item.size - item.previousSize));
} else {
diff = '';
}
table.push([
{ content: item.name },
{ content: item.displayName },
{ content: size, hAlign: 'right' },
{ content: diff, hAlign: 'right' },
]);

@@ -95,0 +132,0 @@ }