Skip to content

Commit

Permalink
fix: use colorette instead of turbocolor rollup#3391
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuever committed May 29, 2021
1 parent 184eb60 commit 8ea05d2
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions scripts/perf.js
Expand Up @@ -2,8 +2,8 @@

const fs = require('fs');
const path = require('path');
const colorette = require('colorette');
const prettyBytes = require('pretty-bytes');
const tc = require('turbocolor');
const rollup = require('../dist/rollup.js');
const { loadPerfConfig, targetDir } = require('./load-perf-config');

Expand All @@ -27,10 +27,10 @@ if (!(numberOfDiscardedResults >= 0) || !(numberOfDiscardedResults < numberOfRun
process.exit(1);
}
console.info(
tc.bold(
`Calculating the average of ${tc.cyan(numberOfRunsToAverage)} runs discarding the ${tc.cyan(
numberOfDiscardedResults
)} largest results.\n`
colorette.bold(
`Calculating the average of ${colorette.cyan(
numberOfRunsToAverage
)} runs discarding the ${colorette.cyan(numberOfDiscardedResults)} largest results.\n`
) + 'Run "npm run perf <number of runs> <number of discarded results>" to change that.'
);

Expand Down Expand Up @@ -111,9 +111,9 @@ function printMeasurements(average, existingAverage, filter = /.*/) {
printedLabels.forEach(label => {
let color = text => text;
if (label[0] === '#') {
color = tc.bold;
color = colorette.bold;
if (label[1] !== '#') {
color = tc.underline;
color = colorette.underline;
}
}
console.info(
Expand All @@ -139,7 +139,9 @@ function getExistingTimings() {
try {
const timings = JSON.parse(fs.readFileSync(perfFile, 'utf8'));
console.info(
tc.bold(`Comparing with ${tc.cyan(perfFile)}. Delete this file to create a new base line.`)
colorette.bold(
`Comparing with ${colorette.cyan(perfFile)}. Delete this file to create a new base line.`
)
);
return timings;
} catch (e) {
Expand All @@ -151,10 +153,14 @@ function persistTimings(timings) {
try {
fs.writeFileSync(perfFile, JSON.stringify(timings, null, 2), 'utf8');
console.info(
tc.bold(`Saving performance information to new reference file ${tc.cyan(perfFile)}.`)
colorette.bold(
`Saving performance information to new reference file ${colorette.cyan(perfFile)}.`
)
);
} catch (e) {
console.error(tc.bold(`Could not persist performance information in ${tc.cyan(perfFile)}.`));
console.error(
colorette.bold(`Could not persist performance information in ${colorette.cyan(perfFile)}.`)
);
process.exit(1);
}
}
Expand All @@ -173,7 +179,7 @@ function getFormattedTime(currentTime, persistedTime = currentTime) {
0
)}ms, ${sign}${relativeDeviation.toFixed(1)}%)`;
if (relativeDeviation > RELATIVE_DEVIATION_FOR_COLORING) {
color = currentTime >= persistedTime ? tc.red : tc.green;
color = currentTime >= persistedTime ? colorette.red : colorette.green;
}
}
return color(formattedTime);
Expand All @@ -187,7 +193,7 @@ function getFormattedMemory(currentMemory, persistedMemory = currentMemory) {
const relativeDeviation = 100 * (absoluteDeviation / persistedMemory);
if (relativeDeviation > RELATIVE_DEVIATION_FOR_COLORING) {
formattedMemory += ` (${sign}${relativeDeviation.toFixed(0)}%)`;
color = currentMemory >= persistedMemory ? tc.red : tc.green;
color = currentMemory >= persistedMemory ? colorette.red : colorette.green;
}
return color(formattedMemory);
}
Expand Down

0 comments on commit 8ea05d2

Please sign in to comment.