Skip to content

Commit 5a111ce

Browse files
authored
fix: replace chalk with picocolors (vitejs#6277)
1 parent 7e3e84e commit 5a111ce

27 files changed

+162
-259
lines changed

packages/vite/LICENSE.md

-111
Original file line numberDiff line numberDiff line change
@@ -564,23 +564,6 @@ Repository: chalk/ansi-regex
564564
565565
---------------------------------------
566566

567-
## ansi-styles
568-
License: MIT
569-
By: Sindre Sorhus
570-
Repository: chalk/ansi-styles
571-
572-
> MIT License
573-
>
574-
> Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
575-
>
576-
> 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:
577-
>
578-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
579-
>
580-
> 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.
581-
582-
---------------------------------------
583-
584567
## anymatch
585568
License: ISC
586569
By: Elan Shanker
@@ -815,22 +798,6 @@ Repository: egoist/cac
815798
816799
---------------------------------------
817800

818-
## chalk
819-
License: MIT
820-
Repository: chalk/chalk
821-
822-
> MIT License
823-
>
824-
> Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
825-
>
826-
> 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:
827-
>
828-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
829-
>
830-
> 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.
831-
832-
---------------------------------------
833-
834801
## chokidar
835802
License: MIT
836803
By: Paul Miller, Elan Shanker
@@ -860,50 +827,6 @@ Repository: git+https://github.com/paulmillr/chokidar.git
860827
861828
---------------------------------------
862829

863-
## color-convert
864-
License: MIT
865-
By: Heather Arthur
866-
Repository: Qix-/color-convert
867-
868-
> Copyright (c) 2011-2016 Heather Arthur <[email protected]>
869-
>
870-
> Permission is hereby granted, free of charge, to any person obtaining
871-
> a copy of this software and associated documentation files (the
872-
> "Software"), to deal in the Software without restriction, including
873-
> without limitation the rights to use, copy, modify, merge, publish,
874-
> distribute, sublicense, and/or sell copies of the Software, and to
875-
> permit persons to whom the Software is furnished to do so, subject to
876-
> the following conditions:
877-
>
878-
> The above copyright notice and this permission notice shall be
879-
> included in all copies or substantial portions of the Software.
880-
>
881-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
882-
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
883-
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
884-
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
885-
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
886-
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
887-
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
888-
889-
---------------------------------------
890-
891-
## color-name
892-
License: MIT
893-
By: DY
894-
Repository: [email protected]:colorjs/color-name.git
895-
896-
> The MIT License (MIT)
897-
> Copyright (c) 2015 Dmitry Ivanov
898-
>
899-
> 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:
900-
>
901-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
902-
>
903-
> 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.
904-
905-
---------------------------------------
906-
907830
## commondir
908831
License: MIT
909832
By: James Halliday
@@ -1843,23 +1766,6 @@ Repository: sindresorhus/globby
18431766
18441767
---------------------------------------
18451768

1846-
## has-flag
1847-
License: MIT
1848-
By: Sindre Sorhus
1849-
Repository: sindresorhus/has-flag
1850-
1851-
> MIT License
1852-
>
1853-
> Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
1854-
>
1855-
> 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:
1856-
>
1857-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1858-
>
1859-
> 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.
1860-
1861-
---------------------------------------
1862-
18631769
## http-proxy
18641770
License: MIT
18651771
By: Charlie Robbins
@@ -4355,23 +4261,6 @@ Repository: sindresorhus/strip-final-newline
43554261
43564262
---------------------------------------
43574263

4358-
## supports-color
4359-
License: MIT
4360-
By: Sindre Sorhus
4361-
Repository: chalk/supports-color
4362-
4363-
> MIT License
4364-
>
4365-
> Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
4366-
>
4367-
> 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:
4368-
>
4369-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4370-
>
4371-
> 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.
4372-
4373-
---------------------------------------
4374-
43754264
## to-regex-range
43764265
License: MIT
43774266
By: Jon Schlinkert, Rouven Weßling

packages/vite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"@vue/compiler-dom": "^3.2.26",
7979
"acorn": "^8.7.0",
8080
"cac": "6.7.9",
81-
"chalk": "^4.1.2",
8281
"chokidar": "^3.5.2",
8382
"compression": "^1.7.4",
8483
"connect": "^3.7.0",
@@ -101,6 +100,7 @@
101100
"okie": "^1.0.1",
102101
"open": "^8.4.0",
103102
"periscopic": "^2.0.3",
103+
"picocolors": "^1.0.0",
104104
"postcss-import": "^14.0.2",
105105
"postcss-load-config": "^3.1.0",
106106
"postcss-modules": "^4.2.2",

packages/vite/rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import json from '@rollup/plugin-json'
88
import alias from '@rollup/plugin-alias'
99
import license from 'rollup-plugin-license'
1010
import MagicString from 'magic-string'
11-
import chalk from 'chalk'
11+
import colors from 'picocolors'
1212
import fg from 'fast-glob'
1313
import { sync as resolve } from 'resolve'
1414

@@ -369,7 +369,7 @@ function licensePlugin() {
369369
if (existingLicenseText !== licenseText) {
370370
fs.writeFileSync('LICENSE.md', licenseText)
371371
console.warn(
372-
chalk.yellow(
372+
colors.yellow(
373373
'\nLICENSE.md updated. You should commit the updated file.\n'
374374
)
375375
)

packages/vite/scripts/patchTypes.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ParseResult } from '@babel/parser'
22
import { parse } from '@babel/parser'
33
import type { File } from '@babel/types'
4-
import chalk from 'chalk'
4+
import colors from 'picocolors'
55
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs'
66
import MagicString from 'magic-string'
77
import { dirname, relative, resolve } from 'path'
@@ -13,7 +13,7 @@ const typesDir = resolve(__dirname, '../types')
1313
// and rewrite them into relative imports - so that api-extractor actually
1414
// includes them in the rolled-up final d.ts file.
1515
walkDir(tempDir)
16-
console.log(chalk.green.bold(`patched types/* imports`))
16+
console.log(colors.green(colors.bold(`patched types/* imports`)))
1717

1818
function slash(p: string): string {
1919
return p.replace(/\\/g, '/')
@@ -42,7 +42,7 @@ function rewriteFile(file: string): void {
4242
plugins: ['typescript', 'classProperties']
4343
})
4444
} catch (e) {
45-
console.log(chalk.red(`failed to parse ${file}`))
45+
console.log(colors.red(`failed to parse ${file}`))
4646
throw e
4747
}
4848
for (const statement of ast.program.body) {

packages/vite/src/node/build.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import chalk from 'chalk'
3+
import colors from 'picocolors'
44
import type { InlineConfig, ResolvedConfig } from './config'
55
import { resolveConfig } from './config'
66
import type {
@@ -413,8 +413,8 @@ async function doBuild(
413413
const libOptions = options.lib
414414

415415
config.logger.info(
416-
chalk.cyan(
417-
`vite v${require('vite/package.json').version} ${chalk.green(
416+
colors.cyan(
417+
`vite v${require('vite/package.json').version} ${colors.green(
418418
`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`
419419
)}`
420420
)
@@ -467,14 +467,14 @@ async function doBuild(
467467
}
468468

469469
const outputBuildError = (e: RollupError) => {
470-
let msg = chalk.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
470+
let msg = colors.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
471471
if (e.id) {
472-
msg += `\nfile: ${chalk.cyan(
472+
msg += `\nfile: ${colors.cyan(
473473
e.id + (e.loc ? `:${e.loc.line}:${e.loc.column}` : '')
474474
)}`
475475
}
476476
if (e.frame) {
477-
msg += `\n` + chalk.yellow(e.frame)
477+
msg += `\n` + colors.yellow(e.frame)
478478
}
479479
config.logger.error(msg, { error: e })
480480
}
@@ -531,7 +531,7 @@ async function doBuild(
531531

532532
// watch file changes with rollup
533533
if (config.build.watch) {
534-
config.logger.info(chalk.cyanBright(`\nwatching for file changes...`))
534+
config.logger.info(colors.cyan(`\nwatching for file changes...`))
535535

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

564564
watcher.on('event', (event) => {
565565
if (event.code === 'BUNDLE_START') {
566-
config.logger.info(chalk.cyanBright(`\nbuild started...`))
566+
config.logger.info(colors.cyan(`\nbuild started...`))
567567
if (options.write) {
568568
prepareOutDir(outDir, options.emptyOutDir, config)
569569
}
570570
} else if (event.code === 'BUNDLE_END') {
571571
event.result.close()
572-
config.logger.info(chalk.cyanBright(`built in ${event.duration}ms.`))
572+
config.logger.info(colors.cyan(`built in ${event.duration}ms.`))
573573
} else if (event.code === 'ERROR') {
574574
outputBuildError(event.error)
575575
}
@@ -622,9 +622,9 @@ function prepareOutDir(
622622
) {
623623
// warn if outDir is outside of root
624624
config.logger.warn(
625-
chalk.yellow(
626-
`\n${chalk.bold(`(!)`)} outDir ${chalk.white.dim(
627-
outDir
625+
colors.yellow(
626+
`\n${colors.bold(`(!)`)} outDir ${colors.white(
627+
colors.dim(outDir)
628628
)} is not inside project root and will not be emptied.\n` +
629629
`Use --emptyOutDir to override.\n`
630630
)
@@ -735,7 +735,7 @@ function resolveBuildOutputs(
735735
} else if (libOptions.formats) {
736736
// user explicitly specifying own output array
737737
logger.warn(
738-
chalk.yellow(
738+
colors.yellow(
739739
`"build.lib.formats" will be ignored because ` +
740740
`"build.rollupOptions.output" is already an array format`
741741
)
@@ -783,9 +783,9 @@ export function onRollupWarning(
783783
userOnWarn(warning, warn)
784784
} else if (warning.code === 'PLUGIN_WARNING') {
785785
config.logger.warn(
786-
`${chalk.bold.yellow(`[plugin:${warning.plugin}]`)} ${chalk.yellow(
787-
warning.message
788-
)}`
786+
`${colors.bold(
787+
colors.yellow(`[plugin:${warning.plugin}]`)
788+
)} ${colors.yellow(warning.message)}`
789789
)
790790
} else {
791791
warn(warning)

packages/vite/src/node/cli.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cac } from 'cac'
2-
import chalk from 'chalk'
2+
import colors from 'picocolors'
33
import { performance } from 'perf_hooks'
44
import type { BuildOptions } from './build'
55
import type { ServerOptions } from './server'
@@ -98,8 +98,8 @@ cli
9898
const info = server.config.logger.info
9999

100100
info(
101-
chalk.cyan(`\n vite v${require('vite/package.json').version}`) +
102-
chalk.green(` dev server running at:\n`),
101+
colors.cyan(`\n vite v${require('vite/package.json').version}`) +
102+
colors.green(` dev server running at:\n`),
103103
{
104104
clear: !server.config.logger.hasWarned
105105
}
@@ -111,11 +111,13 @@ cli
111111
if (global.__vite_start_time) {
112112
// @ts-ignore
113113
const startupDuration = performance.now() - global.__vite_start_time
114-
info(`\n ${chalk.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`)
114+
info(
115+
`\n ${colors.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`
116+
)
115117
}
116118
} catch (e) {
117119
createLogger(options.logLevel).error(
118-
chalk.red(`error when starting dev server:\n${e.stack}`),
120+
colors.red(`error when starting dev server:\n${e.stack}`),
119121
{ error: e }
120122
)
121123
process.exit(1)
@@ -171,7 +173,7 @@ cli
171173
})
172174
} catch (e) {
173175
createLogger(options.logLevel).error(
174-
chalk.red(`error during build:\n${e.stack}`),
176+
colors.red(`error during build:\n${e.stack}`),
175177
{ error: e }
176178
)
177179
process.exit(1)
@@ -202,7 +204,7 @@ cli
202204
await optimizeDeps(config, options.force, true)
203205
} catch (e) {
204206
createLogger(options.logLevel).error(
205-
chalk.red(`error when optimizing deps:\n${e.stack}`),
207+
colors.red(`error when optimizing deps:\n${e.stack}`),
206208
{ error: e }
207209
)
208210
process.exit(1)
@@ -245,7 +247,7 @@ cli
245247
server.printUrls()
246248
} catch (e) {
247249
createLogger(options.logLevel).error(
248-
chalk.red(`error when starting preview server:\n${e.stack}`),
250+
colors.red(`error when starting preview server:\n${e.stack}`),
249251
{ error: e }
250252
)
251253
process.exit(1)

0 commit comments

Comments
 (0)