From 560cb57443ada3f16a1073c22f616937f8b581f3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 9 Aug 2019 15:02:53 +0430 Subject: [PATCH] refactor(config): rename `devModules` to `buildModules` (#6203) --- packages/config/src/config/_app.js | 2 +- packages/config/src/options.js | 9 ++++++++- packages/config/test/__snapshots__/options.test.js.snap | 2 +- .../config/test/config/__snapshots__/index.test.js.snap | 4 ++-- packages/config/test/options.test.js | 7 +++++++ packages/core/src/module.js | 8 ++++---- packages/core/test/module.test.js | 2 +- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/config/src/config/_app.js b/packages/config/src/config/_app.js index cff8bd596f..f4c412c7e4 100644 --- a/packages/config/src/config/_app.js +++ b/packages/config/src/config/_app.js @@ -23,7 +23,7 @@ export default () => ({ css: [], modules: [], - devModules: [], + buildModules: [], layouts: {}, diff --git a/packages/config/src/options.js b/packages/config/src/options.js index 9323d014bd..73c513e585 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -336,6 +336,13 @@ export function getNuxtConfig (_options) { consola.warn('build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.') } + // devModules has been renamed to buildModules + if (typeof options.devModules !== 'undefined') { + consola.warn('`devModules` has been renamed to `buildModules` and will be removed in Nuxt 3.') + options.buildModules.push(...options.devModules) + delete options.devModules + } + // Enable minimize for production builds if (options.build.optimization.minimize === undefined) { options.build.optimization.minimize = !options.dev @@ -376,7 +383,7 @@ export function getNuxtConfig (_options) { // Add loading screen if (options.dev) { - options.devModules.push('@nuxt/loading-screen') + options.buildModules.push('@nuxt/loading-screen') // Disable build indicator for programmatic users if (!options._cli) { options.build.indicator = false diff --git a/packages/config/test/__snapshots__/options.test.js.snap b/packages/config/test/__snapshots__/options.test.js.snap index 000cc02768..c2c6b112fe 100644 --- a/packages/config/test/__snapshots__/options.test.js.snap +++ b/packages/config/test/__snapshots__/options.test.js.snap @@ -143,13 +143,13 @@ Object { "watch": Array [], }, "buildDir": "/var/nuxt/test/.nuxt", + "buildModules": Array [], "cli": Object { "badgeMessages": Array [], }, "css": Array [], "debug": false, "dev": false, - "devModules": Array [], "dir": Object { "app": "app", "assets": "assets", diff --git a/packages/config/test/config/__snapshots__/index.test.js.snap b/packages/config/test/config/__snapshots__/index.test.js.snap index 93d1d3ea21..ba98fa7a70 100644 --- a/packages/config/test/config/__snapshots__/index.test.js.snap +++ b/packages/config/test/config/__snapshots__/index.test.js.snap @@ -123,13 +123,13 @@ Object { "watch": Array [], }, "buildDir": ".nuxt", + "buildModules": Array [], "cli": Object { "badgeMessages": Array [], }, "css": Array [], "debug": undefined, "dev": false, - "devModules": Array [], "dir": Object { "app": "app", "assets": "assets", @@ -450,13 +450,13 @@ Object { "watch": Array [], }, "buildDir": ".nuxt", + "buildModules": Array [], "cli": Object { "badgeMessages": Array [], }, "css": Array [], "debug": undefined, "dev": false, - "devModules": Array [], "dir": Object { "app": "app", "assets": "assets", diff --git a/packages/config/test/options.test.js b/packages/config/test/options.test.js index 0eefbd41ce..7c9d5ace17 100644 --- a/packages/config/test/options.test.js +++ b/packages/config/test/options.test.js @@ -232,6 +232,13 @@ describe('config: options', () => { expect(consola.warn).toHaveBeenCalledWith('vendor has been deprecated due to webpack4 optimization') }) + test('should deprecate devModules', () => { + const config = getNuxtConfig({ devModules: ['foo'], buildModules: ['bar'] }) + expect(consola.warn).toHaveBeenCalledWith('`devModules` has been renamed to `buildModules` and will be removed in Nuxt 3.') + expect(config.devModules).toBe(undefined) + expect(config.buildModules).toEqual(['bar', 'foo']) + }) + test('should deprecate build.extractCSS.allChunks', () => { getNuxtConfig({ build: { extractCSS: { allChunks: true } } }) expect(consola.warn).toHaveBeenCalledWith('build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.') diff --git a/packages/core/src/module.js b/packages/core/src/module.js index 8be703905e..083460d5ef 100644 --- a/packages/core/src/module.js +++ b/packages/core/src/module.js @@ -16,9 +16,9 @@ export default class ModuleContainer { // Call before hook await this.nuxt.callHook('modules:before', this, this.options.modules) - if (this.options.devModules && !this.options._start) { + if (this.options.buildModules && !this.options._start) { // Load every devModule in sequence - await sequence(this.options.devModules, this.addModule.bind(this)) + await sequence(this.options.buildModules, this.addModule.bind(this)) } // Load every module in sequence @@ -136,8 +136,8 @@ export default class ModuleContainer { handler = src } - // Prevent adding devModules-listed entries in production - if (this.options.devModules.includes(handler) && this.options._start) { + // Prevent adding buildModules-listed entries in production + if (this.options.buildModules.includes(handler) && this.options._start) { return } diff --git a/packages/core/test/module.test.js b/packages/core/test/module.test.js index 7037ef010c..8aee02d745 100644 --- a/packages/core/test/module.test.js +++ b/packages/core/test/module.test.js @@ -19,7 +19,7 @@ jest.mock('@nuxt/utils', () => ({ const defaultOptions = { modules: [], - devModules: [] + buildModules: [] } describe('core: module', () => {