🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

css-dedup

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-dedup - npm Package Compare versions

Comparing version
1.4.0
to
1.4.1
+37
-12
bin/css-dedup.js

@@ -227,3 +227,3 @@ #!/usr/bin/env node

// growth—against the run’s combined original size, spelled out as the
// literal “for overall ±N bytes / ±P%” the summary bullets quote in
// literal “total: ±N bytes / ±P%” the summary bullets quote in
// parentheses

@@ -233,5 +233,12 @@ function formatOverallNet(net, totalBefore) {

const sign = net >= 0 ? '-' : '+';
return `for overall ${sign}${Math.abs(net).toLocaleString()} bytes / ${sign}${percent.toFixed(1)}%`;
return `total: ${sign}${Math.abs(net).toLocaleString()} bytes / ${sign}${percent.toFixed(1)}%`;
}
// Appended to an `--aggressive` bullet: what its own delta adds up to once
// combined with the base bullet printed just above—without this, a reader
// has to add the two bullets themselves to know where they’d land together
function formatAggregateTotalNote(totalSaved, before) {
return ` (${formatOverallNet(totalSaved, before)})`;
}
// The one outcome bullet the all-files summary prints twice—once for the

@@ -247,3 +254,9 @@ // base count, once for what `--aggressive` adds—covering its three possible

