Skip to content

Commit

Permalink
Switch to colorette instead of turbocolor
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 18, 2020
1 parent d10c385 commit f0ff869
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 76 deletions.
42 changes: 15 additions & 27 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ Repository: git+https://github.com/paulmillr/chokidar.git
---------------------------------------

## colorette
License: MIT
By: Jorge Bucaran
Repository: git+https://github.com/jorgebucaran/colorette.git

> Copyright © Jorge Bucaran <<https://jorgebucaran.com>>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## date-time
License: MIT
By: Sindre Sorhus
Expand Down Expand Up @@ -718,30 +733,3 @@ Repository: git+https://github.com/micromatch/to-regex-range.git
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
---------------------------------------

## turbocolor
License: MIT
By: Jorge Bucaran
Repository: git+https://github.com/jorgebucaran/turbocolor.git

> Copyright © 2015-present [Jorge Bucaran](https://github.com/jorgebucaran)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
12 changes: 6 additions & 6 deletions cli/logging.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import tc from 'turbocolor';
import color from 'colorette';
import { RollupError } from '../src/rollup/types';
import relativeId from '../src/utils/relativeId';

// @see https://no-color.org
// @see https://www.npmjs.com/package/chalk
if (process.env.FORCE_COLOR === '0' || process.env.NO_COLOR) {
tc.enabled = false;
color.options.enabled = false;
}

// log to stderr to keep `rollup main.js > bundle.js` from breaking
Expand All @@ -19,10 +19,10 @@ export function handleError(err: RollupError, recover = false) {
? `(plugin ${(err).plugin}) ${description}`
: description) || err;

stderr(tc.bold.red(`[!] ${tc.bold(message.toString())}`));
stderr(color.bold(color.red(`[!] ${color.bold(message.toString())}`)));

if (err.url) {
stderr(tc.cyan(err.url));
stderr(color.cyan(err.url));
}

if (err.loc) {
Expand All @@ -32,11 +32,11 @@ export function handleError(err: RollupError, recover = false) {
}

if (err.frame) {
stderr(tc.dim(err.frame));
stderr(color.dim(err.frame));
}

if (err.stack) {
stderr(tc.dim(err.stack));
stderr(color.dim(err.stack));
}

stderr('');
Expand Down
26 changes: 13 additions & 13 deletions cli/run/batchWarnings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tc from 'turbocolor';
import color from 'colorette';
import { RollupWarning } from '../../src/rollup/types';
import relativeId from '../../src/utils/relativeId';
import { stderr } from '../logging';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function batchWarnings() {
? `${relativeId(id)}: (${warning.loc.line}:${warning.loc.column})`
: relativeId(id);

stderr(tc.bold(relativeId(loc)));
stderr(color.bold(relativeId(loc)));
}

if (warning.frame) info(warning.frame);
Expand Down Expand Up @@ -119,9 +119,9 @@ const deferredHandlers: {
info('https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module');

for (const warning of warnings) {
stderr(tc.bold(warning.importer!));
stderr(color.bold(warning.importer!));
stderr(`${warning.missing} is not exported by ${warning.exporter}`);
stderr(tc.gray(warning.frame!));
stderr(color.gray(warning.frame!));
}
},

Expand All @@ -131,15 +131,15 @@ const deferredHandlers: {
`Use output.globals to specify browser global variable names corresponding to external modules`
);
for (const warning of warnings) {
stderr(`${tc.bold(warning.source!)} (guessing '${warning.guess}')`);
stderr(`${color.bold(warning.source!)} (guessing '${warning.guess}')`);
}
},

MIXED_EXPORTS: (warnings) => {
title('Mixing named and default exports');
info(`https://rollupjs.org/guide/en/#output-exports`);
stderr(
tc.bold('The following entry modules are using named and default exports together:')
color.bold('The following entry modules are using named and default exports together:')
);
const displayedWarnings = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
for (const warning of displayedWarnings) {
Expand All @@ -157,7 +157,7 @@ const deferredHandlers: {
title(`Conflicting re-exports`);
for (const warning of warnings) {
stderr(
`${tc.bold(relativeId(warning.reexporter!))} re-exports '${
`${color.bold(relativeId(warning.reexporter!))} re-exports '${
warning.name
}' from both ${relativeId(warning.sources![0])} and ${relativeId(
warning.sources![1]
Expand Down Expand Up @@ -189,7 +189,7 @@ const deferredHandlers: {
if (warning.loc) {
loc += `: (${warning.loc.line}:${warning.loc.column})`;
}
stderr(tc.bold(loc));
stderr(color.bold(loc));
}
if (warning.frame) info(warning.frame);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ const deferredHandlers: {

for (const dependency of dependencies.keys()) {
const importers = dependencies.get(dependency);
stderr(`${tc.bold(dependency)} (imported by ${importers.join(', ')})`);
stderr(`${color.bold(dependency)} (imported by ${importers.join(', ')})`);
}
},

Expand All @@ -244,11 +244,11 @@ const deferredHandlers: {
};

function title(str: string) {
stderr(`${tc.bold.yellow('(!)')} ${tc.bold.yellow(str)}`);
stderr(color.bold(color.yellow(`(!) ${str}`)));
}

function info(url: string) {
stderr(tc.gray(url));
stderr(color.gray(url));
}

function nest<T>(array: T[], prop: string) {
Expand Down Expand Up @@ -277,8 +277,8 @@ function showTruncatedWarnings(warnings: RollupWarning[]) {

const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
for (const { key: id, items } of displayedByModule) {
stderr(tc.bold(relativeId(id)));
stderr(tc.gray(items[0].frame!));
stderr(color.bold(relativeId(id)));
stderr(color.gray(items[0].frame!));

if (items.length > 1) {
stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`);
Expand Down
8 changes: 4 additions & 4 deletions cli/run/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'colorette';
import ms from 'pretty-ms';
import tc from 'turbocolor';
import * as rollup from '../../src/node-entry';
import { InputOptions, OutputOptions, RollupBuild } from '../../src/rollup/types';
import relativeId from '../../src/utils/relativeId';
Expand Down Expand Up @@ -31,7 +31,7 @@ export default function build(
.map(name => (inputOptions.input as Record<string, string>)[name])
.join(', ');
}
stderr(tc.cyan(`\n${tc.bold(inputFiles!)}${tc.bold(files.join(', '))}...`));
stderr(color.cyan(`\n${color.bold(inputFiles!)}${color.bold(files.join(', '))}...`));
}

return rollup
Expand All @@ -58,7 +58,7 @@ export default function build(
}
}
if (outputs.length > 1)
process.stdout.write('\n' + tc.cyan(tc.bold('//→ ' + file.fileName + ':')) + '\n');
process.stdout.write('\n' + color.cyan(color.bold('//→ ' + file.fileName + ':')) + '\n');
process.stdout.write(source);
}
return null
Expand All @@ -73,7 +73,7 @@ export default function build(
if (!silent) {
warnings.flush();
stderr(
tc.green(`created ${tc.bold(files.join(', '))} in ${tc.bold(ms(Date.now() - start))}`)
color.green(`created ${color.bold(files.join(', '))} in ${color.bold(ms(Date.now() - start))}`)
);
if (bundle && bundle.getTimings) {
printTimings(bundle.getTimings());
Expand Down
4 changes: 2 additions & 2 deletions cli/run/loadConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'colorette';
import path from 'path';
import tc from 'turbocolor';
import * as rollup from '../../src/node-entry';
import { RollupBuild, RollupOutput } from '../../src/rollup/types';
import { GenericConfigObject } from '../../src/utils/parseOptions';
Expand Down Expand Up @@ -28,7 +28,7 @@ export default function loadConfigFile(
})
.then((bundle: RollupBuild) => {
if (!silent && warnings.count > 0) {
stderr(tc.bold(`loaded ${relativeId(configFile)} with warnings`));
stderr(color.bold(`loaded ${relativeId(configFile)} with warnings`));
warnings.flush();
}

Expand Down
8 changes: 4 additions & 4 deletions cli/run/timings.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import color from 'colorette';
import prettyBytes from 'pretty-bytes';
import tc from 'turbocolor';
import { SerializedTimings } from '../../src/rollup/types';

export function printTimings(timings: SerializedTimings) {
Object.keys(timings).forEach(label => {
const color =
label[0] === '#' ? (label[1] !== '#' ? tc.underline : tc.bold) : (text: string) => text;
const appliedColor =
label[0] === '#' ? (label[1] !== '#' ? color.underline : color.bold) : (text: string) => text;
const [time, memory, total] = timings[label];
const row = `${label}: ${time.toFixed(0)}ms, ${prettyBytes(memory)} / ${prettyBytes(total)}`;
console.info(color(row));
console.info(appliedColor(row));
});
}
12 changes: 6 additions & 6 deletions cli/run/watch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import color from 'colorette';
import dateTime from 'date-time';
import fs from 'fs';
import ms from 'pretty-ms';
import onExit from 'signal-exit';
import tc from 'turbocolor';
import * as rollup from '../../src/node-entry';
import { RollupWatcher, RollupWatchOptions } from '../../src/rollup/types';
import { mergeOptions } from '../../src/utils/mergeOptions';
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function watch(

case 'START':
if (!silent) {
resetScreen(tc.underline(`rollup v${rollup.VERSION}`));
resetScreen(color.underline(`rollup v${rollup.VERSION}`));
}
break;

Expand All @@ -68,8 +68,8 @@ export default function watch(
.join(', ');
}
stderr(
tc.cyan(
`bundles ${tc.bold(input)}${tc.bold(event.output.map(relativeId).join(', '))}...`
color.cyan(
`bundles ${color.bold(input)}${color.bold(event.output.map(relativeId).join(', '))}...`
)
);
}
Expand All @@ -79,8 +79,8 @@ export default function watch(
warnings.flush();
if (!silent)
stderr(
tc.green(
`created ${tc.bold(event.output.map(relativeId).join(', '))} in ${tc.bold(
color.green(
`created ${color.bold(event.output.map(relativeId).join(', '))} in ${color.bold(
ms(event.duration)
)}`
)
Expand Down
24 changes: 15 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"buble": "^0.19.8",
"chokidar": "^3.3.1",
"codecov": "^3.6.5",
"colorette": "^1.1.0",
"console-group": "^0.3.3",
"core-js": "^3.6.4",
"cross-os": "^1.3.0",
Expand Down Expand Up @@ -126,7 +127,6 @@
"terser": "^4.6.3",
"tslib": "^1.10.0",
"tslint": "^6.0.0",
"turbocolor": "^2.6.1",
"typescript": "^3.7.5",
"url-parse": "^1.4.7"
},
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/interop/_expected.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

var tc = require('turbocolor');
var color = require('colorette');

assert.ok( tc );
assert.ok( color );
4 changes: 2 additions & 2 deletions test/cli/samples/interop/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import tc from 'turbocolor';
import color from 'colorette';

assert.ok( tc );
assert.ok( color );

0 comments on commit f0ff869

Please sign in to comment.