From a0ca2572633e8dcfd7807c10e8fe1fc9a6112058 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Wed, 25 Jul 2018 16:57:43 +0100 Subject: [PATCH] fix: lost context in closures --- bin/nuxt | 2 +- bin/nuxt-build | 6 +++--- bin/nuxt-dev | 2 +- bin/nuxt-generate | 2 +- bin/nuxt-start | 2 +- lib/builder/builder.js | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/nuxt b/bin/nuxt index 79a2ed62b1..c59441bb48 100755 --- a/bin/nuxt +++ b/bin/nuxt @@ -4,7 +4,7 @@ const { join } = require('path') const consola = require('consola') // Global error handler -process.on('unhandledRejection', consola.error) +process.on('unhandledRejection', err => consola.error(err)) // Exit process on fatal errors consola.add({ diff --git a/bin/nuxt-build b/bin/nuxt-build index c4db7dd9e6..83463fa97d 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -51,7 +51,7 @@ const nuxt = new Nuxt(options) const builder = new Builder(nuxt) // Setup hooks -nuxt.hook('error', consola.fatal) +nuxt.hook('error', err => consola.fatal(err)) // Close function const close = () => { @@ -69,11 +69,11 @@ if (options.mode !== 'spa' || argv.generate === false) { builder .build() .then(close) - .catch(consola.fatal) + .catch(err => consola.fatal(err)) } else { // Build + Generate for static deployment new Generator(nuxt, builder) .generate({ build: true }) .then(close) - .catch(consola.fatal) + .catch(err => consola.fatal(err)) } diff --git a/bin/nuxt-dev b/bin/nuxt-dev index 8c0af0f216..419b12c4e0 100755 --- a/bin/nuxt-dev +++ b/bin/nuxt-dev @@ -115,7 +115,7 @@ function startDev(oldInstance) { } }) // Start build - .then(builder.build) + .then(() => builder.build()) // Close old nuxt after successful build .then( () => diff --git a/bin/nuxt-generate b/bin/nuxt-generate index 5c213de593..d32cc6df90 100755 --- a/bin/nuxt-generate +++ b/bin/nuxt-generate @@ -53,4 +53,4 @@ generator .then(() => { process.exit(0) }) - .catch(consola.fatal) + .catch(err => consola.fatal(err)) diff --git a/bin/nuxt-start b/bin/nuxt-start index abd598e3f9..8258cd88d0 100755 --- a/bin/nuxt-start +++ b/bin/nuxt-start @@ -52,7 +52,7 @@ options.dev = false const nuxt = new Nuxt(options) // Setup hooks -nuxt.hook('error', consola.fatal) +nuxt.hook('error', err => consola.fatal(err)) // Check if project is built for production const distDir = resolve( diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 763a4de4e2..2cd4494dda 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -47,7 +47,7 @@ export default class Builder { // Stop watching on nuxt.close() if (this.options.dev) { - this.nuxt.hook('close', this.unwatch) + this.nuxt.hook('close', () => this.unwatch()) } // Initialize shared FS and Cache @@ -57,7 +57,7 @@ export default class Builder { // if(!this.options.dev) { // 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()) // } }