From 6c11e68d21d44fe0d951c0fcd6f517278119636b Mon Sep 17 00:00:00 2001 From: Daniel Miller Date: Fri, 20 Mar 2026 13:25:17 -0700 Subject: [PATCH 1/2] BAE-219 Change out Chalk to styleText from Node --- .changeset/spicy-kings-obey.md | 5 +++++ package.json | 3 +-- pnpm-lock.yaml | 14 +++++++++++--- renovate.json | 2 +- src/validation-errors/additional-prop.js | 19 ++++++++++++++++--- src/validation-errors/default.js | 13 ++++++++----- src/validation-errors/enum.js | 22 ++++++++++------------ src/validation-errors/required.js | 20 +++++++++++++------- 8 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 .changeset/spicy-kings-obey.md diff --git a/.changeset/spicy-kings-obey.md b/.changeset/spicy-kings-obey.md new file mode 100644 index 00000000..75acb1b4 --- /dev/null +++ b/.changeset/spicy-kings-obey.md @@ -0,0 +1,5 @@ +--- +'better-ajv-errors': patch +--- + +Remove Chalk from the project, swapping to styleText from node. diff --git a/package.json b/package.json index 9a2d1b63..8ab46af2 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "module": "./lib/esm/index.mjs", "engines": { - "node": ">= 18.20.6" + "node": ">= 20.12.0" }, "keywords": [ "json-schema", @@ -58,7 +58,6 @@ "dependencies": { "@babel/code-frame": "^7.27.1", "@humanwhocodes/momoa": "^2.0.4", - "chalk": "^4.1.2", "jsonpointer": "^5.0.1", "leven": "^3.1.0 < 4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c56bf991..6127ea68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: '@humanwhocodes/momoa': specifier: ^2.0.4 version: 2.0.4 - chalk: - specifier: ^4.1.2 - version: 4.1.2 jsonpointer: specifier: ^5.0.1 version: 5.0.1 @@ -527,56 +524,67 @@ packages: resolution: {integrity: sha512-wC53ZNDgt0pqx5xCAgNunkTzFE8GTgdZ9EwYGVcg+jEjJdZGtq9xPjDnFgfFozQI/Xm1mh+D9YlYtl+ueswNEg==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.41.1': resolution: {integrity: sha512-jwKCca1gbZkZLhLRtsrka5N8sFAaxrGz/7wRJ8Wwvq3jug7toO21vWlViihG85ei7uJTpzbXZRcORotE+xyrLA==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.41.1': resolution: {integrity: sha512-g0UBcNknsmmNQ8V2d/zD2P7WWfJKU0F1nu0k5pW4rvdb+BIqMm8ToluW/eeRmxCared5dD76lS04uL4UaNgpNA==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.41.1': resolution: {integrity: sha512-XZpeGB5TKEZWzIrj7sXr+BEaSgo/ma/kCgrZgL0oo5qdB1JlTzIYQKel/RmhT6vMAvOdM2teYlAaOGJpJ9lahg==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-loongarch64-gnu@4.41.1': resolution: {integrity: sha512-bkCfDJ4qzWfFRCNt5RVV4DOw6KEgFTUZi2r2RuYhGWC8WhCA8lCAJhDeAmrM/fdiAH54m0mA0Vk2FGRPyzI+tw==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-powerpc64le-gnu@4.41.1': resolution: {integrity: sha512-3mr3Xm+gvMX+/8EKogIZSIEF0WUu0HL9di+YWlJpO8CQBnoLAEL/roTCxuLncEdgcfJcvA4UMOf+2dnjl4Ut1A==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.41.1': resolution: {integrity: sha512-3rwCIh6MQ1LGrvKJitQjZFuQnT2wxfU+ivhNBzmxXTXPllewOF7JR1s2vMX/tWtUYFgphygxjqMl76q4aMotGw==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.41.1': resolution: {integrity: sha512-LdIUOb3gvfmpkgFZuccNa2uYiqtgZAz3PTzjuM5bH3nvuy9ty6RGc/Q0+HDFrHrizJGVpjnTZ1yS5TNNjFlklw==} cpu: [riscv64] os: [linux] + libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.41.1': resolution: {integrity: sha512-oIE6M8WC9ma6xYqjvPhzZYk6NbobIURvP/lEbh7FWplcMO6gn7MM2yHKA1eC/GvYwzNKK/1LYgqzdkZ8YFxR8g==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.41.1': resolution: {integrity: sha512-cWBOvayNvA+SyeQMp79BHPK8ws6sHSsYnK5zDcsC3Hsxr1dgTABKjMnMslPq1DvZIp6uO7kIWhiGwaTdR4Og9A==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.41.1': resolution: {integrity: sha512-y5CbN44M+pUCdGDlZFzGGBSKCA4A/J2ZH4edTYSSxFg7ce1Xt3GtydbVKWLlzL+INfFIZAEg1ZV6hh9+QQf9YQ==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.41.1': resolution: {integrity: sha512-lZkCxIrjlJlMt1dLO/FbpZbzt6J/A8p4DnqzSa4PWqPEUUUnzXLeki/iyPLfV0BmHItlYgHUqJe+3KiyydmiNQ==} diff --git a/renovate.json b/renovate.json index f02d06f2..dca675ff 100644 --- a/renovate.json +++ b/renovate.json @@ -5,7 +5,7 @@ "rangeStrategy": "replace", "packageRules": [ { - "matchPackagePatterns": ["chalk", "leven"], + "matchPackagePatterns": ["leven"], "enabled": false } ] diff --git a/src/validation-errors/additional-prop.js b/src/validation-errors/additional-prop.js index c680f8a5..f3a7d54d 100644 --- a/src/validation-errors/additional-prop.js +++ b/src/validation-errors/additional-prop.js @@ -1,4 +1,5 @@ -import chalk from 'chalk'; +import { styleText } from 'node:util'; + import BaseValidationError from './base'; export default class AdditionalPropValidationError extends BaseValidationError { @@ -9,11 +10,23 @@ export default class AdditionalPropValidationError extends BaseValidationError { print() { const { message, params } = this.options; - const output = [chalk`{red {bold ADDTIONAL PROPERTY} ${message}}\n`]; + + const boldAdditionalPropertiesLabel = styleText( + 'bold', + 'ADDTIONAL PROPERTY', + ); + const magentaAdditionalProperty = styleText( + ['magentaBright'], + params.additionalProperty, + ); + + const output = [ + styleText('red', `${boldAdditionalPropertiesLabel} ${message}\n`), + ]; return output.concat( this.getCodeFrame( - chalk`😲 {magentaBright ${params.additionalProperty}} is not expected to be here!`, + `😲 ${magentaAdditionalProperty} is not expected to be here!`, `${this.instancePath}/${params.additionalProperty}` ) ); diff --git a/src/validation-errors/default.js b/src/validation-errors/default.js index a00df894..15c3a7a2 100644 --- a/src/validation-errors/default.js +++ b/src/validation-errors/default.js @@ -1,14 +1,17 @@ -import chalk from 'chalk'; +import { styleText } from 'node:util'; + import BaseValidationError from './base'; export default class DefaultValidationError extends BaseValidationError { print() { const { keyword, message } = this.options; - const output = [chalk`{red {bold ${keyword.toUpperCase()}} ${message}}\n`]; + const boldUpperKeyword = styleText('bold', keyword.toUpperCase()); + const magentaBrightKeyword = styleText('magentaBright', keyword); - return output.concat( - this.getCodeFrame(chalk`👈đŸŊ {magentaBright ${keyword}} ${message}`) - ); + return [ + styleText('red', `${boldUpperKeyword} ${message}\n`), + this.getCodeFrame(`👈đŸŊ ${magentaBrightKeyword} ${message}`) + ]; } getError() { diff --git a/src/validation-errors/enum.js b/src/validation-errors/enum.js index 22d8d192..018b2e2c 100644 --- a/src/validation-errors/enum.js +++ b/src/validation-errors/enum.js @@ -1,5 +1,5 @@ -import chalk from 'chalk'; import leven from 'leven'; +import { styleText } from 'node:util'; import pointer from 'jsonpointer'; import BaseValidationError from './base'; @@ -10,19 +10,17 @@ export default class EnumValidationError extends BaseValidationError { params: { allowedValues }, } = this.options; const bestMatch = this.findBestMatch(); + const codeFrameMessage = bestMatch !== null + ? `👈đŸŊ Did you mean ${styleText('magentaBright', bestMatch)} here?` + : '👈đŸŊ Unexpected value, should be equal to one of the allowed values'; - const output = [ - chalk`{red {bold ENUM} ${message}}`, - chalk`{red (${allowedValues.join(', ')})}\n`, - ]; + const boldEnumLabel = styleText('bold', 'ENUM'); - return output.concat( - this.getCodeFrame( - bestMatch !== null - ? chalk`👈đŸŊ Did you mean {magentaBright ${bestMatch}} here?` - : chalk`👈đŸŊ Unexpected value, should be equal to one of the allowed values` - ) - ); + return [ + styleText('red', `${boldEnumLabel} ${message}`), + styleText('red', `(${allowedValues.join(', ')})\n`), + this.getCodeFrame(codeFrameMessage), + ]; } getError() { diff --git a/src/validation-errors/required.js b/src/validation-errors/required.js index 9a438fc0..c055e78f 100644 --- a/src/validation-errors/required.js +++ b/src/validation-errors/required.js @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import { styleText } from 'node:util'; import BaseValidationError from './base'; export default class RequiredValidationError extends BaseValidationError { @@ -9,13 +9,19 @@ export default class RequiredValidationError extends BaseValidationError { print() { const { message, params } = this.options; - const output = [chalk`{red {bold REQUIRED} ${message}}\n`]; - return output.concat( - this.getCodeFrame( - chalk`â˜šī¸ {magentaBright ${params.missingProperty}} is missing here!` - ) - ); + const boldRequiredLabel = styleText('bold', 'REQUIRED'); + const magentaMissingProperty = styleText( + 'magentaBright', + params.missingProperty, + ); + + return [ + styleText('red', `${boldRequiredLabel} ${message}\n`), + this.getCodeFrame( + `â˜šī¸ ${magentaMissingProperty} is missing here!`, + ), + ]; } getError() { From 41fcb4c217de24e374adb18d200b8fe4588650b2 Mon Sep 17 00:00:00 2001 From: Daniel Miller Date: Mon, 27 Apr 2026 11:46:36 -0700 Subject: [PATCH 2/2] Fix changeset --- .changeset/spicy-kings-obey.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/spicy-kings-obey.md b/.changeset/spicy-kings-obey.md index 75acb1b4..6d16e0ed 100644 --- a/.changeset/spicy-kings-obey.md +++ b/.changeset/spicy-kings-obey.md @@ -1,5 +1,5 @@ --- -'better-ajv-errors': patch +'better-ajv-errors': major --- Remove Chalk from the project, swapping to styleText from node.