fix: lost context in closures

This commit is contained in:
Clark Du 2018-07-25 16:57:43 +01:00
parent 6567c205c9
commit a0ca257263
6 changed files with 9 additions and 9 deletions

View File

@ -4,7 +4,7 @@ const { join } = require('path')
const consola = require('consola') const consola = require('consola')
// Global error handler // Global error handler
process.on('unhandledRejection', consola.error) process.on('unhandledRejection', err => consola.error(err))
// Exit process on fatal errors // Exit process on fatal errors
consola.add({ consola.add({

View File

@ -51,7 +51,7 @@ const nuxt = new Nuxt(options)
const builder = new Builder(nuxt) const builder = new Builder(nuxt)
// Setup hooks // Setup hooks
nuxt.hook('error', consola.fatal) nuxt.hook('error', err => consola.fatal(err))
// Close function // Close function
const close = () => { const close = () => {
@ -69,11 +69,11 @@ if (options.mode !== 'spa' || argv.generate === false) {
builder builder
.build() .build()
.then(close) .then(close)
.catch(consola.fatal) .catch(err => consola.fatal(err))
} else { } else {
// Build + Generate for static deployment // Build + Generate for static deployment
new Generator(nuxt, builder) new Generator(nuxt, builder)
.generate({ build: true }) .generate({ build: true })
.then(close) .then(close)
.catch(consola.fatal) .catch(err => consola.fatal(err))
} }

View File

@ -115,7 +115,7 @@ function startDev(oldInstance) {
} }
}) })
// Start build // Start build
.then(builder.build) .then(() => builder.build())
// Close old nuxt after successful build // Close old nuxt after successful build
.then( .then(
() => () =>

View File

@ -53,4 +53,4 @@ generator
.then(() => { .then(() => {
process.exit(0) process.exit(0)
}) })
.catch(consola.fatal) .catch(err => consola.fatal(err))

View File

@ -52,7 +52,7 @@ options.dev = false
const nuxt = new Nuxt(options) const nuxt = new Nuxt(options)
// Setup hooks // Setup hooks
nuxt.hook('error', consola.fatal) nuxt.hook('error', err => consola.fatal(err))
// Check if project is built for production // Check if project is built for production
const distDir = resolve( const distDir = resolve(

View File

@ -47,7 +47,7 @@ export default class Builder {
// Stop watching on nuxt.close() // Stop watching on nuxt.close()
if (this.options.dev) { if (this.options.dev) {
this.nuxt.hook('close', this.unwatch) this.nuxt.hook('close', () => this.unwatch())
} }
// Initialize shared FS and Cache // Initialize shared FS and Cache
@ -57,7 +57,7 @@ export default class Builder {
// if(!this.options.dev) { // if(!this.options.dev) {
// TODO: enable again when unsafe concern resolved.(common/options.js:42) // TODO: enable again when unsafe concern resolved.(common/options.js:42)
// this.nuxt.hook('build:done', this.generateConfig) // this.nuxt.hook('build:done', () => this.generateConfig())
// } // }
} }