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

perf: swap chalk for turbocolor #651

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions bin/vuepress.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node

const chalk = require('chalk')
const tc = require('turbocolor')
const semver = require('semver')
const requiredVersion = require('../package.json').engines.node

if (!semver.satisfies(process.version, requiredVersion)) {
console.log(chalk.red(
console.log(tc.red(
`\n[vuepress] minimum Node version not met:` +
`\nYou are using Node ${process.version}, but VuePress ` +
`requires Node ${requiredVersion}.\nPlease upgrade your Node version.\n`
Expand Down Expand Up @@ -53,14 +53,14 @@ program
.arguments('<command>')
.action((cmd) => {
program.outputHelp()
console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`))
console.log(` ` + tc.red(`Unknown command ${tc.yellow(cmd)}.`))
console.log()
})

// add some useful info on help
program.on('--help', () => {
console.log()
console.log(` Run ${chalk.cyan(`vuepress <command> --help`)} for detailed usage of given command.`)
console.log(` Run ${tc.cyan(`vuepress <command> --help`)} for detailed usage of given command.`)
console.log()
})

Expand All @@ -73,23 +73,23 @@ const enhanceErrorMessages = (methodName, log) => {
return
}
this.outputHelp()
console.log(` ` + chalk.red(log(...args)))
console.log(` ` + tc.red(log(...args)))
console.log()
process.exit(1)
}
}

enhanceErrorMessages('missingArgument', argName => {
return `Missing required argument ${chalk.yellow(`<${argName}>`)}.`
return `Missing required argument ${tc.yellow(`<${argName}>`)}.`
})

enhanceErrorMessages('unknownOption', optionName => {
return `Unknown option ${chalk.yellow(optionName)}.`
return `Unknown option ${tc.yellow(optionName)}.`
})

enhanceErrorMessages('optionMissingArgument', (option, flag) => {
return `Missing required argument for option ${chalk.yellow(option.flags)}` + (
flag ? `, got ${chalk.yellow(flag)}` : ``
return `Missing required argument for option ${tc.yellow(option.flags)}` + (
flag ? `, got ${tc.yellow(flag)}` : ``
)
})

Expand All @@ -102,7 +102,7 @@ if (!process.argv.slice(2).length) {
function wrapCommand (fn) {
return (...args) => {
return fn(...args).catch(err => {
console.error(chalk.red(err.stack))
console.error(tc.red(err.stack))
process.exitCode = 1
})
}
Expand Down
8 changes: 4 additions & 4 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {

const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
const tc = require('turbocolor')
const webpack = require('webpack')
const readline = require('readline')
const escape = require('escape-html')
Expand All @@ -23,7 +23,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {

const { outDir } = options
if (path.resolve() === outDir) {
return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
return console.error(logger.error(tc.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
}
await fs.remove(outDir)

Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {

// DONE.
const relativeDir = path.relative(process.cwd(), outDir)
logger.success(`\n${chalk.green('Success!')} Generated static files in ${chalk.cyan(relativeDir)}.\n`)
logger.success(`\n${tc.green('Success!')} Generated static files in ${tc.cyan(relativeDir)}.\n`)

// --- helpers ---

Expand Down Expand Up @@ -160,7 +160,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
try {
html = await renderer.renderToString(context)
} catch (e) {
console.error(logger.error(chalk.red(`Error rendering ${pagePath}:`), false))
console.error(logger.error(tc.red(`Error rendering ${pagePath}:`), false))
throw e
}
const filename = decodeURIComponent(pagePath.replace(/\/$/, '/index.html').replace(/^\//, ''))
Expand Down
4 changes: 2 additions & 2 deletions lib/dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = async function dev (sourceDir, cliOptions = {}) {
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const tc = require('turbocolor')
const webpack = require('webpack')
const chokidar = require('chokidar')
const serve = require('webpack-serve')
Expand All @@ -25,7 +25,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
// setup watchers to update options and dynamically generated files
const update = () => {
prepare(sourceDir).catch(err => {
console.error(logger.error(chalk.red(err.stack), false))
console.error(logger.error(tc.red(err.stack), false))
})
}

Expand Down
4 changes: 2 additions & 2 deletions lib/eject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
const tc = require('turbocolor')
const logger = require('./util/logger')

module.exports = async (dir) => {
Expand All @@ -12,5 +12,5 @@ module.exports = async (dir) => {
const content = await fs.readFile(styleConfig, 'utf-8')
const transformed = content.split('\n').slice(0, -2).join('\n')
await fs.writeFile(styleConfig, transformed)
logger.success(`\nCopied default theme into ${chalk.cyan(target)}.\n`)
logger.success(`\nCopied default theme into ${tc.cyan(target)}.\n`)
}
4 changes: 2 additions & 2 deletions lib/markdown/highlight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const tc = require('turbocolor')
const prism = require('prismjs')
const loadLanguages = require('prismjs/components/index')
const escapeHtml = require('escape-html')
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = (str, lang) => {
try {
loadLanguages([lang])
} catch (e) {
logger.warn(chalk.yellow(`[vuepress] Syntax highlight for language "${lang}" is not supported.`))
logger.warn(tc.yellow(`[vuepress] Syntax highlight for language "${lang}" is not supported.`))
}
}
if (prism.languages[lang]) {
Expand Down
6 changes: 3 additions & 3 deletions lib/prepare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const resolveOptions = require('./resolveOptions')
const { genRoutesFile, genComponentRegistrationFile } = require('./codegen')
const { writeTemp, writeEnhanceTemp } = require('./util')
const logger = require('../util/logger')
const chalk = require('chalk')
const tc = require('turbocolor')

module.exports = async function prepare (sourceDir) {
// 1. load options
Expand Down Expand Up @@ -35,8 +35,8 @@ module.exports = async function prepare (sourceDir) {
// Temporary tip, will be removed at next release.
if (hasUserOverride && !hasUserStyle) {
logger.tip(
`${chalk.magenta('override.styl')} has been split into 2 APIs, we recommend you upgrade to continue.\n` +
` See: ${chalk.magenta('https://vuepress.vuejs.org/default-theme-config/#simple-css-override')}`
`${tc.magenta('override.styl')} has been split into 2 APIs, we recommend you upgrade to continue.\n` +
` See: ${tc.magenta('https://vuepress.vuejs.org/default-theme-config/#simple-css-override')}`
)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/util/logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const tc = require('turbocolor')

const logger = {}

Expand Down Expand Up @@ -31,7 +31,7 @@ const getLoggerFn = (color, label) => (msg, log = true) => {
if (log) msg = msg.slice(1)
newLine = true
}
msg = chalk.reset.inverse.bold[color](` ${label} `) + ' ' + msg
msg = tc.reset.inverse.bold[color](` ${label} `) + ' ' + msg
if (log) {
console.log(newLine ? '\n' + msg : msg)
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/webpack/DevLogPlugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk')
const tc = require('turbocolor')
const logger = require('../util/logger')

module.exports = class DevLogPlugin {
Expand All @@ -14,10 +14,10 @@ module.exports = class DevLogPlugin {
const { displayHost, port, publicPath } = this.options
const time = new Date().toTimeString().match(/^[\d:]+/)[0]

logger.success(`\n${chalk.gray(`[${time}]`)} Build ${chalk.italic(stats.hash.slice(0, 6))} finished in ${stats.endTime - stats.startTime} ms!`)
logger.success(`\n${tc.gray(`[${time}]`)} Build ${tc.italic(stats.hash.slice(0, 6))} finished in ${stats.endTime - stats.startTime} ms!`)
if (isFirst) {
isFirst = false
console.log(`\n${chalk.gray('>')} VuePress dev server listening at ${chalk.cyan(`http://${displayHost}:${port}${publicPath}`)}`)
console.log(`\n${tc.gray('>')} VuePress dev server listening at ${tc.cyan(`http://${displayHost}:${port}${publicPath}`)}`)
}
})
compiler.hooks.invalid.tap('vuepress-log', clearScreen)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"autoprefixer": "^8.2.0",
"babel-loader": "8.0.0-beta.3",
"cache-loader": "^1.2.2",
"chalk": "^2.3.2",
"turbocolor": "^2.2.0",
"chokidar": "^2.0.3",
"commander": "^2.15.1",
"connect-history-api-fallback": "^1.5.0",
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7921,6 +7921,10 @@ tunnel-agent@^0.6.0:
dependencies:
safe-buffer "^5.0.1"

turbocolor@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/turbocolor/-/turbocolor-2.2.0.tgz#9e6c9536e014b4214baef6a87fec4ede1d660b6f"

tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
Expand Down