Skip to content

Commit aa1d65c

Browse files
authored
chore: switch from colors to chalk (#1895)
* swap out dependencies * reimpl * add changelog entry * remove unused import
1 parent 32f09ce commit aa1d65c

File tree

7 files changed

+36
-44
lines changed

7 files changed

+36
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber.
99

1010
## [Unreleased]
11+
### Changed
12+
- Switch from `colors` to `chalk` for terminal coloring ([#1895](https://github.com/cucumber/cucumber-js/pull/1895))
1113

1214
## [8.0.0-rc.2] - 2022-01-10
1315
### Added

features/support/warn_user_about_enabling_developer_mode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { reindent } from 'reindent-template-literals'
2-
import colors from 'colors/safe'
2+
import chalk from 'chalk'
33

44
export function warnUserAboutEnablingDeveloperMode(error: any): void {
55
if (!(error?.code === 'EPERM')) {
@@ -10,7 +10,7 @@ export function warnUserAboutEnablingDeveloperMode(error: any): void {
1010
}
1111

1212
console.error(
13-
colors.red(
13+
chalk.red(
1414
reindent(`
1515
Error: Unable to run feature tests!
1616

features/support/world.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { execFile } from 'child_process'
33
import { expect } from 'chai'
44
import toString from 'stream-to-string'
55
import { PassThrough, pipeline, Writable } from 'stream'
6-
import colors from 'colors/safe'
6+
import stripAnsi from 'strip-ansi'
77
import fs from 'fs'
88
import path from 'path'
99
import VError from 'verror'
@@ -122,7 +122,7 @@ export class World {
122122
error: result.error,
123123
errorOutput: result.stderr,
124124
envelopes,
125-
output: colors.strip(result.stdout),
125+
output: stripAnsi(result.stdout),
126126
}
127127
this.verifiedLastRunError = false
128128
expect(this.lastRun.output).to.not.include('Unhandled rejection')

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@
194194
"@cucumber/tag-expressions": "4.1.0",
195195
"assertion-error-formatter": "^3.0.0",
196196
"capital-case": "^1.0.4",
197+
"chalk": "^4.1.2",
197198
"cli-table3": "0.6.1",
198-
"colors": "1.4.0",
199199
"commander": "^8.0.0",
200200
"duration": "^0.2.2",
201201
"durations": "^3.4.2",
@@ -263,6 +263,7 @@
263263
"sinon-chai": "3.7.0",
264264
"stream-buffers": "3.0.2",
265265
"stream-to-string": "1.2.0",
266+
"strip-ansi": "^6.0.1",
266267
"ts-node": "10.4.0",
267268
"tsd": "0.19.1",
268269
"typescript": "4.5.4"

src/cli/publish_banner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import colors from 'colors/safe'
1+
import chalk from 'chalk'
22
import Table from 'cli-table3'
33

44
const underlineBoldCyan = (x: string): string =>
5-
colors.underline(colors.bold(colors.cyan(x)))
5+
chalk.underline(chalk.bold(chalk.cyan(x)))
66

77
const formattedReportUrl = underlineBoldCyan('https://reports.cucumber.io')
88
const formattedEnv =
9-
colors.cyan('CUCUMBER_PUBLISH_ENABLED') + '=' + colors.cyan('true')
9+
chalk.cyan('CUCUMBER_PUBLISH_ENABLED') + '=' + chalk.cyan('true')
1010
const formattedMoreInfoUrl = underlineBoldCyan(
1111
'https://cucumber.io/docs/cucumber/environment-variables/'
1212
)
1313

1414
const text = `\
1515
Share your Cucumber Report with your team at ${formattedReportUrl}
1616
17-
Command line option: ${colors.cyan('--publish')}
17+
Command line option: ${chalk.cyan('--publish')}
1818
Environment variable: ${formattedEnv}
1919
2020
More information at ${formattedMoreInfoUrl}
2121
22-
To disable this message, add this to your ${colors.bold('./cucumber.js')}:
23-
${colors.bold("module.exports = { default: '--publish-quiet' }")}`
22+
To disable this message, add this to your ${chalk.bold('./cucumber.js')}:
23+
${chalk.bold("module.exports = { default: '--publish-quiet' }")}`
2424

2525
const table = new Table({
2626
style: {

src/formatter/get_color_fns.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import colors from 'colors/safe'
1+
import chalk from 'chalk'
22
import { TestStepResultStatus } from '@cucumber/messages'
33

4-
colors.enable()
5-
64
export type IColorFn = (text: string) => string
75

86
export interface IColorFns {
@@ -20,21 +18,21 @@ export default function getColorFns(enabled: boolean): IColorFns {
2018
return {
2119
forStatus(status: TestStepResultStatus) {
2220
return {
23-
AMBIGUOUS: colors.red.bind(colors),
24-
FAILED: colors.red.bind(colors),
25-
PASSED: colors.green.bind(colors),
26-
PENDING: colors.yellow.bind(colors),
27-
SKIPPED: colors.cyan.bind(colors),
28-
UNDEFINED: colors.yellow.bind(colors),
29-
UNKNOWN: colors.yellow.bind(colors),
21+
AMBIGUOUS: chalk.red.bind(chalk),
22+
FAILED: chalk.red.bind(chalk),
23+
PASSED: chalk.green.bind(chalk),
24+
PENDING: chalk.yellow.bind(chalk),
25+
SKIPPED: chalk.cyan.bind(chalk),
26+
UNDEFINED: chalk.yellow.bind(chalk),
27+
UNKNOWN: chalk.yellow.bind(chalk),
3028
}[status]
3129
},
32-
location: colors.gray.bind(colors),
33-
tag: colors.cyan.bind(colors),
34-
diffAdded: colors.green.bind(colors),
35-
diffRemoved: colors.red.bind(colors),
36-
errorMessage: colors.red.bind(colors),
37-
errorStack: colors.grey.bind(colors),
30+
location: chalk.gray.bind(chalk),
31+
tag: chalk.cyan.bind(chalk),
32+
diffAdded: chalk.green.bind(chalk),
33+
diffRemoved: chalk.red.bind(chalk),
34+
errorMessage: chalk.red.bind(chalk),
35+
errorStack: chalk.grey.bind(chalk),
3836
}
3937
} else {
4038
return {

0 commit comments

Comments
 (0)