Skip to content

Commit 818b47c

Browse files
refactor: replace chalk with styleText
Signed-off-by: Hunar Roop Kahlon <[email protected]>
1 parent d1293e9 commit 818b47c

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

app/entry.server.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PassThrough } from 'stream'
2+
import { styleText } from 'node:util'
23
import {
34
createReadableStreamFromReadable,
45
type LoaderFunctionArgs,
@@ -7,7 +8,6 @@ import {
78
} from '@remix-run/node'
89
import { RemixServer } from '@remix-run/react'
910
import * as Sentry from '@sentry/remix'
10-
import chalk from 'chalk'
1111
import { isbot } from 'isbot'
1212
import { renderToPipeableStream } from 'react-dom/server'
1313
import { getEnv, init } from './utils/env.server.ts'
@@ -102,15 +102,15 @@ export function handleError(
102102
return
103103
}
104104
if (error instanceof Error) {
105-
console.error(chalk.red(error.stack))
105+
console.error(styleText('red', String(error.stack)))
106106
void Sentry.captureRemixServerException(
107107
error,
108108
'remix.server',
109109
request,
110110
true,
111111
)
112112
} else {
113-
console.error(chalk.red(error))
113+
console.error(styleText('red', String(error)))
114114
Sentry.captureException(error)
115115
}
116116
}

app/utils/db.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { styleText } from 'node:util'
12
import { remember } from '@epic-web/remember'
23
import { PrismaClient } from '@prisma/client'
3-
import chalk from 'chalk'
44

55
export const prisma = remember('prisma', () => {
66
// NOTE: if you change anything in this function you'll need to restart
@@ -28,7 +28,8 @@ export const prisma = remember('prisma', () => {
2828
: e.duration < logThreshold * 1.4
2929
? 'redBright'
3030
: 'red'
31-
const dur = chalk[color](`${e.duration}ms`)
31+
const dur = styleText(color, `${e.duration}ms`)
32+
3233
console.info(`prisma:query - ${dur} - ${e.query}`)
3334
})
3435
void client.$connect()

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dotenv/config'
2+
// 👆 this needs to imported first
3+
4+
import { styleText } from 'node:util'
25
import * as fs from 'fs'
3-
import chalk from 'chalk'
46
import closeWithGrace from 'close-with-grace'
57
import sourceMapSupport from 'source-map-support'
68

@@ -20,8 +22,8 @@ sourceMapSupport.install({
2022

2123
closeWithGrace(async ({ err }) => {
2224
if (err) {
23-
console.error(chalk.red(err))
24-
console.error(chalk.red(err.stack))
25+
console.error(styleText('red', err.message))
26+
console.error(styleText('red', String(err.stack)))
2527
process.exit(1)
2628
}
2729
})

server/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import crypto from 'crypto'
2+
import { styleText } from 'node:util'
23
import { createRequestHandler } from '@remix-run/express'
34
import { type ServerBuild, installGlobals } from '@remix-run/node'
45
import { ip as ipAddress } from 'address'
5-
import chalk from 'chalk'
66
import closeWithGrace from 'close-with-grace'
77
import compression from 'compression'
88
import express from 'express'
@@ -239,7 +239,7 @@ if (!portAvailable && !IS_DEV) {
239239
const server = app.listen(portToUse, () => {
240240
if (!portAvailable) {
241241
console.warn(
242-
chalk.yellow(
242+
styleText('yellow',
243243
`⚠️ Port ${desiredPort} is not available, using ${portToUse} instead.`,
244244
),
245245
)
@@ -257,9 +257,9 @@ const server = app.listen(portToUse, () => {
257257

258258
console.log(
259259
`
260-
${chalk.bold('Local:')} ${chalk.cyan(localUrl)}
261-
${lanUrl ? `${chalk.bold('On Your Network:')} ${chalk.cyan(lanUrl)}` : ''}
262-
${chalk.bold('Press Ctrl+C to stop')}
260+
${styleText('bold', 'Local:')} ${styleText('cyan', localUrl)}
261+
${lanUrl ? `${styleText('bold', 'On Your Network:')} ${styleText('cyan', lanUrl)}` : ''}
262+
${styleText('bold', 'Press Ctrl+C to stop')}
263263
`.trim(),
264264
)
265265
})

0 commit comments

Comments
 (0)