Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(config): deprecate mode option #8044

Merged
merged 6 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/config/src/config/_common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import capitalize from 'lodash/capitalize'
import env from 'std-env'
import { TARGETS, MODES } from '@nuxt/utils'
import { TARGETS } from '@nuxt/utils'

export default () => ({
// Env
Expand All @@ -17,9 +17,10 @@ export default () => ({
// Rendering
ssr: true,

// TODO: remove in Nuxt 3
// Mode
mode: MODES.universal,
// Mode (deprecated)
mode: undefined,

// Modern
modern: undefined,

// Modules
Expand Down
9 changes: 9 additions & 0 deletions packages/config/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export function getNuxtConfig (_options) {
options.target = 'server'
}

// Deprecate Mode
if (options.mode) {
if ((options.mode === MODES.universal && options.ssr) || (options.mode === MODES.spa && !options.ssr)) {
consola.warn('`mode` option is deprecated. You can safely remove it from `nuxt.config`')
} else {
consola.warn('`mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`')
}
}

// SSR root option
if (options.ssr === false) {
options.mode = MODES.spa
Expand Down
2 changes: 1 addition & 1 deletion packages/config/test/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Object {
"server_error": "Server error",
"server_error_details": "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.",
},
"mode": "universal",
"mode": undefined,
"modern": undefined,
"modes": Object {
"spa": Object {
Expand Down
4 changes: 2 additions & 2 deletions packages/config/test/config/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Object {
"server_error": "Server error",
"server_error_details": "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.",
},
"mode": "universal",
"mode": undefined,
"modern": undefined,
"modes": Object {
"spa": Object {
Expand Down Expand Up @@ -617,7 +617,7 @@ Object {
"server_error": "Server error",
"server_error_details": "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.",
},
"mode": "universal",
"mode": undefined,
"modern": undefined,
"modes": Object {
"spa": Object {
Expand Down
1 change: 1 addition & 0 deletions packages/types/config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface NuxtOptions extends Configuration {
layoutTransition: Transition
loading: NuxtOptionsLoading | false | string
loadingIndicator: NuxtOptionsLoadingIndicator | false | string
/** @deprecated Use ssr option instead */
mode: 'spa' | 'universal'
target: 'server' | 'static'
modern: 'client' | 'server' | boolean
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/with-config/with-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const hooks = [

describe('with-config', () => {
buildFixture('with-config', () => {
expect(consola.warn).toHaveBeenCalledTimes(7)
expect(consola.warn).toHaveBeenCalledTimes(8)
expect(consola.fatal).toHaveBeenCalledTimes(0)
expect(consola.warn.mock.calls).toMatchObject([
['`router.scrollBehavior` property is deprecated in favor of using `~/app/router.scrollBehavior.js` file, learn more: https://nuxtjs.org/api/configuration-router#scrollbehavior'],
['`mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`'],
['Unknown mode: unknown. Falling back to universal'],
['Invalid plugin mode (server/client/all): \'abc\'. Falling back to \'all\''],
[{
Expand Down