Skip to content

Commit be6bfd2

Browse files
committed
perf: replace ansis with util.styleText
closes #530
1 parent 033daca commit be6bfd2

23 files changed

Lines changed: 145 additions & 98 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ tsdown detects `package.json` in the working directory to:
302302
### Utilities (`src/utils/`)
303303

304304
- `fs.ts` - File system utilities (`fsExists()`, `fsStat()`, `fsRemove()`); use instead of Node.js fs directly
305-
- `logger.ts` - Structured logging (`logger.error()`, `.warn()`, `.info()`, `.debug()`) with colours via `ansis`; respects `logLevel` config
305+
- `logger.ts` - Structured logging (`logger.error()`, `.warn()`, `.info()`, `.debug()`) with colours via `util.styleText`; respects `logLevel` config
306306
- `chunks.ts` - Chunk manipulation utilities
307307
- `ci.ts` - CI environment detection
308308
- `format.ts` - Formatting utilities (byte sizes, etc.)

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
}
121121
},
122122
"dependencies": {
123-
"ansis": "catalog:prod",
124123
"cac": "catalog:prod",
125124
"defu": "catalog:prod",
126125
"empathic": "catalog:prod",

‎packages/migrate/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"dependencies": {
5454
"@antfu/ni": "catalog:migrate",
5555
"@ast-grep/napi": "catalog:migrate",
56-
"ansis": "catalog:prod",
5756
"cac": "catalog:prod",
5857
"consola": "catalog:migrate",
5958
"diff": "catalog:migrate",

‎packages/migrate/src/index.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import process from 'node:process'
22
import { getCliCommand, parseNi, run } from '@antfu/ni'
3-
import { green, greenBright, underline } from 'ansis'
43
import consola from 'consola'
54
import { glob } from 'tinyglobby'
5+
import { styleText } from '../../../src/utils/style.ts'
66
import { migratePackageJson } from './helpers/package-json.ts'
77
import { migrateTsupConfig } from './helpers/tsup-config.ts'
88

@@ -16,8 +16,8 @@ export async function migrate({ dirs, dryRun }: MigrateOptions): Promise<void> {
1616
consola.info('Dry run enabled. No changes were made.')
1717
} else {
1818
const confirm = await consola.prompt(
19-
`Before proceeding, review the migration guide at ${underline`https://tsdown.dev/guide/migrate-from-tsup`}, as this process will modify your files.\n` +
20-
`Uncommitted changes will be lost. Use the ${green`--dry-run`} flag to preview changes without applying them.\n\n` +
19+
`Before proceeding, review the migration guide at ${styleText.underline(`https://tsdown.dev/guide/migrate-from-tsup`)}, as this process will modify your files.\n` +
20+
`Uncommitted changes will be lost. Use the ${styleText.green(`--dry-run`)} flag to preview changes without applying them.\n\n` +
2121
'Continue?',
2222
{ type: 'confirm' },
2323
)
@@ -52,7 +52,7 @@ export async function migrate({ dirs, dryRun }: MigrateOptions): Promise<void> {
5252
for (const dir of cwds) {
5353
process.chdir(dir)
5454

55-
const dirLabel = greenBright(dir)
55+
const dirLabel = styleText.greenBright(dir)
5656
consola.info(`Processing ${dirLabel}`)
5757

5858
let migrated = await migratePackageJson(dryRun)

‎packages/migrate/src/utils.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dim, green, red } from 'ansis'
1+
import { styleText } from '../../../src/utils/style.ts'
22

33
// rename key but keep order
44
export function renameKey(
@@ -20,7 +20,12 @@ export function renameKey(
2020

2121
export function outputDiff(text: string): void {
2222
for (const line of text.split('\n')) {
23-
const color = line[0] === '+' ? green : line[0] === '-' ? red : dim
23+
const color =
24+
line[0] === '+'
25+
? styleText.green
26+
: line[0] === '-'
27+
? styleText.red
28+
: styleText.dim
2429
console.info(color(line))
2530
}
2631
}

‎pnpm-lock.yaml‎

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ catalogs:
7070
publint: ^0.3.23
7171
unplugin-unused: ^0.6.0
7272
prod:
73-
ansis: ^4.3.1
7473
cac: ^7.0.0
7574
defu: ^6.1.7
7675
empathic: ^2.0.1

‎src/build.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { bold, green } from 'ansis'
21
import { clearRequireCache } from 'import-without-cache'
32
import {
43
build as rolldownBuild,
@@ -33,6 +32,7 @@ import {
3332
} from './utils/chunks.ts'
3433
import { debounce, typeAssert } from './utils/general.ts'
3534
import { globalLogger } from './utils/logger.ts'
35+
import { styleText } from './utils/style.ts'
3636

3737
/**
3838
* Build with tsdown.
@@ -175,7 +175,7 @@ async function buildSingle(
175175
if (!watch) {
176176
logger.success(
177177
config.nameLabel,
178-
`Build complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`,
178+
`Build complete in ${styleText.green(`${Math.round(performance.now() - startTime)}ms`)}`,
179179
)
180180
await postBuild()
181181
}
@@ -240,7 +240,7 @@ async function buildSingle(
240240
if (changedFile.length) {
241241
logger.clearScreen('info')
242242
logger.info(
243-
`Found ${bold(changedFile.join(', '))} changed, rebuilding...`,
243+
`Found ${styleText.bold(changedFile.join(', '))} changed, rebuilding...`,
244244
)
245245
}
246246
changedFile.length = 0

‎src/cli.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable unicorn/no-top-level-side-effects */
22
import process from 'node:process'
3-
import { blue, hex } from 'ansis'
43
import { cac } from 'cac'
54
import { VERSION as rolldownVersion } from 'rolldown'
65
import { x } from 'tinyexec'
76
import pkg from '../package.json' with { type: 'json' }
87
import { enableDebug } from './features/debug.ts'
98
import { globalLogger } from './utils/logger.ts'
9+
import { styleText } from './utils/style.ts'
1010
import type { UserConfig } from './config.ts'
1111

1212
const cli = cac('tsdown')
@@ -85,7 +85,9 @@ cli
8585
.action(async (input: string[], flags: UserConfig) => {
8686
globalLogger.level = flags.logLevel || 'info'
8787
globalLogger.info(
88-
`${blue`tsdown v${pkg.version}`} powered by ${hex('#ff7e17')`rolldown v${rolldownVersion}`}`,
88+
`${styleText.blue(`tsdown v${pkg.version}`)} powered by ${styleText[
89+
'#ff7e17,yellow'
90+
](`rolldown v${rolldownVersion}`)}`,
8991
)
9092
const { build } = await import('./build.ts')
9193
if (input.length > 0) flags.entry = input

‎src/config/file.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { readFile } from 'node:fs/promises'
22
import path from 'node:path'
33
import process from 'node:process'
44
import { pathToFileURL } from 'node:url'
5-
import { underline } from 'ansis'
65
import { depsStore, init, isSupported } from 'import-without-cache'
76
import { createDebug } from 'obug'
87
import { createConfigCoreLoader } from 'unconfig-core'
98
import { isInCI } from '../utils/ci.ts'
109
import { fsStat } from '../utils/fs.ts'
1110
import { importWithError, toArray } from '../utils/general.ts'
1211
import { globalLogger } from '../utils/logger.ts'
12+
import { styleText } from '../utils/style.ts'
1313
import type { InlineConfig, UserConfig, UserConfigExport } from './types.ts'
1414
import type {
1515
ConfigEnv,
@@ -45,7 +45,7 @@ export async function loadViteConfig(
4545
config: [exported, deps],
4646
source,
4747
} = result
48-
globalLogger.info(`Using Vite config: ${underline(source)}`)
48+
globalLogger.info(`Using Vite config: ${styleText.underline(source)}`)
4949

5050
exported = await exported
5151
if (typeof exported === 'function') {
@@ -130,7 +130,7 @@ export async function loadConfigFile(
130130
} = result)
131131

132132
globalLogger.info(
133-
`config file: ${underline(file)}`,
133+
`config file: ${styleText.underline(file)}`,
134134
loader === 'native' ? '' : `(${loader})`,
135135
)
136136

0 commit comments

Comments
 (0)