// are additional on top of the base bullet printed just above.
function formatOutcomeBullet({ countLabel, tense, filesShrinkLen, shrinkTotal, filesGrowLen, growTotal, totalBefore, flag, skipFlag, more = false }) {
// `aggregateNote`—passed by the `--aggressive` caller as a pre-formatted
// `formatAggregateTotalNote()` string, against the whole run rather than
// just the files aggressive affects—is appended to every shape, replacing
// the mixed shape’s own “(total: …)” net (just its own two figures) rather
// than sitting alongside it: Two differently-scoped nets both labeled
// “total:” back to back would read as a contradiction.
function formatOutcomeBullet({ countLabel, tense, filesShrinkLen, shrinkTotal, filesGrowLen, growTotal, totalBefore, flag, skipFlag, more = false, aggregateNote = '' }) {
const s = n => n !== 1 ? 's' : '';

@@ -255,3 +268,3 @@ const reduce = tense === 'done' ? 'Reduced' : 'Reduce';

const saved = tense === 'done' ? 'saved' : 'save';
return [`* ${countLabel}: ${reduce} duplication and ${saved} ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })}${flagClause}`];
return [`* ${countLabel}: ${reduce} duplication and ${saved} ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })}${flagClause}${aggregateNote}`];
}

@@ -261,6 +274,7 @@ if (!filesShrinkLen && filesGrowLen) {

const conjunction = tense === 'done' ? 'and' : 'but';
return [`* ${countLabel}: ${reduce} duplication ${conjunction} ${grew} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })}${flagClause}`];
return [`* ${countLabel}: ${reduce} duplication ${conjunction} ${grew} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })}${flagClause}${aggregateNote}`];
}
if (filesShrinkLen && filesGrowLen) {
const net = shrinkTotal - growTotal;
const netNote = aggregateNote || ` (${formatOverallNet(net, totalBefore)})`;
if (tense === 'done') {

@@ -270,6 +284,6 @@ // A gerund list, not “and shrink … but grow …”: `--fix` already

// to draw—just what happened, itemized
const first = `* ${countLabel}: Reduced duplication, shrinking ${filesShrinkLen} file${s(filesShrinkLen)} by ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })} and growing ${filesGrowLen} file${s(filesGrowLen)} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })} (${formatOverallNet(net, totalBefore)})`;
const first = `* ${countLabel}: Reduced duplication, shrinking ${filesShrinkLen} file${s(filesShrinkLen)} by ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })} and growing ${filesGrowLen} file${s(filesGrowLen)} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })}${netNote}`;
return [first];
}
const first = `* ${countLabel}: Reduce duplication and shrink ${filesShrinkLen} file${s(filesShrinkLen)} by ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })} but grow ${filesGrowLen} file${s(filesGrowLen)} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })}${flagClause} (${formatOverallNet(net, totalBefore)})`;
const first = `* ${countLabel}: Reduce duplication and shrink ${filesShrinkLen} file${s(filesShrinkLen)} by ${formatByteMagnitude(shrinkTotal, totalBefore, '-', { more })} but grow ${filesGrowLen} file${s(filesGrowLen)} by ${formatByteMagnitude(growTotal, totalBefore, '+', { more })}${flagClause}${netNote}`;
const second = ` - Skip files that grow in size to save ${formatByteMagnitude(shrinkTotal, totalBefore, '-')} in total with \`${skipFlag}\``;

@@ -297,5 +311,9 @@ return [first, second];

// mode—always still-hypothetical, so always `formatReduceClause()`’s
// present-tense phrasing even inside a `--fix` run
function formatAggressivePreviewLine(aggExtra, aggExtraSaved, before) {
return `* ${aggExtra > 0 ? `${aggExtra} more finding${aggExtra !== 1 ? 's' : ''}` : 'Further consolidation'} in aggressive mode: ${formatReduceClause(aggExtraSaved, before, true)} with \`--fix --aggressive\``;
// present-tense phrasing even inside a `--fix` run. `baseSaved` is the base
// `--fix` bullet’s own outcome, needed only to spell out the combined total
// in the trailing note—the bullet’s main clause still quotes `aggExtraSaved`
// on its own.
function formatAggressivePreviewLine(aggExtra, aggExtraSaved, before, baseSaved) {
const label = aggExtra > 0 ? `${aggExtra} more finding${aggExtra !== 1 ? 's' : ''}` : 'Further consolidation';
return `* ${label} in aggressive mode: ${formatReduceClause(aggExtraSaved, before, true)} with \`--fix --aggressive\`${formatAggregateTotalNote(baseSaved + aggExtraSaved, before)}`;
}

@@ -540,3 +558,3 @@

const { aggExtra, aggExtraSaved, aggDiffers } = computeAggressivePreview(potential, output, applied, bytes);
if (aggDiffers) log(formatAggressivePreviewLine(aggExtra, aggExtraSaved, bytes.before));
if (aggDiffers) log(formatAggressivePreviewLine(aggExtra, aggExtraSaved, bytes.before, bytes.saved));

@@ -606,3 +624,3 @@ return {

const { aggExtra, aggExtraSaved, aggDiffers } = computeAggressivePreview(potential, cssDryRun, applied, bytes);
if (aggDiffers) console.log(formatAggressivePreviewLine(aggExtra, aggExtraSaved, bytes.before));
if (aggDiffers) console.log(formatAggressivePreviewLine(aggExtra, aggExtraSaved, bytes.before, bytes.saved));

@@ -657,2 +675,8 @@ return {

const aggGrowTotal = Math.abs(sumBy(aggFilesGrow, result => result.stats.aggExtraSaved));
// What every file’s outcome adds up to if `--fix --aggressive` ran across
// the whole set, for the aggressive bullet’s trailing total note—the
// base run’s own net plus what aggressive adds on top, each already
// computed above (`aggExtraSaved` is 0 for a file aggressive doesn’t
// affect, so `aggShrinkTotal - aggGrowTotal` already nets to 0 there)
const aggNetAll = (shrinkTotal - growTotal) + (aggShrinkTotal - aggGrowTotal);

@@ -721,2 +745,3 @@ console.log(styleText('bold', `Summary for all files:${erroredNote}`));

more: true,
aggregateNote: formatAggregateTotalNote(aggNetAll, totalBeforeAll),
});

@@ -723,0 +748,0 @@ if (aggOutcome) {

@@ -64,3 +64,3 @@ {

"types": "src/index.d.ts",
"version": "1.4.0"
"version": "1.4.1"
}