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

v2.14.7 #8195

Merged
merged 27 commits into from
Oct 15, 2020
Merged

v2.14.7 #8195

Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d7a8548
chore(deps): update all non-major dependencies (#8101)
renovate[bot] Sep 28, 2020
3aa02cf
chore(deps): update all non-major dependencies (#8131)
renovate[bot] Sep 30, 2020
79440f3
fix(vue-app): scrollRestoration hasn't set (#8055)
Kolobok12309 Sep 30, 2020
8abdc17
fix(vue-app): use mixin to provide `this.$nuxt` (#8068)
danielroe Sep 30, 2020
afc2e2a
chore(deps): lock file maintenance (#8126)
renovate[bot] Sep 30, 2020
61e93d0
Revert "fix(vue-app): use mixin to provide `this.$nuxt` (#8068)"
clarkdo Sep 30, 2020
dfaa196
chore(example): remove usage of axios in layout-transitions
Atinux Oct 6, 2020
34f3211
fix(generator): handle when no `routes.json` defined (#8166)
Atinux Oct 8, 2020
202f355
fix(cli): mode deprecation with explicit spa or universal flag (#8134)
clarkdo Oct 8, 2020
f0c1375
chore(deps): update all non-major dependencies (#8137)
renovate[bot] Oct 8, 2020
1b1ef37
chore(deps): update dependency upath to v2 (#8157)
renovate[bot] Oct 8, 2020
05353fc
chore(deps): lock file maintenance (#8147)
renovate[bot] Oct 8, 2020
81030be
fix(types): make `NuxtConfig` an interface (#8169)
danielroe Oct 9, 2020
00c9dc3
chore(deps): update dependency @types/node to ^12.12.67 (#8171)
renovate[bot] Oct 9, 2020
a748cf0
fix(types): add type for `serverMiddleware` object format (#8182)
danielroe Oct 10, 2020
a52b5af
chore(deps): lock file maintenance (#8191)
renovate[bot] Oct 13, 2020
9c4dac3
fix(vue-app): use getter to provide `this.$nuxt` (#8170)
danielroe Oct 13, 2020
5b87d1c
chore(deps): update all non-major dependencies (#8177)
renovate[bot] Oct 13, 2020
819afcd
fix(cli): avoid error about `nuxt-edge` if installed in parent `node_…
pi0 Oct 13, 2020
b533877
chore(deps): update all non-major dependencies (#8197)
renovate[bot] Oct 13, 2020
7e1ecfe
chore: update yarn.lock
pi0 Oct 13, 2020
5842a64
chore(deps): update dependency @nuxt/opencollective to ^0.3.2 (#8201)
renovate[bot] Oct 13, 2020
d9f4822
fix(cli): rebuild if process.env changes in nuxt.config (#8200)
pi0 Oct 14, 2020
c75ac80
fix(babel-preset-app): always transpile optional chaining and nullish…
pi0 Oct 14, 2020
044d07c
chore(deps): update all non-major dependencies to ^7.12.0 (#8207)
renovate[bot] Oct 15, 2020
7e7190b
fix: add better logs for DX with target option (#8206)
Atinux Oct 15, 2020
265d0e7
v2.14.7
pi0 Oct 15, 2020
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
2 changes: 1 addition & 1 deletion distributions/nuxt-start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"vue-client-only": "^2.0.0",
"vue-meta": "^2.4.0",
"vue-no-ssr": "^1.1.1",
"vue-router": "^3.4.3",
"vue-router": "^3.4.6",
"vuex": "^3.5.1"
},
"engines": {
Expand Down
1 change: 0 additions & 1 deletion examples/layout-transitions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "example-layout-transitions",
"dependencies": {
"axios": "^0.19.0",
"nuxt": "latest"
},
"scripts": {
Expand Down
6 changes: 2 additions & 4 deletions examples/layout-transitions/pages/users-2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
</template>

<script>
import axios from 'axios'

export default {
async asyncData ({ query }) {
const page = +(query.page || 1)
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
return {
page,
totalPages: data.total_pages,
Expand All @@ -50,7 +48,7 @@ export default {
watch: {
async '$route.query.page' (page) {
this.$nuxt.$loading.start()
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
this.users = data.data
this.transitionName = this.getTransitionName(page)
this.page = +(page || 1)
Expand Down
4 changes: 1 addition & 3 deletions examples/layout-transitions/pages/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
</template>

<script>
import axios from 'axios'

export default {
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
watchQuery: ['page'],
Expand All @@ -42,7 +40,7 @@ export default {
},
async asyncData ({ query }) {
const page = +(query.page || 1)
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
return {
page,
totalPages: data.total_pages,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"@vue/server-test-utils": "^1.1.0",
"@vue/test-utils": "^1.1.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.3.0",
"babel-jest": "^26.5.2",
"consola": "^2.15.0",
"create-require": "^1.0.2",
"cross-spawn": "^7.0.3",
"eslint": "^7.9.0",
"eslint": "^7.11.0",
"eslint-multiplexer": "^2.0.0",
"esm": "^3.2.25",
"execa": "^3.4.0",
Expand All @@ -61,18 +61,18 @@
"got": "^11.7.0",
"improved-yarn-audit": "^2.3.1",
"is-wsl": "^2.2.0",
"jest": "^26.4.2",
"jest": "^26.5.3",
"jiti": "^0.1.11",
"jsdom": "^16.4.0",
"klaw-sync": "^6.0.0",
"lerna": "^3.22.1",
"lodash": "^4.17.20",
"node-fetch": "^2.6.1",
"node-sass": "^4.14.1",
"puppeteer-core": "^5.3.0",
"puppeteer-core": "^5.3.1",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"rollup": "2.28.1",
"rollup": "2.29.0",
"rollup-plugin-license": "^2.2.0",
"sass-loader": "^8.0.2",
"sort-package-json": "^1.46.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"pify": "^4.0.1",
"semver": "^7.3.2",
"serialize-javascript": "^5.0.1",
"upath": "^1.2.0"
"upath": "^2.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"pretty-bytes": "^5.4.1",
"serve-static": "^1.14.1",
"std-env": "^2.2.1",
"upath": "^1.2.0",
"upath": "^2.0.0",
"wrap-ansi": "^6.2.0"
},
"publishConfig": {
Expand Down
19 changes: 7 additions & 12 deletions packages/cli/src/run.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { existsSync } from 'fs'
import { resolve } from 'path'
import execa from 'execa'
import consola from 'consola'
import { name as pkgName } from '../package.json'
import NuxtCommand from './command'
import setup from './setup'
import getCommand from './commands'
import { isNuxtDir } from './utils/dir'

function packageExists (name) {
try {
require.resolve(name)
return true
} catch (e) {
return false
}
}

export default async function run (_argv, hooks = {}) {
// Check for not installing both nuxt and nuxt-edge
const dupPkg = '@nuxt/' + (pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge')
if (packageExists(dupPkg)) {
throw new Error('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
const dupPkg = pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge'
const dupPkgJSON = resolve(__dirname, '../..' /* dist/../.. */, dupPkg, 'package.json')
if (existsSync(dupPkgJSON) && require(dupPkgJSON).name !== '@nuxt/' + dupPkg) {
consola.warn('Both `nuxt` and `nuxt-edge` dependencies are installed! Please choose one and remove the other one from dependencies.')
}

// Read from process.argv
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path'
import defaultsDeep from 'lodash/defaultsDeep'
import { loadNuxtConfig as _loadNuxtConfig, getDefaultNuxtConfig } from '@nuxt/config'
import { MODES } from '@nuxt/utils'

export async function loadNuxtConfig (argv, configContext) {
const rootDir = path.resolve(argv._[0] || '.')
Expand All @@ -18,9 +17,11 @@ export async function loadNuxtConfig (argv, configContext) {
}
})

// Nuxt Mode
options.mode =
(argv.spa && MODES.spa) || (argv.universal && MODES.universal) || options.mode
if (argv.spa === true) {
options.ssr = false
} else if (argv.universal === true) {
options.ssr = true
}

// Server options
options.server = defaultsDeep({
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/test/unit/run-edge.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import consola from 'consola'
import getCommand from '../../src/commands'
import run from '../../src/run'

jest.mock('../../src/commands')

jest.mock('../../package.json', () => ({
name: '@nuxt/cli-edge'
}))

describe('run in edge', () => {
test('throws error if nuxt and nuxt-edge are installed', async () => {
await expect(run())
.rejects.toThrow('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
const mockedCommand = { run: jest.fn(() => Promise.resolve({})) }
getCommand.mockImplementationOnce(() => Promise.resolve(mockedCommand))
await run()
expect(consola.warn).toHaveBeenCalledWith('Both `nuxt` and `nuxt-edge` dependencies are installed! Please choose one and remove the other one from dependencies.')
})
})
8 changes: 5 additions & 3 deletions packages/cli/test/unit/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDefaultNuxtConfig } from '@nuxt/config'
import { TARGETS, MODES } from '@nuxt/utils'
import { TARGETS } from '@nuxt/utils'
import { consola } from '../utils'
import { loadNuxtConfig } from '../../src/utils/config'
import * as utils from '../../src/utils'
Expand All @@ -25,7 +25,8 @@ describe('cli/utils', () => {

const options = await loadNuxtConfig(argv)
expect(options.rootDir).toBe(process.cwd())
expect(options.mode).toBe(MODES.universal)
expect(options.mode).toBeUndefined()
expect(options.ssr).toBe(true)
expect(options.server.host).toBe('localhost')
expect(options.server.port).toBe(3000)
expect(options.server.socket).not.toBeDefined()
Expand All @@ -41,7 +42,8 @@ describe('cli/utils', () => {
const options = await loadNuxtConfig(argv)
expect(options.testOption).toBe(true)
expect(options.rootDir).toBe('/some/path')
expect(options.mode).toBe(MODES.spa)
expect(options.mode).toBe('supercharged')
expect(options.ssr).toBe(false)
expect(options.server.host).toBe('nuxt-host')
expect(options.server.port).toBe(3001)
expect(options.server.socket).toBe('/var/run/nuxt.sock')
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"consola": "^2.15.0",
"fs-extra": "^8.1.0",
"html-minifier": "^4.0.0",
"node-html-parser": "^1.2.20"
"node-html-parser": "^1.3.1"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 7 additions & 1 deletion packages/generator/src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ export default class Generator {
if (this.options.router.mode === 'hash') {
routes = ['/']
} else {
routes = flatRoutes(this.getAppRoutes())
try {
routes = flatRoutes(this.getAppRoutes())
} catch (err) {
// Case: where we use custom router.js
// https://github.com/nuxt-community/router-module/issues/83
routes = ['/']
}
}
routes = routes.filter(route => this.shouldGenerateRoute(route))
routes = this.decorateWithPayloads(routes, generateRoutes)
Expand Down
2 changes: 1 addition & 1 deletion packages/types/config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ export interface NuxtOptions extends Configuration {
watchers: NuxtOptionsWatchers
}

export type NuxtConfig = Partial<NuxtOptions>
export interface NuxtConfig extends Partial<NuxtOptions> {}
2 changes: 1 addition & 1 deletion packages/types/config/server-middleware.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import { NextHandleFunction } from 'connect'

export type ServerMiddleware = NextHandleFunction

export type NuxtOptionsServerMiddleware = string | { path: string, prefix?: boolean, handler: string | ServerMiddleware } | ServerMiddleware
export type NuxtOptionsServerMiddleware = string | { path: string, prefix?: boolean, handler: string | ServerMiddleware } | ServerMiddleware | Record<string, ServerMiddleware>
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
],
"dependencies": {
"@types/autoprefixer": "^9.7.2",
"@types/babel__core": "^7.1.9",
"@types/babel__core": "^7.1.10",
"@types/compression": "^1.7.0",
"@types/connect": "^3.4.33",
"@types/etag": "^1.8.0",
"@types/file-loader": "^4.2.0",
"@types/html-minifier": "^4.0.0",
"@types/less": "^3.0.1",
"@types/node": "^12.12.62",
"@types/node": "^12.12.67",
"@types/node-sass": "^4.11.1",
"@types/optimize-css-assets-webpack-plugin": "^5.0.1",
"@types/pug": "^2.0.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
],
"dependencies": {
"node-fetch": "^2.6.1",
"unfetch": "^4.1.0",
"unfetch": "^4.2.0",
"vue": "^2.6.12",
"vue-client-only": "^2.0.0",
"vue-meta": "^2.4.0",
"vue-no-ssr": "^1.1.1",
"vue-router": "^3.4.3",
"vue-router": "^3.4.6",
"vue-template-compiler": "^2.6.12",
"vuex": "^3.5.1"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-app/template/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default {
},
created () {
// Add this.$nuxt in child instances
Vue.prototype.<%= globals.nuxt %> = this
this.$root.$options.<%= globals.nuxt %> = this

if (process.client) {
// add to window so we can listen when ready
window.<%= globals.nuxt %> = <%= (globals.nuxt !== '$nuxt' ? 'window.$nuxt = ' : '') %>this
Expand Down
7 changes: 7 additions & 0 deletions packages/vue-app/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ Vue.component(NuxtChild.name, NuxtChild)
// Component: <Nuxt>
Vue.component(Nuxt.name, Nuxt)

Object.defineProperty(Vue.prototype, '<%= globals.nuxt %>', {
get() {
return this.$root.$options.<%= globals.nuxt %>
},
configurable: true
})

<% if (features.meta) {
// vue-meta configuration
const vueMetaOptions = {
Expand Down
10 changes: 5 additions & 5 deletions packages/vue-app/template/router.scrollBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
<%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, space-before-function-paren */' : '' %>
export default <%= serializeFunction(router.scrollBehavior) %>
<%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, space-before-function-paren */' : '' %>
<% } else { %>import { getMatchedComponents } from './utils'
<% } else { %>import { getMatchedComponents, setScrollRestoration } from './utils'

if (process.client) {
if ('scrollRestoration' in window.history) {
window.history.scrollRestoration = 'manual'
setScrollRestoration('manual')

// reset scrollRestoration to auto when leaving page, allowing page reload
// and back-navigation from other pages to use the browser to restore the
// scrolling position.
window.addEventListener('beforeunload', () => {
window.history.scrollRestoration = 'auto'
setScrollRestoration('auto')
})

// Setting scrollRestoration to manual again when returning to this page.
window.addEventListener('load', () => {
window.history.scrollRestoration = 'manual'
setScrollRestoration('manual')
})
}
}

export default function (to, from, savedPosition) {
export default function (to, from, savedPosition) {
// If the returned position is falsy or an empty object, will retain current scroll position
let position = false

Expand Down
6 changes: 6 additions & 0 deletions packages/vue-app/template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,9 @@ export function stripTrailingSlash (path) {
export function isSamePath (p1, p2) {
return stripTrailingSlash(p1) === stripTrailingSlash(p2)
}

export function setScrollRestoration (newVal) {
try {
window.history.scrollRestoration = newVal;
} catch(e) {}
}
4 changes: 2 additions & 2 deletions packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@nuxt/utils": "2.14.6",
"babel-loader": "^8.1.0",
"cache-loader": "^4.1.0",
"caniuse-lite": "^1.0.30001133",
"caniuse-lite": "^1.0.30001148",
"chalk": "^3.0.0",
"consola": "^2.15.0",
"create-require": "^1.0.2",
Expand All @@ -26,7 +26,7 @@
"glob": "^7.1.6",
"hard-source-webpack-plugin": "^0.13.1",
"hash-sum": "^2.0.0",
"html-webpack-plugin": "^4.4.1",
"html-webpack-plugin": "^4.5.0",
"memory-fs": "^0.4.1",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"pify": "^4.0.1",
Expand Down
13 changes: 13 additions & 0 deletions test/dev/ssr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ describe('ssr', () => {
await stressTest('/asyncData')
})

test('does not share state', async () => {
const [page1, page2] = await Promise.all([
nuxt.server.renderRoute('/context'),
nuxt.server.renderRoute('/context/child')
])

expect(page1.html).toContain('vm: /context')
expect(page1.html).toContain('context: /context')

expect(page2.html).toContain('vm: /context/child')
expect(page2.html).toContain('context: /context/child')
})

// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/ssr/pages/context.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<section data-test="parent">
<pre>vm: {{ $route.fullPath }}</pre>
<pre>context: {{ $nuxt.context.route.fullPath }}</pre>
</section>

<NuxtChild />
</div>
</template>