From 1309e198fb69c2b58f9802e638c4d2b9c1735795 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 21 Jul 2024 00:25:14 -0700 Subject: [PATCH 1/3] refactor: replace `chalk` with `styleText` Signed-off-by: Hunar Roop Kahlon --- app/entry.server.tsx | 6 +++--- app/utils/db.server.ts | 5 +++-- index.js | 8 +++++--- server/index.ts | 10 +++++----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 9f17da84b..2aaa7f842 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -1,4 +1,5 @@ import { PassThrough } from 'stream' +import { styleText } from 'node:util' import { createReadableStreamFromReadable, type LoaderFunctionArgs, @@ -7,7 +8,6 @@ import { } from '@remix-run/node' import { RemixServer } from '@remix-run/react' import * as Sentry from '@sentry/remix' -import chalk from 'chalk' import { isbot } from 'isbot' import { renderToPipeableStream } from 'react-dom/server' import { getEnv, init } from './utils/env.server.ts' @@ -102,7 +102,7 @@ export function handleError( return } if (error instanceof Error) { - console.error(chalk.red(error.stack)) + console.error(styleText('red', String(error.stack))) void Sentry.captureRemixServerException( error, 'remix.server', @@ -110,7 +110,7 @@ export function handleError( true, ) } else { - console.error(chalk.red(error)) + console.error(styleText('red', String(error))) Sentry.captureException(error) } } diff --git a/app/utils/db.server.ts b/app/utils/db.server.ts index 9e010e821..20e1e468a 100644 --- a/app/utils/db.server.ts +++ b/app/utils/db.server.ts @@ -1,6 +1,6 @@ +import { styleText } from 'node:util' import { remember } from '@epic-web/remember' import { PrismaClient } from '@prisma/client' -import chalk from 'chalk' export const prisma = remember('prisma', () => { // NOTE: if you change anything in this function you'll need to restart @@ -28,7 +28,8 @@ export const prisma = remember('prisma', () => { : e.duration < logThreshold * 1.4 ? 'redBright' : 'red' - const dur = chalk[color](`${e.duration}ms`) + const dur = styleText(color, `${e.duration}ms`) + console.info(`prisma:query - ${dur} - ${e.query}`) }) void client.$connect() diff --git a/index.js b/index.js index ef699b60c..6aabf5806 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ import 'dotenv/config' +// 👆 this needs to imported first + +import { styleText } from 'node:util' import * as fs from 'fs' -import chalk from 'chalk' import closeWithGrace from 'close-with-grace' import sourceMapSupport from 'source-map-support' @@ -20,8 +22,8 @@ sourceMapSupport.install({ closeWithGrace(async ({ err }) => { if (err) { - console.error(chalk.red(err)) - console.error(chalk.red(err.stack)) + console.error(styleText('red', err.message)) + console.error(styleText('red', String(err.stack))) process.exit(1) } }) diff --git a/server/index.ts b/server/index.ts index 39a4582dc..c9b6deb01 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,8 +1,8 @@ import crypto from 'crypto' +import { styleText } from 'node:util' import { createRequestHandler } from '@remix-run/express' import { type ServerBuild } from '@remix-run/node' import { ip as ipAddress } from 'address' -import chalk from 'chalk' import closeWithGrace from 'close-with-grace' import compression from 'compression' import express from 'express' @@ -237,7 +237,7 @@ if (!portAvailable && !IS_DEV) { const server = app.listen(portToUse, () => { if (!portAvailable) { console.warn( - chalk.yellow( + styleText('yellow', `⚠️ Port ${desiredPort} is not available, using ${portToUse} instead.`, ), ) @@ -255,9 +255,9 @@ const server = app.listen(portToUse, () => { console.log( ` -${chalk.bold('Local:')} ${chalk.cyan(localUrl)} -${lanUrl ? `${chalk.bold('On Your Network:')} ${chalk.cyan(lanUrl)}` : ''} -${chalk.bold('Press Ctrl+C to stop')} +${styleText('bold', 'Local:')} ${styleText('cyan', localUrl)} +${lanUrl ? `${styleText('bold', 'On Your Network:')} ${styleText('cyan', lanUrl)}` : ''} +${styleText('bold', 'Press Ctrl+C to stop')} `.trim(), ) }) From 237786fd84255dfb3b5a4f019feeae221c5ba862 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 21 Jul 2024 00:25:40 -0700 Subject: [PATCH 2/3] build(deps): remove `chalk` Signed-off-by: Hunar Roop Kahlon --- package-lock.json | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f1b10ab17..4d1c1c674 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,6 @@ "address": "^2.0.3", "bcryptjs": "^2.4.3", "better-sqlite3": "^11.1.2", - "chalk": "^5.3.0", "class-variance-authority": "^0.7.0", "close-with-grace": "^1.3.0", "clsx": "^2.1.1", @@ -9003,6 +9002,7 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, "license": "MIT", "engines": { "node": "^12.17.0 || ^14.13 || >=16.0.0" diff --git a/package.json b/package.json index 418c8bba2..17a92df21 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "address": "^2.0.3", "bcryptjs": "^2.4.3", "better-sqlite3": "^11.1.2", - "chalk": "^5.3.0", "class-variance-authority": "^0.7.0", "close-with-grace": "^1.3.0", "clsx": "^2.1.1", From 181f7e215ca61c256050ad829ec9b1445c174850 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 21 Jul 2024 12:56:09 -0700 Subject: [PATCH 3/3] style(imports): fix import order Signed-off-by: Hunar Roop Kahlon --- app/entry.server.tsx | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 2aaa7f842..f1a94b086 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -1,5 +1,5 @@ -import { PassThrough } from 'stream' import { styleText } from 'node:util' +import { PassThrough } from 'stream' import { createReadableStreamFromReadable, type LoaderFunctionArgs, diff --git a/index.js b/index.js index 6aabf5806..e3e2b221c 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ import 'dotenv/config' // 👆 this needs to imported first -import { styleText } from 'node:util' import * as fs from 'fs' +import { styleText } from 'node:util' import closeWithGrace from 'close-with-grace' import sourceMapSupport from 'source-map-support'