Skip to content

Commit

Permalink
fix: replace chalk with picocolors (vitejs#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Dec 28, 2021
1 parent 7e3e84e commit 5a111ce
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 259 deletions.
111 changes: 0 additions & 111 deletions packages/vite/LICENSE.md
Expand Up @@ -564,23 +564,6 @@ Repository: chalk/ansi-regex
---------------------------------------

## ansi-styles
License: MIT
By: Sindre Sorhus
Repository: chalk/ansi-styles

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
---------------------------------------

## anymatch
License: ISC
By: Elan Shanker
Expand Down Expand Up @@ -815,22 +798,6 @@ Repository: egoist/cac
---------------------------------------

## chalk
License: MIT
Repository: chalk/chalk

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
---------------------------------------

## chokidar
License: MIT
By: Paul Miller, Elan Shanker
Expand Down Expand Up @@ -860,50 +827,6 @@ Repository: git+https://github.com/paulmillr/chokidar.git
---------------------------------------

## color-convert
License: MIT
By: Heather Arthur
Repository: Qix-/color-convert

> Copyright (c) 2011-2016 Heather Arthur <fayearthur@gmail.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.
---------------------------------------

## color-name
License: MIT
By: DY
Repository: git@github.com:colorjs/color-name.git

> The MIT License (MIT)
> Copyright (c) 2015 Dmitry Ivanov
>
> 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.
---------------------------------------

## commondir
License: MIT
By: James Halliday
Expand Down Expand Up @@ -1843,23 +1766,6 @@ Repository: sindresorhus/globby
---------------------------------------

## has-flag
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/has-flag

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
---------------------------------------

## http-proxy
License: MIT
By: Charlie Robbins
Expand Down Expand Up @@ -4355,23 +4261,6 @@ Repository: sindresorhus/strip-final-newline
---------------------------------------

## supports-color
License: MIT
By: Sindre Sorhus
Repository: chalk/supports-color

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
---------------------------------------

## to-regex-range
License: MIT
By: Jon Schlinkert, Rouven Weßling
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Expand Up @@ -78,7 +78,6 @@
"@vue/compiler-dom": "^3.2.26",
"acorn": "^8.7.0",
"cac": "6.7.9",
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
"compression": "^1.7.4",
"connect": "^3.7.0",
Expand All @@ -101,6 +100,7 @@
"okie": "^1.0.1",
"open": "^8.4.0",
"periscopic": "^2.0.3",
"picocolors": "^1.0.0",
"postcss-import": "^14.0.2",
"postcss-load-config": "^3.1.0",
"postcss-modules": "^4.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/rollup.config.js
Expand Up @@ -8,7 +8,7 @@ import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import license from 'rollup-plugin-license'
import MagicString from 'magic-string'
import chalk from 'chalk'
import colors from 'picocolors'
import fg from 'fast-glob'
import { sync as resolve } from 'resolve'

Expand Down Expand Up @@ -369,7 +369,7 @@ function licensePlugin() {
if (existingLicenseText !== licenseText) {
fs.writeFileSync('LICENSE.md', licenseText)
console.warn(
chalk.yellow(
colors.yellow(
'\nLICENSE.md updated. You should commit the updated file.\n'
)
)
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/scripts/patchTypes.ts
@@ -1,7 +1,7 @@
import type { ParseResult } from '@babel/parser'
import { parse } from '@babel/parser'
import type { File } from '@babel/types'
import chalk from 'chalk'
import colors from 'picocolors'
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs'
import MagicString from 'magic-string'
import { dirname, relative, resolve } from 'path'
Expand All @@ -13,7 +13,7 @@ const typesDir = resolve(__dirname, '../types')
// and rewrite them into relative imports - so that api-extractor actually
// includes them in the rolled-up final d.ts file.
walkDir(tempDir)
console.log(chalk.green.bold(`patched types/* imports`))
console.log(colors.green(colors.bold(`patched types/* imports`)))

function slash(p: string): string {
return p.replace(/\\/g, '/')
Expand Down Expand Up @@ -42,7 +42,7 @@ function rewriteFile(file: string): void {
plugins: ['typescript', 'classProperties']
})
} catch (e) {
console.log(chalk.red(`failed to parse ${file}`))
console.log(colors.red(`failed to parse ${file}`))
throw e
}
for (const statement of ast.program.body) {
Expand Down
32 changes: 16 additions & 16 deletions packages/vite/src/node/build.ts
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import colors from 'picocolors'
import type { InlineConfig, ResolvedConfig } from './config'
import { resolveConfig } from './config'
import type {
Expand Down Expand Up @@ -413,8 +413,8 @@ async function doBuild(
const libOptions = options.lib

config.logger.info(
chalk.cyan(
`vite v${require('vite/package.json').version} ${chalk.green(
colors.cyan(
`vite v${require('vite/package.json').version} ${colors.green(
`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`
)}`
)
Expand Down Expand Up @@ -467,14 +467,14 @@ async function doBuild(
}

const outputBuildError = (e: RollupError) => {
let msg = chalk.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
let msg = colors.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
if (e.id) {
msg += `\nfile: ${chalk.cyan(
msg += `\nfile: ${colors.cyan(
e.id + (e.loc ? `:${e.loc.line}:${e.loc.column}` : '')
)}`
}
if (e.frame) {
msg += `\n` + chalk.yellow(e.frame)
msg += `\n` + colors.yellow(e.frame)
}
config.logger.error(msg, { error: e })
}
Expand Down Expand Up @@ -531,7 +531,7 @@ async function doBuild(

// watch file changes with rollup
if (config.build.watch) {
config.logger.info(chalk.cyanBright(`\nwatching for file changes...`))
config.logger.info(colors.cyan(`\nwatching for file changes...`))

const output: OutputOptions[] = []
if (Array.isArray(outputs)) {
Expand Down Expand Up @@ -563,13 +563,13 @@ async function doBuild(

watcher.on('event', (event) => {
if (event.code === 'BUNDLE_START') {
config.logger.info(chalk.cyanBright(`\nbuild started...`))
config.logger.info(colors.cyan(`\nbuild started...`))
if (options.write) {
prepareOutDir(outDir, options.emptyOutDir, config)
}
} else if (event.code === 'BUNDLE_END') {
event.result.close()
config.logger.info(chalk.cyanBright(`built in ${event.duration}ms.`))
config.logger.info(colors.cyan(`built in ${event.duration}ms.`))
} else if (event.code === 'ERROR') {
outputBuildError(event.error)
}
Expand Down Expand Up @@ -622,9 +622,9 @@ function prepareOutDir(
) {
// warn if outDir is outside of root
config.logger.warn(
chalk.yellow(
`\n${chalk.bold(`(!)`)} outDir ${chalk.white.dim(
outDir
colors.yellow(
`\n${colors.bold(`(!)`)} outDir ${colors.white(
colors.dim(outDir)
)} is not inside project root and will not be emptied.\n` +
`Use --emptyOutDir to override.\n`
)
Expand Down Expand Up @@ -735,7 +735,7 @@ function resolveBuildOutputs(
} else if (libOptions.formats) {
// user explicitly specifying own output array
logger.warn(
chalk.yellow(
colors.yellow(
`"build.lib.formats" will be ignored because ` +
`"build.rollupOptions.output" is already an array format`
)
Expand Down Expand Up @@ -783,9 +783,9 @@ export function onRollupWarning(
userOnWarn(warning, warn)
} else if (warning.code === 'PLUGIN_WARNING') {
config.logger.warn(
`${chalk.bold.yellow(`[plugin:${warning.plugin}]`)} ${chalk.yellow(
warning.message
)}`
`${colors.bold(
colors.yellow(`[plugin:${warning.plugin}]`)
)} ${colors.yellow(warning.message)}`
)
} else {
warn(warning)
Expand Down
18 changes: 10 additions & 8 deletions packages/vite/src/node/cli.ts
@@ -1,5 +1,5 @@
import { cac } from 'cac'
import chalk from 'chalk'
import colors from 'picocolors'
import { performance } from 'perf_hooks'
import type { BuildOptions } from './build'
import type { ServerOptions } from './server'
Expand Down Expand Up @@ -98,8 +98,8 @@ cli
const info = server.config.logger.info

info(
chalk.cyan(`\n vite v${require('vite/package.json').version}`) +
chalk.green(` dev server running at:\n`),
colors.cyan(`\n vite v${require('vite/package.json').version}`) +
colors.green(` dev server running at:\n`),
{
clear: !server.config.logger.hasWarned
}
Expand All @@ -111,11 +111,13 @@ cli
if (global.__vite_start_time) {
// @ts-ignore
const startupDuration = performance.now() - global.__vite_start_time
info(`\n ${chalk.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`)
info(
`\n ${colors.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`
)
}
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error when starting dev server:\n${e.stack}`),
colors.red(`error when starting dev server:\n${e.stack}`),
{ error: e }
)
process.exit(1)
Expand Down Expand Up @@ -171,7 +173,7 @@ cli
})
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error during build:\n${e.stack}`),
colors.red(`error during build:\n${e.stack}`),
{ error: e }
)
process.exit(1)
Expand Down Expand Up @@ -202,7 +204,7 @@ cli
await optimizeDeps(config, options.force, true)
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error when optimizing deps:\n${e.stack}`),
colors.red(`error when optimizing deps:\n${e.stack}`),
{ error: e }
)
process.exit(1)
Expand Down Expand Up @@ -245,7 +247,7 @@ cli
server.printUrls()
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error when starting preview server:\n${e.stack}`),
colors.red(`error when starting preview server:\n${e.stack}`),
{ error: e }
)
process.exit(1)
Expand Down

0 comments on commit 5a111ce

Please sign in to comment.