Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use colorette instead of turbocolor #3391 #4114

Merged
merged 1 commit into from May 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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