Skip to content

Commit b936aee

Browse files
committedSep 5, 2023
fix: improve log colors
1 parent 9dd96c3 commit b936aee

22 files changed

+42
-52
lines changed
 

‎vite-plugin-ssr/node/plugin/plugins/config/resolveBase.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function resolveBaseFromUserConfig(config: UserConfig, configVps: undefined | Co
2828
function resolve(base: string | null, baseServer_: string | null, baseAssets_: string | null): BaseServers {
2929
{
3030
const wrongBase = (val: string) =>
31-
`should start with ${pc.bold('/')}, ${pc.bold('http://')}, or ${pc.bold('https://')} (it's ${pc.bold(
31+
`should start with ${pc.cyan('/')}, ${pc.cyan('http://')}, or ${pc.cyan('https://')} (it's ${pc.cyan(
3232
val
3333
)} instead)`
3434
assertUsage(base === null || isBaseAssets(base), `vite.config.js#base ${wrongBase(base!)}`)
@@ -38,7 +38,7 @@ function resolve(base: string | null, baseServer_: string | null, baseAssets_: s
3838
)
3939
assertUsage(
4040
baseServer_ === null || baseServer_.startsWith('/'),
41-
`Config ${pc.cyan('baseServer')} should start with a leading slash ${pc.bold('/')} (it's ${pc.bold(
41+
`Config ${pc.cyan('baseServer')} should start with a leading slash ${pc.cyan('/')} (it's ${pc.cyan(
4242
String(baseServer_)
4343
)} instead)`
4444
)

‎vite-plugin-ssr/node/plugin/plugins/importUserCode/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function handleHotUpdate(ctx: HmrContext, config: ResolvedConfig, configVps: Con
106106
// - Can be annoying for files that obviously aren't processed by Vite.
107107
if (!isVikeConfig && !isViteModule) {
108108
logViteAny(
109-
`${msg} — ${pc.bold('no HMR')}, see https://vite-plugin-ssr.com/on-demand-compiler`,
109+
`${msg} — ${pc.cyan('no HMR')}, see https://vite-plugin-ssr.com/on-demand-compiler`,
110110
'info',
111111
null,
112112
true,

‎vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/serializePageConfigs.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,12 @@ function getConfigValueSerialized(value: unknown, configName: string, configDefi
186186
configValueSerialized = stringify(value, { valueName })
187187
} catch (err) {
188188
assert(hasProp(err, 'messageCore', 'string'))
189-
const configPath = pc.bold(configDefinedByFile)
190189
assertUsage(
191190
false,
192191
[
193-
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configPath}.`,
194-
`Its value must be defined in an another file and then imported by ${configPath} (because it isn't serializable: ${err.messageCore}).`,
195-
`Only serializable config values can be defined inside ${configPath}, see https://vite-plugin-ssr.com/header-file.`
192+
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configDefinedByFile}.`,
193+
`Its value must be defined in an another file and then imported by ${configDefinedByFile} (because it isn't serializable: ${err.messageCore}).`,
194+
`Only serializable config values can be defined inside ${configDefinedByFile}, see https://vite-plugin-ssr.com/header-file.`
196195
].join(' ')
197196
)
198197
}

