mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 22:55:13 +00:00
e5d202badb
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
42 lines
927 B
JavaScript
42 lines
927 B
JavaScript
import consola from 'consola'
|
|
import exit from 'exit'
|
|
import { checkDependencies } from './utils/dependencies'
|
|
import { fatalBox } from './utils/formatting'
|
|
|
|
let _setup = false
|
|
|
|
export default function setup ({ dev }) {
|
|
// Apply default NODE_ENV if not provided
|
|
if (!process.env.NODE_ENV) {
|
|
process.env.NODE_ENV = dev ? 'development' : 'production'
|
|
}
|
|
|
|
if (_setup) {
|
|
return
|
|
}
|
|
_setup = true
|
|
|
|
checkDependencies()
|
|
|
|
// Global error handler
|
|
/* istanbul ignore next */
|
|
process.on('unhandledRejection', (err) => {
|
|
consola.error(err)
|
|
})
|
|
|
|
// Exit process on fatal errors
|
|
/* istanbul ignore next */
|
|
consola.addReporter({
|
|
log (logObj) {
|
|
if (logObj.type === 'fatal') {
|
|
const errorMessage = String(logObj.args[0])
|
|
process.stderr.write(fatalBox(errorMessage))
|
|
exit(1)
|
|
}
|
|
}
|
|
})
|
|
|
|
// Wrap all console logs with consola for better DX
|
|
consola.wrapConsole()
|
|
}
|