From 06a288376adaef8be8b06c315dc0a8cf0ecdaa06 Mon Sep 17 00:00:00 2001 From: Pim Date: Wed, 25 Sep 2019 17:11:39 +0200 Subject: [PATCH] fix(webpack): dont push to compilersWatching in callback (#6448) --- packages/builder/src/builder.js | 6 +++--- packages/builder/test/__utils__/index.js | 4 +++- packages/builder/test/builder.build.test.js | 2 ++ packages/builder/test/builder.generate.test.js | 8 +++++++- packages/webpack/src/builder.js | 5 +++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index a25bb8c02f..cc01f3bac7 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -157,6 +157,9 @@ export default class Builder { // Generate routes and interpret the template files await this.generateRoutesAndFiles() + // Add vue-app template dir to watchers + this.options.build.watch.push(this.globPathWithExtensions(this.template.dir)) + await this.resolvePlugins() // Start bundle build: webpack, rollup, parcel... @@ -244,9 +247,6 @@ export default class Builder { await this.resolveLoadingIndicator(templateContext) - // Add vue-app template dir to watchers - this.options.build.watch.push(this.globPathWithExtensions(this.template.dir)) - await this.compileTemplates(templateContext) if (this.bundleBuilder) { diff --git a/packages/builder/test/__utils__/index.js b/packages/builder/test/__utils__/index.js index 28ce879c21..e703b3ff7c 100644 --- a/packages/builder/test/__utils__/index.js +++ b/packages/builder/test/__utils__/index.js @@ -2,7 +2,9 @@ export const createNuxt = () => ({ options: { globalName: 'global_name', globals: [], - build: {}, + build: { + watch: [] + }, router: {}, dir: { app: 'app' diff --git a/packages/builder/test/builder.build.test.js b/packages/builder/test/builder.build.test.js index 00d47394f4..bea111acfb 100644 --- a/packages/builder/test/builder.build.test.js +++ b/packages/builder/test/builder.build.test.js @@ -33,6 +33,7 @@ describe('builder: builder build', () => { nuxt.options.srcDir = '/var/nuxt/src' nuxt.options.buildDir = '/var/nuxt/build' nuxt.options.dir = { pages: '/var/nuxt/src/pages' } + nuxt.options.build.template = { dir: '/var/nuxt/src/template' } nuxt.options.build.createRoutes = jest.fn() const bundleBuilder = { build: jest.fn() } @@ -70,6 +71,7 @@ describe('builder: builder build', () => { expect(r).nthCalledWith(3, '/var/nuxt/build', 'dist', 'client') expect(r).nthCalledWith(4, '/var/nuxt/build', 'dist', 'server') expect(builder.generateRoutesAndFiles).toBeCalledTimes(1) + expect(nuxt.options.build.watch).toEqual(['/var/nuxt/src/template/**/*.{vue,js}']) expect(builder.resolvePlugins).toBeCalledTimes(1) expect(bundleBuilder.build).toBeCalledTimes(1) expect(builder._buildStatus).toEqual(2) diff --git a/packages/builder/test/builder.generate.test.js b/packages/builder/test/builder.generate.test.js index 2d7e7b7b56..83b912acf5 100644 --- a/packages/builder/test/builder.generate.test.js +++ b/packages/builder/test/builder.generate.test.js @@ -82,7 +82,7 @@ describe('builder: builder generate', () => { expect(builder.addOptionalTemplates).toBeCalledTimes(1) expect(builder.resolveCustomTemplates).toBeCalledTimes(1) expect(builder.resolveLoadingIndicator).toBeCalledTimes(1) - expect(builder.options.build.watch).toEqual(['/var/nuxt/src/template/**/*.{vue,js}']) + expect(builder.options.build.watch).toEqual([]) expect(builder.compileTemplates).toBeCalledTimes(1) expect(consola.success).toBeCalledTimes(1) expect(consola.success).toBeCalledWith('Nuxt files generated') @@ -237,6 +237,7 @@ describe('builder: builder generate', () => { const nuxt = createNuxt() nuxt.options.srcDir = '/var/nuxt/src' nuxt.options.build = { + watch: [], template: { dir: '/var/nuxt/templates' }, templates: [ '/var/nuxt/templates/foo.js', @@ -275,6 +276,7 @@ describe('builder: builder generate', () => { name: 'test_loading_indicator' } nuxt.options.build = { + watch: [], template: { dir: '/var/nuxt/templates' } } const builder = new Builder(nuxt, BundleBuilder) @@ -301,6 +303,7 @@ describe('builder: builder generate', () => { name: '@/app/template.vue' } nuxt.options.build = { + watch: [], template: { dir: '/var/nuxt/templates' } } const builder = new Builder(nuxt, BundleBuilder) @@ -330,6 +333,7 @@ describe('builder: builder generate', () => { name: '@/app/empty.vue' } nuxt.options.build = { + watch: [], template: { dir: '/var/nuxt/templates' } } const builder = new Builder(nuxt, BundleBuilder) @@ -599,6 +603,7 @@ describe('builder: builder generate', () => { const nuxt = createNuxt() nuxt.options.srcDir = '/var/nuxt/src' nuxt.options.build = { + watch: [], createRoutes: jest.fn(), template: { dir: '/var/nuxt/templates' } } @@ -642,6 +647,7 @@ describe('builder: builder generate', () => { pages: '/var/nuxt/pages' } nuxt.options.build = { + watch: [], createRoutes: jest.fn() } nuxt.options.router = { diff --git a/packages/webpack/src/builder.js b/packages/webpack/src/builder.js index 8e2f0b8338..f4e8dfbcb0 100644 --- a/packages/webpack/src/builder.js +++ b/packages/webpack/src/builder.js @@ -136,10 +136,11 @@ export class WebpackBundler { if (err) { return reject(err) } - watching.close = pify(watching.close) - this.compilersWatching.push(watching) resolve() }) + + watching.close = pify(watching.close) + this.compilersWatching.push(watching) }) }