From e1535eb35de1943dc01478779b855bb4610f4bb0 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sun, 8 Feb 2026 15:16:52 +0000 Subject: [PATCH 1/2] swap from chalk to native styleText --- commands/index.js | 48 ++++++++++++++------ features/application-template-wrapper.js | 15 +++--- features/template-only-glimmer-components.js | 37 +++++++++------ package.json | 1 - pnpm-lock.yaml | 3 -- 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/commands/index.js b/commands/index.js index 20ac85c..08e81e8 100644 --- a/commands/index.js +++ b/commands/index.js @@ -3,10 +3,10 @@ const VersionChecker = require('ember-cli-version-checker'); -const chalk = require('chalk'); const fs = require('fs'); const mkdirp = require('mkdirp'); const path = require('path'); +const { styleText } = require('node:util'); const strip = require('../utils').strip; const getConfigPath = require('../utils').getConfigPath; @@ -15,9 +15,16 @@ const FEATURES = require('../features'); const USAGE_MESSAGE = strip` Usage: - To list all available features, run ${chalk.bold('ember feature:list')}. - To enable a feature, run ${chalk.bold('ember feature:enable some-feature')}. - To disable a feature, run ${chalk.bold( + To list all available features, run ${styleText( + 'bold', + 'ember feature:list' + )}. + To enable a feature, run ${styleText( + 'bold', + 'ember feature:enable some-feature' + )}. + To disable a feature, run ${styleText( + 'bold', 'ember feature:disable some-feature' )}. `; @@ -53,7 +60,10 @@ const SHARED = { if (feature === undefined) { console.log( - chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`) + styleText( + 'red', + `Error: ${styleText('bold', name)} is not a valid feature.\n` + ) ); return LIST_FEATURES.run.apply(this); } @@ -64,8 +74,9 @@ const SHARED = { ); if (!this._isFeatureAvailable(feature)) { console.log( - chalk.red( - `Error: ${chalk.bold(name)} is only available in Ember ${ + styleText( + 'red', + `Error: ${styleText('bold', name)} is only available in Ember ${ feature.since } or above.` ) @@ -94,8 +105,10 @@ const SHARED = { let state = value ? 'Enabled' : 'Disabled'; console.log( - chalk.green( - `${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline( + styleText( + 'green', + `${state} ${styleText('bold', name)}. Be sure to commit ${styleText( + 'underline', 'config/optional-features.json' )} to source control!` ) @@ -135,10 +148,14 @@ const LIST_FEATURES = Object.assign( if (this._isFeatureAvailable(feature)) { console.log(strip` ${INDENT_START} - ${chalk.bold(key)} ${chalk.cyan(`(Default: ${feature.default})`)} + ${styleText('bold', key)} ${styleText( + 'cyan', + `(Default: ${feature.default})` + )} ${feature.description} - ${chalk.gray( - `More information: ${chalk.underline(feature.url)}` + ${styleText( + 'gray', + `More information: ${styleText('underline', feature.url)}` )}`); hasFeatures = true; @@ -149,10 +166,13 @@ const LIST_FEATURES = Object.assign( console.log(); } else { console.log( - chalk.gray(strip` + styleText( + 'gray', + strip` ${INDENT_START} No optional features available for your current Ember version. - `) + ` + ) ); } }, diff --git a/features/application-template-wrapper.js b/features/application-template-wrapper.js index 96ad3ed..db67cfc 100644 --- a/features/application-template-wrapper.js +++ b/features/application-template-wrapper.js @@ -1,10 +1,10 @@ /* eslint-disable no-console */ 'use strict'; -const chalk = require('chalk'); const fs = require('fs'); const p = require('util').promisify; const path = require('path'); +const { styleText } = require('node:util'); const strip = require('../utils').strip; module.exports = { @@ -27,8 +27,10 @@ module.exports = { if (isPod) { // TODO console.log( - chalk.yellow( - `${chalk.bold( + styleText( + 'yellow', + `${styleText( + 'bold', 'Note:' )} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n` ) @@ -54,7 +56,7 @@ module.exports = { if (shouldRunCodemod === undefined) { console.log(strip` - Disabling ${chalk.bold('application-template-wrapper')}... + Disabling ${styleText('bold', 'application-template-wrapper')}... This will remove the \`
\` wrapper for the top-level application template (\`${templatePath}\`). @@ -66,7 +68,8 @@ module.exports = { - Depending on your choice of \`rootElement\`, your app might not be wrapped inside a block-level element anymore. - For more information, see ${chalk.underline( + For more information, see ${styleText( + 'underline', 'https://github.com/emberjs/rfcs/pull/280' )}. @@ -113,7 +116,7 @@ module.exports = { content.push(''); } - console.log(` ${chalk.yellow('overwrite')} ${templatePath}`); + console.log(` ${styleText('yellow', 'overwrite')} ${templatePath}`); await p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8', diff --git a/features/template-only-glimmer-components.js b/features/template-only-glimmer-components.js index 7fb4c6f..ea50cbd 100644 --- a/features/template-only-glimmer-components.js +++ b/features/template-only-glimmer-components.js @@ -1,7 +1,7 @@ /* eslint-disable no-console */ 'use strict'; -const chalk = require('chalk'); +const { styleText } = require('node:util'); const fs = require('fs'); const globSync = require('glob').globSync; const mkdirp = require('mkdirp'); @@ -38,8 +38,10 @@ module.exports = { if (podModulePrefix) { if (!modulePrefix || !podModulePrefix.startsWith(`${modulePrefix}/`)) { console.log( - chalk.yellow( - `${chalk.bold( + styleText( + 'yellow', + `${styleText( + 'bold', 'Note:' )} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n` ) @@ -50,8 +52,10 @@ module.exports = { podsFolder = podModulePrefix.slice(modulePrefix.length + 1); if (!podsFolder) { console.log( - chalk.yellow( - `${chalk.bold( + styleText( + 'yellow', + `${styleText( + 'bold', 'Note:' )} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n` ) @@ -144,7 +148,7 @@ module.exports = { if (shouldRunCodemod === undefined) { console.log(strip` - Enabling ${chalk.bold('template-only-glimmer-components')}... + Enabling ${styleText('bold', 'template-only-glimmer-components')}... This will change the semantics for template-only components (components without a \`.js\` file). @@ -156,13 +160,16 @@ module.exports = { - Passing classes in the invocation (i.e. \`{{my-component class="..."}}\`) will not work, since there is no wrapper element to apply the classes to. - For more information, see ${chalk.underline( + For more information, see ${styleText( + 'underline', 'https://github.com/emberjs/rfcs/pull/278' )}. - While these changes may be desirable for ${chalk.italic( + While these changes may be desirable for ${styleText( + 'italic', 'new components' - )}, they may unexpectedly break the styling or runtime behavior of your ${chalk.italic( + )}, they may unexpectedly break the styling or runtime behavior of your ${styleText( + 'italic', 'existing components' )}. @@ -173,9 +180,13 @@ module.exports = { for (let i = 0; i < templates.length; i++) { console.log(strip` ${INDENT_START} - - ${chalk.underline(templates[i])} - ${chalk.gray( - `(Recommendation: add ${chalk.cyan.underline(components[i])})` + - ${styleText('underline', templates[i])} + ${styleText( + 'gray', + `(Recommendation: add ${styleText( + 'cyan', + styleText('underline', components[i]) + )})` )} `); } @@ -195,7 +206,7 @@ module.exports = { if (shouldRunCodemod) { for (let i = 0; i < components.length; i++) { let componentPath = components[i]; - console.log(` ${chalk.green('create')} ${componentPath}`); + console.log(` ${styleText('green', 'create')} ${componentPath}`); let absolutePath = path.join(project.root, componentPath); await mkdirp(path.dirname(absolutePath)); await p(fs.writeFile)(absolutePath, ComponentFile, { diff --git a/package.json b/package.json index 975058f..de30671 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "test": "qunit tests/**/*-test.js" }, "dependencies": { - "chalk": "^4.1.2", "ember-cli-version-checker": "^5.1.2", "glob": "^13.0.1", "inquirer": "^13.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7de816e..0d8f290 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: dependencies: - chalk: - specifier: ^4.1.2 - version: 4.1.2 ember-cli-version-checker: specifier: ^5.1.2 version: 5.1.2 From 15e1843ab425981d775c50db5d4e634017309441 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sun, 8 Feb 2026 16:32:04 +0000 Subject: [PATCH 2/2] stripAnsi for tests --- tests/commands-test.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/commands-test.js b/tests/commands-test.js index 25c17a2..e0a61ab 100644 --- a/tests/commands-test.js +++ b/tests/commands-test.js @@ -8,6 +8,7 @@ const execa = require('execa'); const mkdirp = require('mkdirp'); const p = require('path').join; const strip = require('../utils').strip; +const { stripVTControlCharacters: stripAnsi } = require('node:util'); const FEATURES = require('../features'); @@ -99,15 +100,17 @@ QUnit.module('commands', (hooks) => { let feature = FEATURES[key]; assert.ok( - result.stdout.indexOf(`${key} (Default: ${feature.default}`) >= 0, + stripAnsi(result.stdout).indexOf( + `${key} (Default: ${feature.default}` + ) >= 0, `it should include ${key} and its default value` ); assert.ok( - result.stdout.indexOf(feature.description) >= 0, + stripAnsi(result.stdout).indexOf(feature.description) >= 0, `it should include the description for ${key}` ); assert.ok( - result.stdout.indexOf(feature.url) >= 0, + stripAnsi(result.stdout).indexOf(feature.url) >= 0, `it should include the URL for ${key}` ); }); @@ -190,7 +193,8 @@ QUnit.module('commands', (hooks) => { 'it should print an error' ); assert.ok( - result.stdout.indexOf('foo-bar is not a valid feature') >= 0, + stripAnsi(result.stdout).indexOf('foo-bar is not a valid feature') >= + 0, 'it should print an error' ); }); @@ -216,11 +220,11 @@ QUnit.module('commands', (hooks) => { ); assert.ok( - result.stdout.indexOf('Error:') >= 0, + stripAnsi(result.stdout).indexOf('Error:') >= 0, 'it should print an error' ); assert.ok( - result.stdout.indexOf( + stripAnsi(result.stdout).indexOf( 'application-template-wrapper is only available in Ember 3.1.0 or above' ) >= 0, 'it should print an error'