Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing new line for certain logs #54442

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions packages/next/src/build/output/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,66 @@ export const prefixes = {
info: '- ' + chalk.cyan('info'),
event: '- ' + chalk.magenta('event'),
trace: '- ' + chalk.magenta('trace'),
} as const

const LOGGING_METHOD = {
log: 'log',
warn: 'warn',
error: 'error',
} as const

function prefixedLog(prefixType: keyof typeof prefixes, ...message: any[]) {
if ((message[0] === '' || message[0] === undefined) && message.length === 1) {
message.shift()
}

const consoleMethod: keyof typeof LOGGING_METHOD =
prefixType in LOGGING_METHOD
? LOGGING_METHOD[prefixType as keyof typeof LOGGING_METHOD]
: 'log'

const prefix = prefixes[prefixType]
// If there's no message, don't print the prefix but a new line
if (message.length === 0) {
console[consoleMethod]('')
} else {
console[consoleMethod](prefix, ...message)
}
}

export function wait(...message: any[]) {
console.log(prefixes.wait, ...message)
prefixedLog('wait', ...message)
}

export function error(...message: any[]) {
console.error(prefixes.error, ...message)
prefixedLog('error', ...message)
}

export function warn(...message: any[]) {
console.warn(prefixes.warn, ...message)
prefixedLog('warn', ...message)
}

export function ready(...message: any[]) {
console.log(prefixes.ready, ...message)
prefixedLog('ready', ...message)
}

export function info(...message: any[]) {
console.log(prefixes.info, ...message)
prefixedLog('info', ...message)
}

export function event(...message: any[]) {
console.log(prefixes.event, ...message)
prefixedLog('event', ...message)
}

export function trace(...message: any[]) {
console.log(prefixes.trace, ...message)
prefixedLog('trace', ...message)
}

const warnOnceMessages = new Set()
export function warnOnce(...message: any[]) {
if (!warnOnceMessages.has(message[0])) {
warnOnceMessages.add(message.join(' '))

warn(...message)
}
}
1 change: 1 addition & 0 deletions packages/next/src/lib/eslint/runLintCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ async function lint(
eslint = new ESLint(options)
}
} else {
Log.warn('')
Log.warn(
'The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config'
)
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/lib/metadata/resolvers/resolve-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export function getSocialImageFallbackMetadataBase(
}

if (isMetadataBaseMissing) {
Log.warnOnce('')
Log.warnOnce(
`\nmetadata.metadataBase is not set for resolving social open graph or twitter images, using "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
`metadata.metadataBase is not set for resolving social open graph or twitter images, using "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
)
}

Expand Down