diff --git a/.eslintrc.js b/.eslintrc.js index 924554b3f3bb5d6d4954828834f7049838f6396d..1579b81e3cee8060fd361f77207745fae6241818 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 de9effb3eb6ac7217b0f520a8540281641469675..e92a52ed8c3a0482a915ae4589b4a68658bc2d90 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 0aee08b912eed5febd8ba22f1c4a7a4b06520d15..1decfe33274338872541283451a5c26152d949da 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 91a339c1d4836774ea8d71929e5180cb5ba68c96..5c7674e137e52118e47900356fb464e420f47b94 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 e4ef6f279808c1d2d728213e12b01740db71af1d..8eb9a28fe1744cf830367ff885717197a5ed5c55 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 e7f8195996787b37cdef1ff064b5585145e3f856..54a1b379c784b234eba89393326fab2582d06d0e 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 3660f344082c58cd6b2df1c897bf93ad6e11d47f..4293fe879a03543c7214dc77d6424908eb195979 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 7b1aaf3f0e61ee215fbd6225f203a37e2765e0a0..2c8497eecebe9b4e5e06faad97508630cc5b79e0 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 ae5ba717cec6e20790aa299b92dccbc4e6c1b09f..d8d2a9b365d4839499d8a66c5d4d8e3a4e606dd2 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 3e8edace36ed3f5388daa4bd5ec9b02b7c341f5e..83f3d015be04b34cae3d17e4b72d025c72f12ebf 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 641ee3658211e9852e792a3c77bb2cdcd12a4633..e8d318a87e7f7b8714523ebb962c79227ddf9357 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 d83dbc0b25e83cd821576f1d7bc348d5212acadc..5bfdbccefe4029d7590bf1ceeb51772671c8270a 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 1c7fc463b9dc53d48f03fee284d7a285a5ac53ed..73e4d4d8b23c5470a221afe6364bd67706701527 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 3b253b94fdb92fff5a8477f1f467d1792652c4af..5ab4f78599e5aecc10b056ee73d7f61a8d40369b 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 d57497dea4bfbd8e72e540599dbd4aa3c2fcd994..81c8ec683c06e79f26f9a63eaa738b0cbceef782 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) }