Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Distribution File Sizes', function (t) {
let filepath = require('path').resolve('./test/lib/ngn.min.js')
let stats = require('fs').statSync(filepath)
let uncompressedSize = (stats.size / 1000).toFixed(2)
t.ok(uncompressedSize < 100, 'Uncompressed distributable file is under 100kb (' + (stats.size / 1000) + 'kb).')
let compressedSize = (gzip.fileSync(filepath, { level: 9 }) / 1000).toFixed(2)
t.ok(compressedSize < 30, 'Compressed (minified) distributable is under 30kb (' + compressedSize + 'kb)')
t.end()
})
readDirs(path.resolve('./lib-out/'), async (filepath, filename) => {
try {
console.log(chalk.greenBright(`> ${filename}: ${bytes(gzipSize.fileSync(filepath))}`))
} catch (err) {
console.error(err)
}
}, (err) => {
console.error(err)
return glob.sync(pattern).reduce((total, path) => {
return total + gzipSize.fileSync(path)
}, 0)
}
.reduce((acc, file) => acc + fileSync(resolve(path, file)), 0);
}
.forEach(f => {
const path = `./dist/${f}`;
table.push([
f,
toKb(fs.statSync(path).size),
toKb(gzipSize.fileSync(path))
]);
});
function analyzeStylesheet( inputCSSFile, outputJSONFile ) {
if ( ! existsSync( inputCSSFile ) ) {
return;
}
const parsedSize = statSync( inputCSSFile ).size;
const gzipSize = gzip.fileSync( inputCSSFile );
const hash = hashFile( inputCSSFile );
const styleStats = { statSize: parsedSize, parsedSize, gzipSize, hash };
writeFileSync( outputJSONFile, JSON.stringify( styleStats, null, 2 ) );
}
get size() {
let sizes = {
size: new Number(statSync(this.path).size),
zipped: new Number(gzipSize.fileSync(this.path)),
};
function bytesToString() {
let value = parseInt(Number.prototype.toString.call(this));
return prettyBytes(value);
}
sizes.size.toString = bytesToString;
sizes.zipped.toString = bytesToString;
return sizes;
}
module.exports = function fileSize(file) {
let stats = fs.statSync(file);
if (stats.isDirectory()) {
return fs.readdirSync(file)
.map((child) => path.join(file, child))
.filter((child) => fs.statSync(child).isFile())
.map((child) => fileSize(child))
.join('\n');
}
let size = fs.statSync(file).size;
let gzip = gzipSize.fileSync(file);
return `${path.relative(process.cwd(), file)} ${colors.grey(`(${prettyByte(size)}, ${prettyByte(gzip)} zipped)`)}`;
};