Skip to content

Commit

Permalink
fix: remove picocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Oct 5, 2024
1 parent 93c5bc6 commit f1794b9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
27 changes: 19 additions & 8 deletions app/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pico from 'picocolors'
import type { LogLevel } from './env.server'

export type EnumValues<Type> = Type[keyof Type]
Expand All @@ -11,6 +10,18 @@ export function isBrowser() {
return typeof window !== 'undefined'
}

// Custom color functions using ANSI escape codes
const colors = {
blue: (text: string) => `\x1b[34m${text}\x1b[0m`,
dim: (text: string) => `\x1b[2m${text}\x1b[0m`,
gray: (text: string) => `\x1b[90m${text}\x1b[0m`,
green: (text: string) => `\x1b[32m${text}\x1b[0m`,
magenta: (text: string) => `\x1b[35m${text}\x1b[0m`,
red: (text: string) => `\x1b[31m${text}\x1b[0m`,
yellow: (text: string) => `\x1b[33m${text}\x1b[0m`,
cyan: (text: string) => `\x1b[36m${text}\x1b[0m`,
}

/**
* Generates a formatted timestamp string.
* @param date - Optional Date object. Defaults to current date/time.
Expand All @@ -28,16 +39,16 @@ function logTimestamp(date?: Date, localtime = true): string {
const minutes = String(useUTC ? now.getUTCMinutes() : now.getMinutes()).padStart(2, '0')
const seconds = String(useUTC ? now.getUTCSeconds() : now.getSeconds()).padStart(2, '0')

return pico.dim(`[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`)
return colors.dim(`[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`)
}

// Constants for log colors
const LOG_COLORS: Record<LogLevel, (text: string) => string> = {
info: pico.green,
warn: pico.yellow,
error: pico.red,
debug: pico.magenta,
query: pico.blue,
info: colors.green,
warn: colors.yellow,
error: colors.red,
debug: colors.magenta,
query: colors.blue,
}

// Constants for log methods with uppercase keys
Expand All @@ -51,7 +62,7 @@ const LOG_METHODS: Record<string, (...args: unknown[]) => void> = {
}

// Fallback constants
const DEFAULT_COLOR = pico.gray
const DEFAULT_COLOR = colors.gray
const DEFAULT_LOG_METHOD = console.log
const LOG_LEVELS = Object.keys(LOG_METHODS)
const MAX_LEVEL_LENGTH = Math.max(...LOG_LEVELS.map((level) => level.length))
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"isbot": "^5.1.17",
"lucide-react": "^0.447.0",
"morgan": "^1.10.0",
"picocolors": "^1.1.0",
"react-dom": "^18.3.1",
"react": "^18.3.1",
"remix-flat-routes": "^0.6.5",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import 'dotenv/config'
import path from 'node:path'
import { createRequestHandler } from '@remix-run/express'
import { installGlobals } from '@remix-run/node'
import compression from 'compression'
Expand All @@ -26,7 +25,7 @@ import { parseNumber, purgeRequireCache } from './utils.js'
installGlobals()

// Get Remix build directory
const BUILD_DIR = path.join(process.cwd(), 'dist/remix')
const BUILD_DIR = `${process.cwd()}/dist/remix`

const staticOptions = {
immutable: true,
Expand Down
5 changes: 1 addition & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/// <reference types="vitest" />

import { resolve } from 'node:path'
import { type VitePluginConfig, vitePlugin as remix } from '@remix-run/dev'
import { installGlobals } from '@remix-run/node'
import { flatRoutes } from 'remix-flat-routes'
Expand All @@ -15,7 +12,7 @@ installGlobals()
const isTestOrStorybook = process.env.NODE_ENV === 'test' || process.argv[1]?.includes('storybook')

const RemixConfig: VitePluginConfig = {
buildDirectory: resolve(__dirname, 'dist/remix'),
buildDirectory: './dist/remix',
ignoredRouteFiles: ['**/.*'],
serverModuleFormat: 'esm',
routes(defineRoutes) {
Expand Down

0 comments on commit f1794b9

Please sign in to comment.