From 91b0ebbed2c20b8659dbae6f3ff4924940983a09 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 31 Dec 2021 02:26:51 +0100 Subject: build: Upgrade to chalk 5.0.0 anyways Requires some workarounds for ts-jest to find the vendored dependencies. --- config/jest.config.base.js | 7 +++++-- packages/main/package.json | 2 +- packages/main/src/utils/logging.ts | 6 +++--- yarn.lock | 11 +++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config/jest.config.base.js b/config/jest.config.base.js index f265c1c..87d5b31 100644 --- a/config/jest.config.base.js +++ b/config/jest.config.base.js @@ -2,7 +2,7 @@ import { join } from 'path'; import { fileURLToDirname } from './utils.js'; -const dirname = fileURLToDirname(import.meta.url); +const thisDir = fileURLToDirname(import.meta.url); /** @type {import('ts-jest').InitialOptionsTsJest} */ export default { @@ -13,8 +13,11 @@ export default { }, }, moduleNameMapper: { - '@sophie/(.+)': join(dirname, '../packages/$1/src/index.ts'), + '@sophie/(.+)': join(thisDir, '../packages/$1/src/index.ts'), '^(\\.{1,2}/.*)\\.js$': '$1', + // Workaround for typescript to recognize the vendored dependencies of chalk. + '#ansi-styles': join(thisDir, '../node_modules/chalk/source/vendor/ansi-styles/index.js'), + '#supports-color': join(thisDir, '../node_modules/chalk/source/vendor/supports-color/index.js'), }, resetMocks: true, restoreMocks: true, diff --git a/packages/main/package.json b/packages/main/package.json index eb2ecf6..f4cf18b 100644 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -10,7 +10,7 @@ "dependencies": { "@sophie/service-shared": "workspace:*", "@sophie/shared": "workspace:*", - "chalk": "^4.1.2", + "chalk": "^5.0.0", "electron": "16.0.5", "json5": "^2.2.0", "lodash-es": "^4.17.21", diff --git a/packages/main/src/utils/logging.ts b/packages/main/src/utils/logging.ts index ed40365..f703749 100644 --- a/packages/main/src/utils/logging.ts +++ b/packages/main/src/utils/logging.ts @@ -18,7 +18,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import chalk, { Chalk } from 'chalk'; +import chalk, { ChalkInstance } from 'chalk'; import loglevel, { Logger } from 'loglevel'; import prefix from 'loglevel-plugin-prefix'; @@ -28,7 +28,7 @@ if (import.meta.env?.DEV) { loglevel.setLevel('info'); } -const COLORS: Partial> = { +const COLORS: Partial> = { TRACE: chalk.magenta, DEBUG: chalk.cyan, INFO: chalk.blue, @@ -37,7 +37,7 @@ const COLORS: Partial> = { CRITICAL: chalk.red, }; -function getColor(level: string): Chalk { +function getColor(level: string): ChalkInstance { return COLORS[level] ?? chalk.gray; } diff --git a/yarn.lock b/yarn.lock index 12a41fc..9d19aac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1203,7 +1203,7 @@ __metadata: "@types/lodash-es": ^4.17.5 "@types/ms": ^0.7.31 "@types/node": ^17.0.5 - chalk: ^4.1.2 + chalk: ^5.0.0 electron: 16.0.5 electron-devtools-installer: ^3.2.0 esbuild: ^0.14.9 @@ -2345,7 +2345,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.1, chalk@npm:^4.1.2": +"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.1": version: 4.1.2 resolution: "chalk@npm:4.1.2" dependencies: @@ -2355,6 +2355,13 @@ __metadata: languageName: node linkType: hard +"chalk@npm:^5.0.0": + version: 5.0.0 + resolution: "chalk@npm:5.0.0" + checksum: 6eba7c518b9aa5fe882ae6d14a1ffa58c418d72a3faa7f72af56641f1bbef51b645fca1d6e05d42357b7d3c846cd504c0b7b64d12309cdd07867e3b4411e0d01 + languageName: node + linkType: hard + "char-regex@npm:^1.0.2": version: 1.0.2 resolution: "char-regex@npm:1.0.2" -- cgit v1.2.3-54-g00ecf