From 2b92b42656e1b6fda229763428480a267333b01c Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Mon, 1 Oct 2018 18:39:38 +0900 Subject: [PATCH] refactor: replace colors with colorette Colorette is lighter and faster than the colors package. It's also "safe" by default; it doesn't mutate the string prototype. Terminal color support is autodetected, so our console output will not contain unreadable symbols if the target terminal does not support color. --- bin/lib/start.js | 12 ++++++------ package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/lib/start.js b/bin/lib/start.js index 0f85f3c41..8967fe238 100644 --- a/bin/lib/start.js +++ b/bin/lib/start.js @@ -3,7 +3,7 @@ const options = require('./options') const fs = require('fs') const extend = require('extend') -const colors = require('colors/safe') +const { cyan, red, bold } = require('colorette') module.exports = function (program, server) { const start = program @@ -29,7 +29,7 @@ module.exports = function (program, server) { fs.readFile(configFile, (err, file) => { // No file exists, not a problem if (err) { - console.log(colors.cyan.bold('TIP'), 'create a config.json: `$ solid init`') + console.log(cyan(bold('TIP')), 'create a config.json: `$ solid init`') } else { // Use flags with priority over config file const config = JSON.parse(file) @@ -123,17 +123,17 @@ function bin (argv, server) { } catch (e) { if (e.code === 'EACCES') { if (e.syscall === 'mkdir') { - console.log(colors.red.bold('ERROR'), `You need permissions to create '${e.path}' folder`) + console.log(red(bold('ERROR')), `You need permissions to create '${e.path}' folder`) } else { - console.log(colors.red.bold('ERROR'), 'You need root privileges to start on this port') + console.log(red(bold('ERROR')), 'You need root privileges to start on this port') } return 1 } if (e.code === 'EADDRINUSE') { - console.log(colors.red.bold('ERROR'), 'The port ' + argv.port + ' is already in use') + console.log(red(bold('ERROR')), 'The port ' + argv.port + ' is already in use') return 1 } - console.log(colors.red.bold('ERROR'), e.message) + console.log(red(bold('ERROR')), e.message) return 1 } app.listen(argv.port, function () { diff --git a/package-lock.json b/package-lock.json index 4af8f6d0d..ab26126bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1979,10 +1979,10 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "colors": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.2.tgz", - "integrity": "sha512-rhP0JSBGYvpcNQj4s5AdShMeE5ahMop96cTeDl/v9qQQm2fYClE2QXZRi8wLzc+GmXSxdIqqbOIAhyObEXDbfQ==" + "colorette": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.0.5.tgz", + "integrity": "sha512-7mcpZLRdXqHLaOhGfKaDD/K7UjLSp6MkrDT6DziQ/HKBxqV3G1yLZAc14UCP8bCQAJTbcvd4k6MGRVYUa4NmHw==" }, "combine-source-map": { "version": "0.8.0", diff --git a/package.json b/package.json index 71b8aad94..beb982cf7 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "body-parser": "^1.18.3", "busboy": "^0.2.12", "camelize": "^1.0.0", - "colors": "^1.1.2", + "colorette": "^1.0.5", "commander": "^2.9.0", "cors": "^2.7.1", "debug": "^2.6.9",