Skip to content

Commit 010a6d9

Browse files
authored
Merge pull request #356 from emberjs/picocolors
[e18e] swap from chalk to native styleText
2 parents 927a0de + 15e1843 commit 010a6d9

File tree

6 files changed

+77
-43
lines changed

6 files changed

+77
-43
lines changed

commands/index.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
const VersionChecker = require('ember-cli-version-checker');
55

6-
const chalk = require('chalk');
76
const fs = require('fs');
87
const mkdirp = require('mkdirp');
98
const path = require('path');
9+
const { styleText } = require('node:util');
1010
const strip = require('../utils').strip;
1111
const getConfigPath = require('../utils').getConfigPath;
1212

@@ -15,9 +15,16 @@ const FEATURES = require('../features');
1515
const USAGE_MESSAGE = strip`
1616
Usage:
1717
18-
To list all available features, run ${chalk.bold('ember feature:list')}.
19-
To enable a feature, run ${chalk.bold('ember feature:enable some-feature')}.
20-
To disable a feature, run ${chalk.bold(
18+
To list all available features, run ${styleText(
19+
'bold',
20+
'ember feature:list'
21+
)}.
22+
To enable a feature, run ${styleText(
23+
'bold',
24+
'ember feature:enable some-feature'
25+
)}.
26+
To disable a feature, run ${styleText(
27+
'bold',
2128
'ember feature:disable some-feature'
2229
)}.
2330
`;
@@ -53,7 +60,10 @@ const SHARED = {
5360

5461
if (feature === undefined) {
5562
console.log(
56-
chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`)
63+
styleText(
64+
'red',
65+
`Error: ${styleText('bold', name)} is not a valid feature.\n`
66+
)
5767
);
5868
return LIST_FEATURES.run.apply(this);
5969
}
@@ -64,8 +74,9 @@ const SHARED = {
6474
);
6575
if (!this._isFeatureAvailable(feature)) {
6676
console.log(
67-
chalk.red(
68-
`Error: ${chalk.bold(name)} is only available in Ember ${
77+
styleText(
78+
'red',
79+
`Error: ${styleText('bold', name)} is only available in Ember ${
6980
feature.since
7081
} or above.`
7182
)
@@ -94,8 +105,10 @@ const SHARED = {
94105
let state = value ? 'Enabled' : 'Disabled';
95106

96107
console.log(
97-
chalk.green(
98-
`${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline(
108+
styleText(
109+
'green',
110+
`${state} ${styleText('bold', name)}. Be sure to commit ${styleText(
111+
'underline',
99112
'config/optional-features.json'
100113
)} to source control!`
101114
)
@@ -135,10 +148,14 @@ const LIST_FEATURES = Object.assign(
135148
if (this._isFeatureAvailable(feature)) {
136149
console.log(strip`
137150
${INDENT_START}
138-
${chalk.bold(key)} ${chalk.cyan(`(Default: ${feature.default})`)}
151+
${styleText('bold', key)} ${styleText(
152+
'cyan',
153+
`(Default: ${feature.default})`
154+
)}
139155
${feature.description}
140-
${chalk.gray(
141-
`More information: ${chalk.underline(feature.url)}`
156+
${styleText(
157+
'gray',
158+
`More information: ${styleText('underline', feature.url)}`
142159
)}`);
143160

144161
hasFeatures = true;
@@ -149,10 +166,13 @@ const LIST_FEATURES = Object.assign(
149166
console.log();
150167
} else {
151168
console.log(
152-
chalk.gray(strip`
169+
styleText(
170+
'gray',
171+
strip`
153172
${INDENT_START}
154173
No optional features available for your current Ember version.
155-
`)
174+
`
175+
)
156176
);
157177
}
158178
},

features/application-template-wrapper.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable no-console */
22
'use strict';
33

4-
const chalk = require('chalk');
54
const fs = require('fs');
65
const p = require('util').promisify;
76
const path = require('path');
7+
const { styleText } = require('node:util');
88
const strip = require('../utils').strip;
99

1010
module.exports = {
@@ -27,8 +27,10 @@ module.exports = {
2727
if (isPod) {
2828
// TODO
2929
console.log(
30-
chalk.yellow(
31-
`${chalk.bold(
30+
styleText(
31+
'yellow',
32+
`${styleText(
33+
'bold',
3234
'Note:'
3335
)} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n`
3436
)
@@ -54,7 +56,7 @@ module.exports = {
5456

5557
if (shouldRunCodemod === undefined) {
5658
console.log(strip`
57-
Disabling ${chalk.bold('application-template-wrapper')}...
59+
Disabling ${styleText('bold', 'application-template-wrapper')}...
5860
5961
This will remove the \`<div class="ember-view">\` wrapper for the top-level application template (\`${templatePath}\`).
6062
@@ -66,7 +68,8 @@ module.exports = {
6668
6769
- Depending on your choice of \`rootElement\`, your app might not be wrapped inside a block-level element anymore.
6870
69-
For more information, see ${chalk.underline(
71+
For more information, see ${styleText(
72+
'underline',
7073
'https://github.com/emberjs/rfcs/pull/280'
7174
)}.
7275
@@ -113,7 +116,7 @@ module.exports = {
113116
content.push('');
114117
}
115118

116-
console.log(` ${chalk.yellow('overwrite')} ${templatePath}`);
119+
console.log(` ${styleText('yellow', 'overwrite')} ${templatePath}`);
117120

118121
await p(fs.writeFile)(templatePath, content.join('\n'), {
119122
encoding: 'UTF-8',

features/template-only-glimmer-components.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
'use strict';
33

4-
const chalk = require('chalk');
4+
const { styleText } = require('node:util');
55
const fs = require('fs');
66
const globSync = require('glob').globSync;
77
const mkdirp = require('mkdirp');
@@ -38,8 +38,10 @@ module.exports = {
3838
if (podModulePrefix) {
3939
if (!modulePrefix || !podModulePrefix.startsWith(`${modulePrefix}/`)) {
4040
console.log(
41-
chalk.yellow(
42-
`${chalk.bold(
41+
styleText(
42+
'yellow',
43+
`${styleText(
44+
'bold',
4345
'Note:'
4446
)} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`
4547
)
@@ -50,8 +52,10 @@ module.exports = {
5052
podsFolder = podModulePrefix.slice(modulePrefix.length + 1);
5153
if (!podsFolder) {
5254
console.log(
53-
chalk.yellow(
54-
`${chalk.bold(
55+
styleText(
56+
'yellow',
57+
`${styleText(
58+
'bold',
5559
'Note:'
5660
)} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`
5761
)
@@ -144,7 +148,7 @@ module.exports = {
144148

145149
if (shouldRunCodemod === undefined) {
146150
console.log(strip`
147-
Enabling ${chalk.bold('template-only-glimmer-components')}...
151+
Enabling ${styleText('bold', 'template-only-glimmer-components')}...
148152
149153
This will change the semantics for template-only components (components without a \`.js\` file).
150154
@@ -156,13 +160,16 @@ module.exports = {
156160
157161
- Passing classes in the invocation (i.e. \`{{my-component class="..."}}\`) will not work, since there is no wrapper element to apply the classes to.
158162
159-
For more information, see ${chalk.underline(
163+
For more information, see ${styleText(
164+
'underline',
160165
'https://github.com/emberjs/rfcs/pull/278'
161166
)}.
162167
163-
While these changes may be desirable for ${chalk.italic(
168+
While these changes may be desirable for ${styleText(
169+
'italic',
164170
'new components'
165-
)}, they may unexpectedly break the styling or runtime behavior of your ${chalk.italic(
171+
)}, they may unexpectedly break the styling or runtime behavior of your ${styleText(
172+
'italic',
166173
'existing components'
167174
)}.
168175
@@ -173,9 +180,13 @@ module.exports = {
173180
for (let i = 0; i < templates.length; i++) {
174181
console.log(strip`
175182
${INDENT_START}
176-
- ${chalk.underline(templates[i])}
177-
${chalk.gray(
178-
`(Recommendation: add ${chalk.cyan.underline(components[i])})`
183+
- ${styleText('underline', templates[i])}
184+
${styleText(
185+
'gray',
186+
`(Recommendation: add ${styleText(
187+
'cyan',
188+
styleText('underline', components[i])
189+
)})`
179190
)}
180191
`);
181192
}
@@ -195,7 +206,7 @@ module.exports = {
195206
if (shouldRunCodemod) {
196207
for (let i = 0; i < components.length; i++) {
197208
let componentPath = components[i];
198-
console.log(` ${chalk.green('create')} ${componentPath}`);
209+
console.log(` ${styleText('green', 'create')} ${componentPath}`);
199210
let absolutePath = path.join(project.root, componentPath);
200211
await mkdirp(path.dirname(absolutePath));
201212
await p(fs.writeFile)(absolutePath, ComponentFile, {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"test": "qunit tests/**/*-test.js"
2525
},
2626
"dependencies": {
27-
"chalk": "^4.1.2",
2827
"ember-cli-version-checker": "^5.1.2",
2928
"glob": "^13.0.1",
3029
"inquirer": "^13.2.2",

pnpm-lock.yaml

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

tests/commands-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const execa = require('execa');
88
const mkdirp = require('mkdirp');
99
const p = require('path').join;
1010
const strip = require('../utils').strip;
11+
const { stripVTControlCharacters: stripAnsi } = require('node:util');
1112

1213
const FEATURES = require('../features');
1314

@@ -99,15 +100,17 @@ QUnit.module('commands', (hooks) => {
99100
let feature = FEATURES[key];
100101

101102
assert.ok(
102-
result.stdout.indexOf(`${key} (Default: ${feature.default}`) >= 0,
103+
stripAnsi(result.stdout).indexOf(
104+
`${key} (Default: ${feature.default}`
105+
) >= 0,
103106
`it should include ${key} and its default value`
104107
);
105108
assert.ok(
106-
result.stdout.indexOf(feature.description) >= 0,
109+
stripAnsi(result.stdout).indexOf(feature.description) >= 0,
107110
`it should include the description for ${key}`
108111
);
109112
assert.ok(
110-
result.stdout.indexOf(feature.url) >= 0,
113+
stripAnsi(result.stdout).indexOf(feature.url) >= 0,
111114
`it should include the URL for ${key}`
112115
);
113116
});
@@ -190,7 +193,8 @@ QUnit.module('commands', (hooks) => {
190193
'it should print an error'
191194
);
192195
assert.ok(
193-
result.stdout.indexOf('foo-bar is not a valid feature') >= 0,
196+
stripAnsi(result.stdout).indexOf('foo-bar is not a valid feature') >=
197+
0,
194198
'it should print an error'
195199
);
196200
});
@@ -216,11 +220,11 @@ QUnit.module('commands', (hooks) => {
216220
);
217221

218222
assert.ok(
219-
result.stdout.indexOf('Error:') >= 0,
223+
stripAnsi(result.stdout).indexOf('Error:') >= 0,
220224
'it should print an error'
221225
);
222226
assert.ok(
223-
result.stdout.indexOf(
227+
stripAnsi(result.stdout).indexOf(
224228
'application-template-wrapper is only available in Ember 3.1.0 or above'
225229
) >= 0,
226230
'it should print an error'

0 commit comments

Comments
 (0)