Skip to content

Commit

Permalink
chore: tweak server start output (#8582)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Jun 14, 2022
1 parent 73e1775 commit 3439132
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/vite/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function printServerUrls(
info: Logger['info']
): void {
const urls: Array<{ label: string; url: string }> = []
const notes: Array<{ label: string; message: string }> = []

if (hostname.host && loopbackHosts.has(hostname.host)) {
let hostnameName = hostname.name
Expand All @@ -191,9 +192,11 @@ function printServerUrls(
})

if (hostname.name === 'localhost') {
urls.push({
label: 'Network',
url: colors.dim(`use ${colors.white(colors.bold('--host'))} to expose`)
notes.push({
label: 'Hint',
message: colors.dim(
`Use ${colors.white(colors.bold('--host'))} to expose to network.`
)
})
}
} else {
Expand All @@ -217,9 +220,17 @@ function printServerUrls(
})
}

const length = urls.reduce(
(length, { label }) => Math.max(length, label.length),
0
if (!hostname.host || wildcardHosts.has(hostname.host)) {
notes.push({
label: 'Note',
message: colors.dim(
'You are using a wildcard host. Ports might be overriden.'
)
})
}

const length = Math.max(
...[...urls, ...notes].map(({ label }) => label.length)
)
const print = (
iconWithColor: string,
Expand All @@ -236,11 +247,7 @@ function printServerUrls(
urls.forEach(({ label, url: text }) => {
print(colors.green('➜'), label, text)
})
if (!hostname.host || wildcardHosts.has(hostname.host)) {
print(
colors.bold(colors.blue('ⓘ')),
'Note',
colors.dim('You are using a wildcard host. Ports might be overriden.')
)
}
notes.forEach(({ label, message: text }) => {
print(colors.white('❖'), label, text)
})
}

0 comments on commit 3439132

Please sign in to comment.