From d6834a794cee77f456c7aa21798263bf2bae77e2 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 15 Jan 2022 11:32:37 +0800 Subject: [PATCH] fix: replace chalk with picocolors --- .eslintrc.js | 2 ++ package.json | 2 +- packages/uni-cli-shared/package.json | 2 +- packages/uni-cli-shared/src/hbx/log.ts | 10 +++++----- .../src/vite/plugins/vitejs/plugins/css.ts | 6 +++--- packages/vite-plugin-uni/package.json | 4 ++-- packages/vite-plugin-uni/src/cli/server.ts | 6 +++--- packages/vite-plugin-uni/src/cli/utils.ts | 4 ++-- pnpm-lock.yaml | 17 +++++++++++------ scripts/apiExtractor.js | 13 ++++++------- scripts/build.js | 4 ++-- scripts/release.js | 14 +++++++------- scripts/updateVersion.js | 4 ++-- scripts/utils.js | 6 +++--- scripts/verifyCommit.js | 19 +++++++++---------- 15 files changed, 59 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 924554b3f..1579b81e3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,6 +46,8 @@ module.exports = { files: [ 'packages/{uni-cli-shared,uni-cli-nvue,uni-app-vite,uni-h5-vite,uni-mp-vite,uni-mp-compiler,vite-plugin-uni}/**', 'packages/*/vite.config.ts', + '.eslintrc.js', + 'scripts/**', ], rules: { 'no-restricted-globals': ['error', ...DOMGlobals], diff --git a/package.json b/package.json index de9effb3e..e92a52ed8 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "@vue/runtime-core": "3.2.26", "@vue/runtime-dom": "3.2.26", "@vue/shared": "3.2.26", - "chalk": "^4.1.1", "core-js": "^2.6.12", "enquirer": "^2.3.6", "eslint": "^7.17.0", @@ -72,6 +71,7 @@ "mini-types": "^0.1.7", "minimist": "^1.2.5", "miniprogram-api-typings": "^3.4.4", + "picocolors": "^1.0.0", "prettier": "^2.4.1", "rollup": "^2.57.0", "rollup-plugin-jscc": "^2.0.0", diff --git a/packages/uni-cli-shared/package.json b/packages/uni-cli-shared/package.json index 0aee08b91..1decfe332 100644 --- a/packages/uni-cli-shared/package.json +++ b/packages/uni-cli-shared/package.json @@ -30,7 +30,6 @@ "@vue/server-renderer": "3.2.26", "@vue/shared": "3.2.26", "base64url": "^3.0.1", - "chalk": "^4.1.1", "chokidar": "^3.5.2", "compare-versions": "^3.6.0", "debug": "^4.3.2", @@ -45,6 +44,7 @@ "merge": "^2.1.1", "mime": "^3.0.0", "module-alias": "^2.2.2", + "picocolors": "^1.0.0", "postcss-import": "^14.0.2", "postcss-load-config": "^3.1.0", "postcss-modules": "^4.2.2", diff --git a/packages/uni-cli-shared/src/hbx/log.ts b/packages/uni-cli-shared/src/hbx/log.ts index 91a339c1d..5c7674e13 100644 --- a/packages/uni-cli-shared/src/hbx/log.ts +++ b/packages/uni-cli-shared/src/hbx/log.ts @@ -1,5 +1,5 @@ import path from 'path' -import chalk from 'chalk' +import colors from 'picocolors' import { LogErrorOptions } from 'vite' import { normalizePath } from '../utils' import { Formatter } from '../logs/format' @@ -75,16 +75,16 @@ function buildErrorMessage( ): string { if (err.plugin) { args.push( - `${chalk.magenta('[plugin:' + err.plugin + ']')} ${chalk.red( + `${colors.magenta('[plugin:' + err.plugin + ']')} ${colors.red( err.message )}` ) } else { - args.push(chalk.red(err.message)) + args.push(colors.red(err.message)) } if (err.id) { args.push( - `at ${chalk.cyan( + `at ${colors.cyan( normalizePath( path.relative(process.env.UNI_INPUT_DIR, err.id.split('?')[0]) ) + @@ -96,7 +96,7 @@ function buildErrorMessage( ) } if (err.frame) { - args.push(chalk.yellow(pad(err.frame))) + args.push(colors.yellow(pad(err.frame))) } if (includeStack && err.stack) { args.push(pad(cleanStack(err.stack))) diff --git a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts index e4ef6f279..8eb9a28fe 100644 --- a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts +++ b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts @@ -1,7 +1,7 @@ import fs from 'fs' import path from 'path' import glob from 'fast-glob' -import chalk from 'chalk' +import colors from 'picocolors' import postcssrc from 'postcss-load-config' import { dataToEsm } from '@rollup/pluginutils' import { PluginContext, RollupError, SourceMap } from 'rollup' @@ -567,7 +567,7 @@ async function compileCSS( column: message.column, })}` } - config.logger.warn(chalk.yellow(msg)) + config.logger.warn(colors.yellow(msg)) } } @@ -716,7 +716,7 @@ export async function minifyCSS(css: string, config: ResolvedConfig) { if (warnings.length) { const msgs = await formatMessages(warnings, { kind: 'warning' }) config.logger.warn( - chalk.yellow(`warnings when minifying css:\n${msgs.join('\n')}`) + colors.yellow(`warnings when minifying css:\n${msgs.join('\n')}`) ) } return code diff --git a/packages/vite-plugin-uni/package.json b/packages/vite-plugin-uni/package.json index e7f819599..54a1b379c 100644 --- a/packages/vite-plugin-uni/package.json +++ b/packages/vite-plugin-uni/package.json @@ -36,13 +36,13 @@ "@vue/compiler-sfc": "3.2.26", "@vue/shared": "3.2.26", "cac": "^6.7.3", - "chalk": "^4.1.1", "debug": "^4.3.2", "estree-walker": "^2.0.2", "express": "^4.17.1", "fs-extra": "^10.0.0", "hash-sum": "^2.0.0", - "jsonc-parser": "^3.0.0" + "jsonc-parser": "^3.0.0", + "picocolors": "^1.0.0" }, "devDependencies": { "@types/debug": "^4.1.7", diff --git a/packages/vite-plugin-uni/src/cli/server.ts b/packages/vite-plugin-uni/src/cli/server.ts index 3660f3440..4293fe879 100644 --- a/packages/vite-plugin-uni/src/cli/server.ts +++ b/packages/vite-plugin-uni/src/cli/server.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import chalk from 'chalk' +import colors from 'picocolors' import { createLogger, createServer as createViteServer, @@ -28,8 +28,8 @@ export async function createServer(options: CliOptions & ServerOptions) { const logger = server.config.logger logger.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, } diff --git a/packages/vite-plugin-uni/src/cli/utils.ts b/packages/vite-plugin-uni/src/cli/utils.ts index 7b1aaf3f0..2c8497eec 100644 --- a/packages/vite-plugin-uni/src/cli/utils.ts +++ b/packages/vite-plugin-uni/src/cli/utils.ts @@ -1,7 +1,7 @@ import fs from 'fs' import os from 'os' import path from 'path' -import chalk from 'chalk' +import colors from 'picocolors' import { performance } from 'perf_hooks' import { BuildOptions, InlineConfig, Logger } from 'vite' @@ -209,7 +209,7 @@ export function printStartupDuration( // @ts-ignore const startupDuration = performance.now() - global.__vite_start_time logger.info( - `${whitespace ? `\n ` : ''}${chalk.cyan( + `${whitespace ? `\n ` : ''}${colors.cyan( `ready in ${Math.ceil(startupDuration)}ms.` )}\n` ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ae5ba717c..d8d2a9b36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,7 +24,6 @@ importers: '@vue/runtime-core': 3.2.26 '@vue/runtime-dom': 3.2.26 '@vue/shared': 3.2.26 - chalk: ^4.1.1 core-js: ^2.6.12 enquirer: ^2.3.6 eslint: ^7.17.0 @@ -35,6 +34,7 @@ importers: mini-types: ^0.1.7 minimist: ^1.2.5 miniprogram-api-typings: ^3.4.4 + picocolors: ^1.0.0 prettier: ^2.4.1 rollup: ^2.57.0 rollup-plugin-jscc: ^2.0.0 @@ -71,7 +71,6 @@ importers: '@vue/runtime-core': 3.2.26 '@vue/runtime-dom': 3.2.26 '@vue/shared': 3.2.26 - chalk: 4.1.2 core-js: 2.6.12 enquirer: 2.3.6 eslint: 7.32.0 @@ -82,6 +81,7 @@ importers: mini-types: 0.1.7 minimist: 1.2.5 miniprogram-api-typings: 3.4.4 + picocolors: 1.0.0 prettier: 2.5.1 rollup: 2.60.2 rollup-plugin-jscc: 2.0.0_rollup@2.60.2 @@ -372,7 +372,6 @@ importers: '@vue/server-renderer': 3.2.26 '@vue/shared': 3.2.26 base64url: ^3.0.1 - chalk: ^4.1.1 chokidar: ^3.5.2 compare-versions: ^3.6.0 debug: ^4.3.2 @@ -387,6 +386,7 @@ importers: merge: ^2.1.1 mime: ^3.0.0 module-alias: ^2.2.2 + picocolors: ^1.0.0 postcss: ^8.4.5 postcss-import: ^14.0.2 postcss-load-config: ^3.1.0 @@ -408,7 +408,6 @@ importers: '@vue/server-renderer': 3.2.26_vue@3.2.26 '@vue/shared': 3.2.26 base64url: 3.0.1 - chalk: 4.1.2 chokidar: 3.5.2 compare-versions: 3.6.0 debug: 4.3.3 @@ -423,6 +422,7 @@ importers: merge: 2.1.1 mime: 3.0.0 module-alias: 2.2.2 + picocolors: 1.0.0 postcss-import: 14.0.2_postcss@8.4.5 postcss-load-config: 3.1.0 postcss-modules: 4.2.2_postcss@8.4.5 @@ -806,7 +806,6 @@ importers: '@vue/compiler-sfc': 3.2.26 '@vue/shared': 3.2.26 cac: ^6.7.3 - chalk: ^4.1.1 chokidar: ^3.5.2 debug: ^4.3.2 estree-walker: ^2.0.2 @@ -814,6 +813,7 @@ importers: fs-extra: ^10.0.0 hash-sum: ^2.0.0 jsonc-parser: ^3.0.0 + picocolors: ^1.0.0 dependencies: '@babel/core': 7.16.5 '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.16.5 @@ -829,13 +829,13 @@ importers: '@vue/compiler-sfc': 3.2.26 '@vue/shared': 3.2.26 cac: 6.7.12 - chalk: 4.1.2 debug: 4.3.3 estree-walker: 2.0.2 express: 4.17.1 fs-extra: 10.0.0 hash-sum: 2.0.0 jsonc-parser: 3.0.0 + picocolors: 1.0.0 devDependencies: '@types/debug': 4.1.7 '@types/express': 4.17.13 @@ -3580,6 +3580,7 @@ packages: engines: {node: '>=8'} dependencies: color-convert: 2.0.1 + dev: true /ansi-styles/5.2.0: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} @@ -4052,6 +4053,7 @@ packages: dependencies: ansi-styles: 4.3.0 supports-color: 7.2.0 + dev: true /char-regex/1.0.2: resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} @@ -4162,12 +4164,14 @@ packages: engines: {node: '>=7.0.0'} dependencies: color-name: 1.1.4 + dev: true /color-name/1.1.3: resolution: {integrity: sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=} /color-name/1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + dev: true /colorette/2.0.16: resolution: {integrity: sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==} @@ -8500,6 +8504,7 @@ packages: engines: {node: '>=8'} dependencies: has-flag: 4.0.0 + dev: true /supports-color/8.1.1: resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==} diff --git a/scripts/apiExtractor.js b/scripts/apiExtractor.js index 3e8edace3..83f3d015b 100644 --- a/scripts/apiExtractor.js +++ b/scripts/apiExtractor.js @@ -1,29 +1,28 @@ const fs = require('fs-extra') const path = require('path') -const chalk = require('chalk') +const colors = require('picocolors') exports.extract = async function extract(target) { const pkgDir = path.resolve(`packages/${target}`) console.log() console.log( - chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`)) + colors.bold(colors.yellow(`Rolling up type definitions for ${target}...`)) ) // build types const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor') const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`) - const extractorConfig = ExtractorConfig.loadFileAndPrepare( - extractorConfigPath - ) + const extractorConfig = + ExtractorConfig.loadFileAndPrepare(extractorConfigPath) const extractorResult = Extractor.invoke(extractorConfig, { localBuild: true, - showVerboseMessages: true + showVerboseMessages: true, }) if (extractorResult.succeeded) { console.log( - chalk.bold(chalk.green(`API Extractor completed successfully.`)) + colors.bold(colors.green(`API Extractor completed successfully.`)) ) } else { console.error( diff --git a/scripts/build.js b/scripts/build.js index 641ee3658..e8d318a87 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,6 +1,6 @@ const fs = require('fs-extra') const path = require('path') -const chalk = require('chalk') +const colors = require('picocolors') const execa = require('execa') const { spawn } = require('child_process') @@ -88,7 +88,7 @@ async function buildAll(targets) { } async function build(target) { - console.log(`\n${chalk.blueBright(chalk.bold(target))}:`) + console.log(`\n${colors.bold(target)}:`) const pkgDir = path.resolve(`packages/${target}`) const pkg = require(`${pkgDir}/package.json`) diff --git a/scripts/release.js b/scripts/release.js index d83dbc0b2..5bfdbccef 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,7 +1,7 @@ const args = require('minimist')(process.argv.slice(2)) const fs = require('fs') const path = require('path') -const chalk = require('chalk') +const colors = require('picocolors') const semver = require('semver') const currentVersion = require('../package.json').version const { prompt } = require('enquirer') @@ -22,10 +22,10 @@ const bin = (name) => path.resolve(__dirname, '../node_modules/.bin/' + name) const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts }) const dryRun = (bin, args, opts = {}) => - console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts) + console.log(colors.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts) const runIfNotDry = isDryRun ? dryRun : run const getPkgRoot = (pkg) => path.resolve(__dirname, '../packages/' + pkg) -const step = (msg) => console.log(chalk.cyan(msg)) +const step = (msg) => console.log(colors.cyan(msg)) async function main() { const targetVersion = ( @@ -106,7 +106,7 @@ async function main() { if (skippedPackages.length) { console.log( - chalk.yellow( + colors.yellow( `The following packages are skipped and NOT published:\n- ${skippedPackages.join( '\n- ' )}` @@ -142,7 +142,7 @@ function updateDeps(pkg, depType, version) { packages.includes(dep.replace(/^@dcloudio\//, '')) ) { console.log( - chalk.yellow(`${pkg.name} -> ${depType} -> ${dep}@${version}`) + colors.yellow(`${pkg.name} -> ${depType} -> ${dep}@${version}`) ) deps[dep] = version } @@ -181,10 +181,10 @@ async function publishPackage(pkgName, version, runIfNotDry) { stdio: 'pipe', } ) - console.log(chalk.green(`Successfully published ${pkgName}@${version}`)) + console.log(colors.green(`Successfully published ${pkgName}@${version}`)) } catch (e) { if (e.stderr.match(/previously published/)) { - console.log(chalk.red(`Skipping already published: ${pkgName}`)) + console.log(colors.red(`Skipping already published: ${pkgName}`)) } else { throw e } diff --git a/scripts/updateVersion.js b/scripts/updateVersion.js index 1c7fc463b..73e4d4d8b 100644 --- a/scripts/updateVersion.js +++ b/scripts/updateVersion.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const chalk = require('chalk') +const colors = require('picocolors') const { prompt } = require('enquirer') const { resolvePackages } = require('./utils') const args = process.argv.slice(2) @@ -38,7 +38,7 @@ function updateDeps(pkg, depType, module, oldVersion, newVersion) { if (deps[name].includes(oldVersion)) { deps[name] = deps[name].replace(oldVersion, newVersion) console.log( - chalk.yellow(`${pkg.name} -> ${depType} -> ${name}@${newVersion}`) + colors.yellow(`${pkg.name} -> ${depType} -> ${name}@${newVersion}`) ) } } diff --git a/scripts/utils.js b/scripts/utils.js index 3b253b94f..5ab4f7859 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const chalk = require('chalk') +const colors = require('picocolors') const priority = { 'uni-shared': 100, @@ -65,8 +65,8 @@ exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => { } else { console.log() console.error( - ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red( - `Target ${chalk.underline(partialTargets)} not found!` + ` ${colors.bgRed.white(' ERROR ')} ${colors.red( + `Target ${colors.underline(partialTargets)} not found!` )}` ) console.log() diff --git a/scripts/verifyCommit.js b/scripts/verifyCommit.js index d57497dea..81c8ec683 100644 --- a/scripts/verifyCommit.js +++ b/scripts/verifyCommit.js @@ -1,27 +1,26 @@ // Invoked on the commit-msg git hook by yorkie. -const chalk = require('chalk') +const colors = require('picocolors') const msgPath = process.env.GIT_PARAMS -const msg = require('fs') - .readFileSync(msgPath, 'utf-8') - .trim() +const msg = require('fs').readFileSync(msgPath, 'utf-8').trim() -const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ +const commitRE = + /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ if (!commitRE.test(msg)) { console.log() console.error( - ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red( + ` ${colors.bgRed.white(' ERROR ')} ${colors.red( `invalid commit message format.` )}\n\n` + - chalk.red( + colors.red( ` Proper commit message format is required for automated changelog generation. Examples:\n\n` ) + - ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` + - ` ${chalk.green( + ` ${colors.green(`feat(compiler): add 'comments' option`)}\n` + + ` ${colors.green( `fix(v-model): handle events on blur (close #28)` )}\n\n` + - chalk.red(` See .github/commit-convention.md for more details.\n`) + colors.red(` See .github/commit-convention.md for more details.\n`) ) process.exit(1) } -- GitLab