‎vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function triggerPrepareStackTrace(err: unknown) {
315315
function getErrIntroMsg(operation: 'transpile' | 'execute', filePath: FilePath) {
316316
const msg = [
317317
pc.red(`Failed to ${operation}`),
318-
pc.red(pc.bold(getFilePathToShowToUser(filePath))),
318+
pc.bold(pc.red(getFilePathToShowToUser(filePath))),
319319
pc.red(`because:`)
320320
].join(' ')
321321
return msg

‎vite-plugin-ssr/node/plugin/plugins/previewConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function previewConfig(): Plugin {
4444
;[outDirRoot, outDirClient, outDirServer].forEach((outDirAny) => {
4545
assertUsage(
4646
fs.existsSync(outDirAny),
47-
`Cannot run ${pc.cyan('$ vite preview')}: your app isn't built (the build directory ${pc.bold(
47+
`Cannot run ${pc.cyan('$ vite preview')}: your app isn't built (the build directory ${pc.cyan(
4848
outDirAny
4949
)} is missing). Make sure to run ${pc.cyan('$ vite build')} before running ${pc.cyan('$ vite preview')}.`
5050
)

‎vite-plugin-ssr/node/plugin/shared/findPageFiles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function findPageFiles(config: ResolvedConfig, fileTypes: FileType[], isDe
1919
// We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
2020
assertWarning(
2121
time < 1.5 * 1000,
22-
`Finding your page files ${pc.bold(
22+
`Finding your page files ${pc.cyan(
2323
'**/*.page.*'
2424
)} took an unexpected long time (${time}ms). Reach out to the vite-plugin-ssr maintainer.`,
2525
{

‎vite-plugin-ssr/node/plugin/shared/loggerNotProd.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function logConfigInfo(msg: string, logType: LogType): void {
8484
logWithVikeTag(msg, logType, category)
8585
}
8686
function logConfigErrorRecover(): void {
87-
const msg = pc.green(pc.bold('Configuration successfully loaded'))
87+
const msg = pc.bold(pc.green('Configuration successfully loaded'))
8888
clearLogs({ clearAlsoIfConfigIsInvalid: true })
8989
const category = getConfigCategory()
9090
logWithVikeTag(msg, 'error-recover', category)
@@ -189,7 +189,7 @@ function logConfigError(err: unknown): void {
189189
}
190190

191191
function logFallbackErrIntro(category: LogCategory) {
192-
logWithVikeTag(pc.red(pc.bold('[Error] An error was thrown:')), 'error', category)
192+
logWithVikeTag(pc.bold(pc.red('[Error] An error was thrown:')), 'error', category)
193193
}
194194

195195
function getConfigCategory(): LogCategory {

‎vite-plugin-ssr/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getPrettyErrorWithCodeSnippet(err: ErrorWithCodeSnippet, userRootDir: s
6666

6767
const msgFirstLine = [
6868
pc.red('Failed to transpile'),
69-
pc.red(pc.bold(getFilePathVite(normalizeId(id), userRootDir))),
69+
pc.bold(pc.red(getFilePathVite(normalizeId(id), userRootDir))),
7070
pc.red('because:')
7171
].join(' ')
7272

‎vite-plugin-ssr/node/plugin/shared/loggerNotProd/log.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ function applyViteSourceMapToStackTrace(thing: unknown) {
8383

8484
function prependTags(msg: string, projectTag: '[vite]' | ProjectTag, category: LogCategory | null, logType: LogType) {
8585
const color = (s: string) => {
86-
if (logType === 'error' && !hasRed(msg)) return pc.red(pc.bold(s))
87-
if (logType === 'error-recover' && !hasGreen(msg)) return pc.green(pc.bold(s))
86+
if (logType === 'error' && !hasRed(msg)) return pc.bold(pc.red(s))
87+
if (logType === 'error-recover' && !hasGreen(msg)) return pc.bold(pc.green(s))
8888
if (logType === 'warn' && !hasYellow(msg)) return pc.yellow(s)
89-
if (projectTag === '[vite]') return pc.cyan(pc.bold(s))
90-
if (projectTag.startsWith(`[${projectInfo.projectName}`)) return pc.cyan(pc.bold(s))
89+
if (projectTag === '[vite]') return pc.bold(pc.cyan(s))
90+
if (projectTag.startsWith(`[${projectInfo.projectName}`)) return pc.bold(pc.cyan(s))
9191
assert(false)
9292
}
93-
let tag = color(pc.bold(`${projectTag}`))
93+
let tag = color(`${projectTag}`)
9494
if (category) {
9595
tag = tag + pc.dim(`[${category}]`)
9696
}

‎vite-plugin-ssr/node/prerender/runPrerender.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ async function routeAndPrerender(
757757
try {
758758
res = await prerenderPage(pageContext)
759759
} catch (err) {
760-
assertIsNotAbort(err, pc.bold(pageContext.urlOriginal))
760+
assertIsNotAbort(err, pc.cyan(pageContext.urlOriginal))
761761
throw err
762762
}
763763
const { documentHtml, pageContextSerialized } = res

‎vite-plugin-ssr/node/runtime/html/renderHtml.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ async function renderTemplate(
221221
const { hookName, hookFilePath } = pageContext._renderHook
222222
assertUsage(
223223
!htmlStream,
224-
`Injecting two streams in ${pc.cyan('escapeInject')} template tag of ${hookName}() hook defined by ${pc.bold(
225-
hookFilePath
226-
)}. Inject only one stream instead.`
224+
`Injecting two streams in ${pc.cyan(
225+
'escapeInject'
226+
)} template tag of ${hookName}() hook defined by ${hookFilePath}. Inject only one stream instead.`
227227
)
228228
htmlStream = stream
229229
}
@@ -263,10 +263,7 @@ async function renderTemplate(
263263
const getErrMsg = (typeText: string, end: null | string) => {
264264
const { hookName, hookFilePath } = pageContext._renderHook
265265
const nth: string = (i === 0 && '1st') || (i === 1 && '2nd') || (i === 2 && '3rd') || `${i}-th`
266-
return [
267-
`The ${nth} HTML variable is ${typeText}, see ${hookName}() hook defined by ${pc.bold(hookFilePath)}.`,
268-
end
269-
]
266+
return [`The ${nth} HTML variable is ${typeText}, see ${hookName}() hook defined by ${hookFilePath}.`, end]
270267
.filter(Boolean)
271268
.join(' ')
272269
}

‎vite-plugin-ssr/node/runtime/renderPage.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async function renderPage<
9797
}
9898

9999
const httpRequestId = getRequestId()
100-
const urlToShowToUser = pc.bold(pageContextInit.urlOriginal)
100+
const urlToShowToUser = pageContextInit.urlOriginal
101101
logHttpRequest(urlToShowToUser, httpRequestId)
102102
globalObject.pendingRequestsCount++
103103

@@ -118,7 +118,7 @@ async function renderPageAndPrepare(
118118
): Promise<PageContextAfterRender> {
119119
// Invalid config
120120
const handleInvalidConfig = () => {
121-
logRuntimeInfo?.(pc.red(pc.bold("Couldn't load configuration: see error above.")), httpRequestId, 'error')
121+
logRuntimeInfo?.(pc.bold(pc.red("Couldn't load configuration: see error above.")), httpRequestId, 'error')
122122
const pageContextHttpReponseNull = getPageContextHttpResponseNull(pageContextInit)
123123
return pageContextHttpReponseNull
124124
}
@@ -300,7 +300,7 @@ async function renderPageAlreadyPrepared(
300300

301301
function logHttpRequest(urlToShowToUser: string, httpRequestId: number) {
302302
const clearErrors = globalObject.pendingRequestsCount === 0
303-
logRuntimeInfo?.(`HTTP request: ${urlToShowToUser}`, httpRequestId, 'info', clearErrors)
303+
logRuntimeInfo?.(`HTTP request: ${pc.bold(urlToShowToUser)}`, httpRequestId, 'info', clearErrors)
304304
}
305305
function logHttpResponse(urlToShowToUser: string, httpRequestId: number, pageContextReturn: PageContextAfterRender) {
306306
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null
@@ -317,10 +317,10 @@ function logHttpResponse(urlToShowToUser: string, httpRequestId: number, pageCon
317317
.find((header) => header[0] === 'Location')
318318
assert(headerRedirect)
319319
const urlRedirect = headerRedirect[1]
320-
urlToShowToUser = pc.bold(urlRedirect)
320+
urlToShowToUser = urlRedirect
321321
}
322322
logRuntimeInfo?.(
323-
`HTTP ${type} ${urlToShowToUser} ${color(statusCode ?? 'ERR')}`,
323+
`HTTP ${type} ${pc.bold(urlToShowToUser)} ${color(statusCode ?? 'ERR')}`,
324324
httpRequestId,
325325
isNominal ? 'info' : 'error'
326326
)
@@ -475,7 +475,7 @@ function normalizeUrl(pageContextInit: { urlOriginal: string }, httpRequestId: n
475475
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash)
476476
if (!urlNormalized) return null
477477
logRuntimeInfo?.(
478-
`URL normalized from ${pc.bold(urlOriginal)} to ${pc.bold(
478+
`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(
479479
urlNormalized
480480
)} (https://vite-plugin-ssr.com/url-normalization)`,
481481
httpRequestId,

‎vite-plugin-ssr/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function copy(G: Graph): Graph {
3535
function check(G: Graph, n: string, path: string[]) {
3636
if (path.includes(n)) {
3737
const cycle = path.slice(path.indexOf(n)).concat(n)
38-
assertUsage(false, `Infinite loop of HTTP URL redirects: ${cycle.map(pc.bold).join(' -> ')}`)
38+
assertUsage(false, `Infinite loop of HTTP URL redirects: ${cycle.map(pc.cyan).join(' -> ')}`)
3939
}
4040
G[n]?.forEach((node) => check(G, node, [...path, n]))
4141
}

‎vite-plugin-ssr/shared/page-configs/loadPageCode.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ function assertIsNotNull(configValue: unknown, configName: string, codeFilePath:
9696
assert(!codeFilePath.includes('+config.'))
9797
assertUsage(
9898
configValue !== null,
99-
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a ${pc.bold('+config.js')} file instead of ${pc.bold(
100-
codeFilePath
101-
)}`
99+
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a '+config.js' file instead of ${codeFilePath}`
102100
)
103101
}

‎vite-plugin-ssr/shared/page-configs/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getConfigSrc(
6666
): string {
6767
const { filePath, fileExportPath } = definedAt
6868
const exportPath = getExportPath(fileExportPath)
69-
let configSrc = `${pc.bold(filePath)} > ${pc.cyan(exportPath)}`
69+
let configSrc = `${filePath} > ${pc.cyan(exportPath)}`
7070
if (append) {
7171
configSrc = `${configSrc} > (${pc.blue(append)})`
7272
}

‎vite-plugin-ssr/shared/route/abort.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function logAbortErrorHandled(
213213
const urlCurrent = pageContext._urlRewrite ?? pageContext.urlOriginal
214214
assert(urlCurrent)
215215
const abortCall = err._pageContextAbort._abortCall
216-
assertInfo(false, `${pc.cyan(abortCall)} intercepted while rendering ${pc.bold(urlCurrent)}`, { onlyOnce: false })
216+
assertInfo(false, `${pc.cyan(abortCall)} intercepted while rendering ${pc.cyan(urlCurrent)}`, { onlyOnce: false })
217217
}
218218

219219
function assertStatusCode(statusCode: number, expected: number[], caller: 'render' | 'redirect') {

‎vite-plugin-ssr/shared/route/executeOnBeforeRouteHook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function executeOnBeforeRouteHook(
6363
assertUsage(
6464
pageContext._allPageIds.includes(hookReturn.pageContext._pageId),
6565
`${errPrefix2} ${joinEnglish(
66-
pageContext._allPageIds.map((s) => pc.bold(s)),
66+
pageContext._allPageIds.map((s) => pc.cyan(s)),
6767
'or'
6868
)}`
6969
)

‎vite-plugin-ssr/shared/route/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async function route(pageContext: PageContextForRoute): Promise<{
137137
resolvePrecendence(routeMatches)
138138
const winner = routeMatches[0]
139139

140-
debug(`Route matches for URL ${pc.bold(urlPathname)} (in precedence order):`, routeMatches)
140+
debug(`Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches)
141141

142142
objectAssign(pageContextAddendum, { _routeMatches: routeMatches })
143143

‎vite-plugin-ssr/shared/route/resolveRedirects.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function resolveRouteStringRedirect(urlSource: string, urlTarget: string, urlPat
2727
urlTarget.startsWith('http://') ||
2828
urlTarget.startsWith('https://') ||
2929
urlTarget === '*',
30-
`${configSrc} Invalid redirection target URL ${highlight(urlTarget)}: the target URL should start with ${highlight(
30+
`${configSrc} Invalid redirection target URL ${pc.cyan(urlTarget)}: the target URL should start with ${pc.cyan(
3131
'/'
32-
)}, ${highlight('http://')}, ${highlight('https://')}, or be ${highlight('*')}`
32+
)}, ${pc.cyan('http://')}, ${pc.cyan('https://')}, or be ${pc.cyan('*')}`
3333
)
3434
assertParams(urlSource, urlTarget)
3535
const match = resolveRouteString(urlSource, urlPathname)
@@ -54,14 +54,10 @@ function assertParams(urlSource: string, urlTarget: string) {
5454
const segments = urlSource.split('/')
5555
assertUsage(
5656
segments.includes(routeSegment),
57-
`${configSrc} The redirection source URL ${highlight(urlSource)} is missing the URL parameter ${highlight(
57+
`${configSrc} The redirection source URL ${pc.cyan(urlSource)} is missing the URL parameter ${pc.cyan(
5858
routeSegment
59-
)} used by the redirection target URL ${highlight(urlTarget)}`
59+
)} used by the redirection target URL ${pc.cyan(urlTarget)}`
6060
)
6161
}
6262
})
6363
}
64-
65-
function highlight(str: string) {
66-
return pc.bold(str)
67-
}

‎vite-plugin-ssr/shared/route/resolveRouteString.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function resolveRouteString(routeString: string, urlPathname: string): null | {
5050
} else if (routeSegment && isParam(routeSegment)) {
5151
assertWarning(
5252
!routeSegment.startsWith(PARAM_TOKEN_OLD),
53-
`Outdated Route String ${pc.bold(routeString)}, use ${pc.bold(
53+
`Outdated Route String ${pc.cyan(routeString)}, use ${pc.cyan(
5454
routeString.split(PARAM_TOKEN_OLD).join(PARAM_TOKEN_NEW)
5555
)} instead.`,
5656
{ onlyOnce: true }
@@ -128,6 +128,6 @@ function highlight(routeString: string) {
128128
if (routeString === '') {
129129
routeString = "''"
130130
}
131-
return pc.bold(routeString)
131+
return pc.cyan(routeString)
132132
}
133133
}

‎vite-plugin-ssr/utils/assertDefaultExport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function assertDefaultExportObject(
3030
const exportDefault = fileExports.default
3131
assertUsage(
3232
isObject(exportDefault),
33-
`The ${pc.cyan('export default')} of ${pc.bold(filePath)} should be an object (but it's ${pc.cyan(
33+
`The ${pc.cyan('export default')} of ${filePath} should be an object (but it's ${pc.cyan(
3434
`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`
3535
)} instead)`
3636
)

‎vite-plugin-ssr/utils/trackLogs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function trackLogs() {
1818
var methodOriginal = process[stdName].write
1919
// @ts-ignore
2020
process[stdName].write = function (...args) {
21-
log(pc.blue(pc.bold('*** LOG ***')))
21+
log(pc.bold(pc.blue('*** LOG ***')))
2222
// @ts-ignore
2323
methodOriginal.apply(process[stdName], args)
2424
// @ts-ignore

0 commit comments

Comments
 (0)
Please sign in to comment.