@nuxt/app-edge
Advanced tools
Comparing version 2.3.0-25673137.81b25ee to 2.3.0-25673151.96bdcab
@@ -11,2 +11,3 @@ # Change Log | ||
* **app:** lint all templates ([#4175](https://github.com/nuxt/nuxt.js/issues/4175)) ([96bdcab](https://github.com/nuxt/nuxt.js/commit/96bdcab)) | ||
* **app:** throw an error when layout property is not string ([#4142](https://github.com/nuxt/nuxt.js/issues/4142)) ([f5530ad](https://github.com/nuxt/nuxt.js/commit/f5530ad)) | ||
@@ -13,0 +14,0 @@ * **publish:** set each package's publishConfig to public ([28b246d](https://github.com/nuxt/nuxt.js/commit/28b246d)), closes [lerna/lerna#178](https://github.com/lerna/lerna/issues/178) |
/*! | ||
* @nuxt/app-edge v2.3.0-25673137.81b25ee (c) 2016-2018 | ||
* @nuxt/app-edge v2.3.0-25673151.96bdcab (c) 2016-2018 | ||
@@ -17,3 +17,3 @@ * - All the amazing contributors | ||
var name = "@nuxt/app-edge"; | ||
var version = "2.3.0-25673137.81b25ee"; | ||
var version = "2.3.0-25673151.96bdcab"; | ||
var repository = "nuxt/nuxt.js"; | ||
@@ -20,0 +20,0 @@ var license = "MIT"; |
{ | ||
"name": "@nuxt/app-edge", | ||
"version": "2.3.0-25673137.81b25ee", | ||
"version": "2.3.0-25673151.96bdcab", | ||
"repository": "nuxt/nuxt.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -15,3 +15,3 @@ import Vue from 'vue' | ||
const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`).join(',') %> } | ||
const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`).join(',') %> }<%= isTest ? '// eslint-disable-line' : '' %> | ||
@@ -21,3 +21,5 @@ <% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %> | ||
export default { | ||
<%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %> | ||
head: <%= serialize(head).replace(/:\w+\(/gm, ':function(') %>, | ||
<%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %> | ||
render(h, props) { | ||
@@ -40,3 +42,3 @@ <% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %> | ||
return h('div',{ | ||
return h('div', { | ||
domProps: { | ||
@@ -54,6 +56,6 @@ id: '<%= globals.id %>' | ||
}), | ||
beforeCreate () { | ||
beforeCreate() { | ||
Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt) | ||
}, | ||
created () { | ||
created() { | ||
// Add this.$nuxt in child instances | ||
@@ -72,3 +74,3 @@ Vue.prototype.<%= globals.nuxt %> = this | ||
<% if (loading) { %> | ||
mounted () { | ||
mounted() { | ||
this.$loading = this.$refs.loading | ||
@@ -82,3 +84,3 @@ }, | ||
<% if (loading) { %> | ||
errorChanged () { | ||
errorChanged() { | ||
if (this.nuxt.err && this.$loading) { | ||
@@ -91,3 +93,3 @@ if (this.$loading.fail) this.$loading.fail() | ||
<% if (splitChunks.layouts) { %> | ||
setLayout (layout) { | ||
setLayout(layout) { | ||
<% if (debug) { %> | ||
@@ -102,3 +104,3 @@ if(layout && typeof layout !== 'string') throw new Error('[nuxt] Avoid using non-string value as layout property.') | ||
}, | ||
loadLayout (layout) { | ||
loadLayout(layout) { | ||
const undef = !layout | ||
@@ -105,0 +107,0 @@ const inexisting = !(layouts['_' + layout] || resolvedLayouts['_' + layout]) |
import Vue from 'vue' | ||
import middleware from './middleware' | ||
import { createApp, NuxtError } from './index' | ||
import { | ||
@@ -19,2 +18,3 @@ applyAsyncData, | ||
} from './utils' | ||
import { createApp, NuxtError } from './index' | ||
@@ -33,3 +33,3 @@ const noopData = () => { return {} } | ||
Object.assign(Vue.config, <%= serialize(vue.config) %>) | ||
Object.assign(Vue.config, <%= serialize(vue.config) %>)<%= isTest ? '// eslint-disable-line' : '' %> | ||
@@ -51,3 +51,3 @@ <% if (debug || mode === 'spa') { %> | ||
} | ||
if (handled === true){ | ||
if (handled === true) { | ||
return handled | ||
@@ -85,6 +85,6 @@ } | ||
createApp() | ||
.then(mountApp) | ||
.catch((err) => { | ||
console.error('[nuxt] Error while initializing app', err) | ||
}) | ||
.then(mountApp) | ||
.catch((err) => { | ||
console.error('[nuxt] Error while initializing app', err) | ||
}) | ||
@@ -114,6 +114,6 @@ function componentOption(component, key, ...args) { | ||
if (from && from.matched.length && from.matched[0].components.default) { | ||
const from_transitions = componentTransitions(from.matched[0].components.default) | ||
Object.keys(from_transitions) | ||
.filter((key) => from_transitions[key] && key.toLowerCase().includes('leave')) | ||
.forEach((key) => { transitions[key] = from_transitions[key] }) | ||
const fromTransitions = componentTransitions(from.matched[0].components.default) | ||
Object.keys(fromTransitions) | ||
.filter(key => fromTransitions[key] && key.toLowerCase().includes('leave')) | ||
.forEach((key) => { transitions[key] = fromTransitions[key] }) | ||
} | ||
@@ -125,3 +125,3 @@ | ||
async function loadAsyncComponents (to, from, next) { | ||
async function loadAsyncComponents(to, from, next) { | ||
// Check if route path changed (this._pathChanged), only if the page is not an error (for validate()) | ||
@@ -147,3 +147,3 @@ this._pathChanged = !!app.nuxt.err || from.path !== to.path | ||
if (Array.isArray(watchQuery)) { | ||
return watchQuery.some((key) => this._diffQuery[key]) | ||
return watchQuery.some(key => this._diffQuery[key]) | ||
} | ||
@@ -160,6 +160,6 @@ return false | ||
} catch (err) { | ||
err = err || {} | ||
const statusCode = (err.statusCode || err.status || (err.response && err.response.status) || 500) | ||
this.error({ statusCode, message: err.message }) | ||
this.<%= globals.nuxt %>.$emit('routeChanged', to, from, err) | ||
const error = err || {} | ||
const statusCode = (error.statusCode || error.status || (error.response && error.response.status) || 500) | ||
this.error({ statusCode, message: error.message }) | ||
this.<%= globals.nuxt %>.$emit('routeChanged', to, from, error) | ||
next(false) | ||
@@ -193,4 +193,4 @@ } | ||
function callMiddleware (Components, context, layout) { | ||
let midd = <%= devalue(router.middleware) %> | ||
function callMiddleware(Components, context, layout) { | ||
let midd = <%= devalue(router.middleware) %><%= isTest ? '// eslint-disable-line' : '' %> | ||
let unknownMiddleware = false | ||
@@ -224,3 +224,3 @@ | ||
async function render (to, from, next) { | ||
async function render(to, from, next) { | ||
if (this._pathChanged === false && this._queryChanged === false) return next() | ||
@@ -350,3 +350,3 @@ // Handle first render on SPA mode | ||
// Only if its slug has changed or is watch query changes | ||
if (this._pathChanged && this._queryChanged || Component._path !== _lastPaths[i]) { | ||
if ((this._pathChanged && this._queryChanged) || Component._path !== _lastPaths[i]) { | ||
Component._dataRefresh = true | ||
@@ -358,3 +358,3 @@ } else if (!this._pathChanged && this._queryChanged) { | ||
} else if (Array.isArray(watchQuery)) { | ||
Component._dataRefresh = watchQuery.some((key) => this._diffQuery[key]) | ||
Component._dataRefresh = watchQuery.some(key => this._diffQuery[key]) | ||
} | ||
@@ -366,3 +366,3 @@ } | ||
let promises = [] | ||
const promises = [] | ||
@@ -384,3 +384,3 @@ const hasAsyncData = ( | ||
<% if (loading) { %> | ||
if(this.$loading.increase) { | ||
if (this.$loading.increase) { | ||
this.$loading.increase(loadingIncrease) | ||
@@ -398,14 +398,14 @@ } | ||
if (hasFetch) { | ||
let p = Component.options.fetch(app.context) | ||
if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { | ||
p = Promise.resolve(p) | ||
let p = Component.options.fetch(app.context) | ||
if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { | ||
p = Promise.resolve(p) | ||
} | ||
p.then((fetchResult) => { | ||
<% if (loading) { %> | ||
if (this.$loading.increase) { | ||
this.$loading.increase(loadingIncrease) | ||
} | ||
p.then((fetchResult) => { | ||
<% if (loading) { %> | ||
if (this.$loading.increase) { | ||
this.$loading.increase(loadingIncrease) | ||
} | ||
<% } %> | ||
}) | ||
promises.push(p) | ||
<% } %> | ||
}) | ||
promises.push(p) | ||
} | ||
@@ -426,6 +426,5 @@ | ||
} catch (error) { | ||
if (!error) { | ||
error = {} | ||
} else if (error.message === 'ERR_REDIRECT') { | ||
} catch (err) { | ||
const error = err || {} | ||
if (error.message === 'ERR_REDIRECT') { | ||
return this.<%= globals.nuxt %>.$emit('routeChanged', to, from, error) | ||
@@ -453,3 +452,3 @@ } | ||
// Fix components format in matched, it's due to code-splitting of vue-router | ||
function normalizeComponents (to, ___) { | ||
function normalizeComponents(to, ___) { | ||
flatMapComponents(to, (Component, _, match, key) => { | ||
@@ -506,3 +505,3 @@ if (typeof Component === 'object' && !Component.options) { | ||
const newData = instance.constructor.options.data.call(instance) | ||
for (let key in newData) { | ||
for (const key in newData) { | ||
Vue.set(instance.$data, key, newData[key]) | ||
@@ -520,3 +519,3 @@ } | ||
function nuxtReady (_app) { | ||
function nuxtReady(_app) { | ||
window.<%= globals.readyCallback %>Cbs.forEach((cb) => { | ||
@@ -553,3 +552,3 @@ if (typeof cb === 'function') { | ||
function hotReloadAPI (_app) { | ||
function hotReloadAPI(_app) { | ||
if (!module.hot) return | ||
@@ -562,3 +561,3 @@ | ||
function addHotReload ($component, depth) { | ||
function addHotReload($component, depth) { | ||
if ($component.$vnode.data._hasHotReload) return | ||
@@ -641,3 +640,3 @@ $component.$vnode.data._hasHotReload = true | ||
router = __app.router | ||
<% if (store) { %>store = __app.store <% } %> | ||
<% if (store) { %>store = __app.store<% } %> | ||
@@ -651,3 +650,3 @@ // Resolve route components | ||
<% if (mode !== 'spa') { %> | ||
// Load layout | ||
// Load layout | ||
const layout = NUXT.layout || 'default' | ||
@@ -654,0 +653,0 @@ await _app.loadLayout(layout) |
@@ -1,2 +0,2 @@ | ||
/* | ||
/*<%= isTest ? ' @vue/component' : '' %> | ||
** From https://github.com/egoist/vue-no-ssr | ||
@@ -3,0 +3,0 @@ ** With the authorization of @egoist |
@@ -0,6 +1,13 @@ | ||
<%= isTest ? '// @vue/component' : '' %> | ||
export default { | ||
name: 'nuxt-child', | ||
functional: true, | ||
props: ['keepAlive', 'keepAliveProps'], | ||
render (h, { parent, data, props }) { | ||
props: { | ||
nuxtChildKey: { | ||
type: String, | ||
default: '' | ||
}, | ||
keepAlive: Boolean | ||
}, | ||
render(h, { parent, data, props }) { | ||
data.nuxtChild = true | ||
@@ -20,3 +27,3 @@ const _parent = parent | ||
const transition = transitions[depth] || defaultTransition | ||
let transitionProps = {} | ||
const transitionProps = {} | ||
transitionsKeys.forEach((key) => { | ||
@@ -28,3 +35,3 @@ if (typeof transition[key] !== 'undefined') { | ||
let listeners = {} | ||
const listeners = {} | ||
listenersKeys.forEach((key) => { | ||
@@ -48,3 +55,3 @@ if (typeof transition[key] === 'function') { | ||
] | ||
if (typeof props.keepAlive !== 'undefined') { | ||
if (props.keepAlive) { | ||
routerView = [ | ||
@@ -51,0 +58,0 @@ h('keep-alive', { props: props.keepAliveProps }, routerView) |
@@ -0,7 +1,8 @@ | ||
<%= isTest ? '// @vue/component' : '' %> | ||
export default { | ||
name: 'nuxt-link', | ||
functional: true, | ||
render (h, { data, children }) { | ||
render(h, { data, children }) { | ||
return h('router-link', data, children) | ||
} | ||
} |
@@ -0,3 +1,4 @@ | ||
<%= isTest ? '// @vue/component' : '' %> | ||
import Vue from 'vue' | ||
import NuxtChild from './nuxt-child' | ||
import { compile } from '../utils' | ||
@@ -13,8 +14,10 @@ <% if (components.ErrorPage) { %> | ||
<% } %> | ||
import NuxtChild from './nuxt-child' | ||
import { compile } from '../utils' | ||
export default { | ||
name: 'nuxt', | ||
props: ['nuxtChildKey', 'keepAlive'], | ||
props: { | ||
nuxtChildKey: String, | ||
keepAlive: Boolean | ||
}, | ||
render(h) { | ||
@@ -35,7 +38,7 @@ // If there is some error | ||
}, | ||
beforeCreate () { | ||
beforeCreate() { | ||
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt) | ||
}, | ||
computed: { | ||
routerViewKey () { | ||
routerViewKey() { | ||
// If nuxtChildKey prop is given or current route has children | ||
@@ -42,0 +45,0 @@ if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) { |
@@ -14,4 +14,6 @@ import Vue from 'vue' | ||
/* Plugins */ | ||
<%= isTest ? '/* eslint-disable camelcase */' : '' %> | ||
<% plugins.forEach((plugin) => { %>import <%= plugin.name %> from '<%= plugin.name %>' // Source: <%= relativeToBuild(plugin.src) %><%= (plugin.ssr===false) ? ' (ssr: false)' : '' %> | ||
<% }) %> | ||
<%= isTest ? '/* eslint-enable camelcase */' : '' %> | ||
@@ -44,5 +46,5 @@ // Component: <no-ssr> | ||
.replace('appear(', 'function(').replace('afterAppear(', 'function(').replace('appearCancelled(', 'function(') | ||
%> | ||
%><%= isTest ? '// eslint-disable-line' : '' %> | ||
async function createApp (ssrContext) { | ||
async function createApp(ssrContext) { | ||
const router = await createRouter(ssrContext) | ||
@@ -55,9 +57,10 @@ | ||
<% if (mode === 'universal') { %> | ||
// Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141 | ||
const registerModule = store.registerModule | ||
store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options)) | ||
// Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141 | ||
const registerModule = store.registerModule | ||
store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options)) | ||
<% } %> | ||
<% } %> | ||
// Create Root instance | ||
// Create Root instance13:14:29: Error: can't open file '.eslintrc.js' (error 2: No such file or directory) | ||
// here we inject the router and store to all child components, | ||
@@ -71,3 +74,3 @@ // making them available everywhere as `this.$router` and `this.$store`. | ||
transitions: [ defaultTransition ], | ||
setTransitions (transitions) { | ||
setTransitions(transitions) { | ||
if (!Array.isArray(transitions)) { | ||
@@ -91,3 +94,3 @@ transitions = [ transitions ] | ||
dateErr: null, | ||
error (err) { | ||
error(err) { | ||
err = err || null | ||
@@ -132,2 +135,3 @@ app.context._errored = !!err | ||
<% if (plugins.length) { %> | ||
const inject = function (key, value) { | ||
@@ -151,3 +155,3 @@ if (!key) throw new Error('inject(key, value) has no key provided') | ||
Object.defineProperty(Vue.prototype, key, { | ||
get () { | ||
get() { | ||
return this.$root.$options[key] | ||
@@ -159,2 +163,3 @@ } | ||
} | ||
<% } %> | ||
@@ -171,2 +176,3 @@ <% if (store) { %> | ||
// Plugin execution | ||
<%= isTest ? '/* eslint-disable camelcase */' : '' %> | ||
<% plugins.filter(p => p.ssr).forEach((plugin) => { %> | ||
@@ -178,2 +184,3 @@ if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %> | ||
}<% } %> | ||
<%= isTest ? '/* eslint-enable camelcase */' : '' %> | ||
@@ -199,4 +206,4 @@ // If server-side, wait for async component to be resolved first | ||
app, | ||
router, | ||
<% if(store) { %>store<% } %> | ||
<% if(store) { %>store,<% } %> | ||
router | ||
} | ||
@@ -203,0 +210,0 @@ } |
@@ -5,3 +5,3 @@ <% if (middleware) { %> | ||
function getModule (filename) { | ||
function getModule(filename) { | ||
const file = files(filename) | ||
@@ -8,0 +8,0 @@ return file.default || file |
import Vue from 'vue' | ||
import Router from 'vue-router' | ||
import { interopDefault } from './utils'; | ||
import { interopDefault } from './utils' | ||
<% function recursiveRoutes(routes, tab, components) { | ||
<% function recursiveRoutes(routes, tab, components, indentCount) { | ||
let res = '' | ||
const baseIndent = tab.repeat(indentCount) | ||
const firstIndent = '\n' + tab.repeat(indentCount + 1) | ||
const nextIndent = ',' + firstIndent | ||
routes.forEach((route, i) => { | ||
@@ -11,15 +14,19 @@ route._name = '_' + hash(route.component) | ||
// @see: https://router.vuejs.org/api/#router-construction-options | ||
res += tab + '{\n' | ||
res += tab + '\tpath: ' + JSON.stringify(route.path) | ||
res += (route.component) ? ',\n\t' + tab + 'component: ' + (splitChunks.pages ? route._name : `() => ${route._name}.default || ${route._name}`) : '' | ||
res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : '' | ||
res += (route.meta) ? ',\n\t' + tab + 'meta: ' + JSON.stringify(route.meta) : '' | ||
res += (typeof route.props !== 'undefined') ? ',\n\t' + tab + 'props: ' + (typeof route.props === 'function' ? serialize(route.props) : JSON.stringify(route.props)) : '' | ||
res += (typeof route.caseSensitive !== 'undefined') ? ',\n\t' + tab + 'caseSensitive: ' + JSON.stringify(route.caseSensitive) : '' | ||
res += (route.alias) ? ',\n\t' + tab + 'alias: ' + JSON.stringify(route.alias) : '' | ||
res += (route.pathToRegexpOptions) ? ',\n\t' + tab + 'pathToRegexpOptions: ' + JSON.stringify(route.pathToRegexpOptions) : '' | ||
res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : '' | ||
res += (route.beforeEnter) ? ',\n\t' + tab + 'beforeEnter: ' + serialize(route.beforeEnter) : '' | ||
res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t', components) + '\n\t' + tab + ']' : '' | ||
res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n') | ||
res += '{' | ||
res += firstIndent + 'path: ' + JSON.stringify(route.path) | ||
res += (route.component) ? nextIndent + 'component: ' + (splitChunks.pages ? route._name : `() => ${route._name}.default || ${route._name}`) : '' | ||
res += (route.redirect) ? nextIndent + 'redirect: ' + JSON.stringify(route.redirect) : '' | ||
res += (route.meta) ? nextIndent + 'meta: ' + JSON.stringify(route.meta) : '' | ||
res += (typeof route.props !== 'undefined') ? nextIndent + 'props: ' + (typeof route.props === 'function' ? serialize(route.props) : JSON.stringify(route.props)) : '' | ||
res += (typeof route.caseSensitive !== 'undefined') ? nextIndent + 'caseSensitive: ' + JSON.stringify(route.caseSensitive) : '' | ||
res += (route.alias) ? nextIndent + 'alias: ' + JSON.stringify(route.alias) : '' | ||
res += (route.pathToRegexpOptions) ? nextIndent + 'pathToRegexpOptions: ' + JSON.stringify(route.pathToRegexpOptions) : '' | ||
res += (route.name) ? nextIndent + 'name: ' + JSON.stringify(route.name) : '' | ||
if (route.beforeEnter) { | ||
if(isTest) { res += ',\n/* eslint-disable indent, semi */' } | ||
res += (isTest ? firstIndent : nextIndent) + 'beforeEnter: ' + serialize(route.beforeEnter) | ||
if(isTest) { res += firstIndent + '/* eslint-enable indent, semi */' } | ||
} | ||
res += (route.children) ? nextIndent + 'children: [' + recursiveRoutes(routes[i].children, tab, components, indentCount + 1) + ']' : '' | ||
res += '\n' + baseIndent + '}' + (i + 1 === routes.length ? '' : ', ') | ||
}) | ||
@@ -29,4 +36,4 @@ return res | ||
const _components = [] | ||
const _routes = recursiveRoutes(router.routes, '\t\t', _components) | ||
%> <%= uniqBy(_components, '_name').map((route) => { | ||
const _routes = recursiveRoutes(router.routes, ' ', _components, 2) | ||
%><%= uniqBy(_components, '_name').map((route) => { | ||
if (!route.component) return '' | ||
@@ -61,3 +68,3 @@ const path = relativeToBuild(route.component) | ||
position = { x: 0, y: 0 } | ||
} else if (to.matched.some((r) => r.components.default.options.scrollToTop)) { | ||
} else if (to.matched.some(r => r.components.default.options.scrollToTop)) { | ||
// if one of the children has scrollToTop option set to true | ||
@@ -98,3 +105,3 @@ position = { x: 0, y: 0 } | ||
export function createRouter () { | ||
export function createRouter() { | ||
return new Router({ | ||
@@ -106,5 +113,5 @@ mode: '<%= router.mode %>', | ||
scrollBehavior, | ||
routes: [ | ||
<%= _routes %> | ||
], | ||
<%= isTest ? '/* eslint-disable quotes */' : '' %> | ||
routes: [<%= _routes %>], | ||
<%= isTest ? '/* eslint-enable quotes */' : '' %> | ||
<% if (router.parseQuery) { %>parseQuery: <%= serialize(router.parseQuery).replace('parseQuery(', 'function(') %>,<% } %> | ||
@@ -111,0 +118,0 @@ <% if (router.stringifyQuery) { %>stringifyQuery: <%= serialize(router.stringifyQuery).replace('stringifyQuery(', 'function(') %>,<% } %> |
@@ -0,7 +1,7 @@ | ||
import { stringify } from 'querystring' | ||
import Vue from 'vue' | ||
import { stringify } from 'querystring' | ||
import omit from 'lodash/omit' | ||
import middleware from './middleware' | ||
import { applyAsyncData, sanitizeComponent, getMatchedComponents, getContext, middlewareSeries, promisify, urlJoin } from './utils' | ||
import { createApp, NuxtError } from './index' | ||
import { applyAsyncData, sanitizeComponent, getMatchedComponents, getContext, middlewareSeries, promisify, urlJoin } from './utils' | ||
@@ -13,5 +13,5 @@ const debug = require('debug')('nuxt:render') | ||
const noopApp = () => new Vue({ render: (h) => h('div') }) | ||
const noopApp = () => new Vue({ render: h => h('div') }) | ||
const createNext = (ssrContext) => (opts) => { | ||
const createNext = ssrContext => (opts) => { | ||
ssrContext.redirected = opts | ||
@@ -25,4 +25,5 @@ // If nuxt generate | ||
opts.path = opts.path + (opts.query ? '?' + opts.query : '') | ||
if (!opts.path.startsWith('http') && ('<%= router.base %>' !== '/' && !opts.path.startsWith('<%= router.base %>'))) { | ||
opts.path = urlJoin('<%= router.base %>', opts.path) | ||
const routerBase = '<%= router.base %>' | ||
if (!opts.path.startsWith('http') && (routerBase !== '/' && !opts.path.startsWith(routerBase))) { | ||
opts.path = urlJoin(routerBase, opts.path) | ||
} | ||
@@ -64,3 +65,3 @@ // Avoid loop redirect | ||
// Call beforeNuxtRender() methods | ||
await Promise.all(ssrContext.beforeRenderFns.map((fn) => promisify(fn, { Components, nuxtState: ssrContext.nuxt }))) | ||
await Promise.all(ssrContext.beforeRenderFns.map(fn => promisify(fn, { Components, nuxtState: ssrContext.nuxt }))) | ||
<% if (store) { %> | ||
@@ -73,3 +74,3 @@ // Add the state from the vuex store | ||
// Load layout for error page | ||
let errLayout = (typeof NuxtError.layout === 'function' ? NuxtError.layout(app.context) : NuxtError.layout) | ||
const errLayout = (typeof NuxtError.layout === 'function' ? NuxtError.layout(app.context) : NuxtError.layout) | ||
ssrContext.nuxt.layout = errLayout || 'default' | ||
@@ -111,3 +112,3 @@ await _app.loadLayout(errLayout) | ||
*/ | ||
let midd = <%= serialize(router.middleware).replace('middleware(', 'function(') %> | ||
let midd = <%= serialize(router.middleware).replace('middleware(', 'function(') %><%= isTest ? '// eslint-disable-line' : '' %> | ||
midd = midd.map((name) => { | ||
@@ -194,8 +195,8 @@ if (typeof name === 'function') return name | ||
// Call asyncData & fetch hooks on components matched by the route. | ||
let asyncDatas = await Promise.all(Components.map((Component) => { | ||
let promises = [] | ||
const asyncDatas = await Promise.all(Components.map((Component) => { | ||
const promises = [] | ||
// Call asyncData(context) | ||
if (Component.options.asyncData && typeof Component.options.asyncData === 'function') { | ||
let promise = promisify(Component.options.asyncData, app.context) | ||
const promise = promisify(Component.options.asyncData, app.context) | ||
promise.then((asyncDataResult) => { | ||
@@ -214,4 +215,3 @@ ssrContext.asyncData[Component.cid] = asyncDataResult | ||
promises.push(Component.options.fetch(app.context)) | ||
} | ||
else { | ||
} else { | ||
promises.push(null) | ||
@@ -218,0 +218,0 @@ } |
@@ -84,3 +84,3 @@ import Vue from 'vue' | ||
// Dynamically require module | ||
function getModule (filename) { | ||
function getModule(filename) { | ||
const file = files(filename) | ||
@@ -97,3 +97,3 @@ const module = file.default || file | ||
function getModuleNamespace (storeData, namePath, forAppend = false) { | ||
function getModuleNamespace(storeData, namePath, forAppend = false) { | ||
if (namePath.length === 1) { | ||
@@ -112,3 +112,3 @@ if (forAppend) { | ||
function appendModule (module, filename, name) { | ||
function appendModule(module, filename, name) { | ||
const file = files(filename) | ||
@@ -115,0 +115,0 @@ module.appends = module.appends || [] |
@@ -23,3 +23,3 @@ import Vue from 'vue' | ||
export function interopDefault(promise) { | ||
return promise.then(m => m.default || m); | ||
return promise.then(m => m.default || m) | ||
} | ||
@@ -35,3 +35,3 @@ | ||
Component.options.data = function () { | ||
const data = ComponentData.call(this) | ||
const data = ComponentData.call(this) | ||
if (this.$ssrContext) { | ||
@@ -104,3 +104,4 @@ asyncData = this.$ssrContext.asyncData[Component.cid] | ||
} | ||
return match.components[key] = sanitizeComponent(Component) | ||
match.components[key] = sanitizeComponent(Component) | ||
return match.components[key] | ||
}) | ||
@@ -123,3 +124,2 @@ ) | ||
export async function setContext(app, context) { | ||
const route = (context.to ? context.to : context.route) | ||
// If context not defined, create it | ||
@@ -136,3 +136,3 @@ if (!app.context) { | ||
base: '<%= router.base %>', | ||
env: <%= JSON.stringify(env) %> | ||
env: <%= JSON.stringify(env) %><%= isTest ? '// eslint-disable-line' : '' %> | ||
} | ||
@@ -209,5 +209,5 @@ // Only set once | ||
return promisify(promises[0], appContext) | ||
.then(() => { | ||
return middlewareSeries(promises.slice(1), appContext) | ||
}) | ||
.then(() => { | ||
return middlewareSeries(promises.slice(1), appContext) | ||
}) | ||
} | ||
@@ -239,3 +239,3 @@ | ||
export function getLocation(base, mode) { | ||
var path = window.location.pathname | ||
let path = window.location.pathname | ||
if (mode === 'hash') { | ||
@@ -304,13 +304,13 @@ return window.location.hash.replace(/^#\//, '') | ||
function parse(str, options) { | ||
var tokens = [] | ||
var key = 0 | ||
var index = 0 | ||
var path = '' | ||
var defaultDelimiter = options && options.delimiter || '/' | ||
var res | ||
const tokens = [] | ||
let key = 0 | ||
let index = 0 | ||
let path = '' | ||
const defaultDelimiter = (options && options.delimiter) || '/' | ||
let res | ||
while ((res = PATH_REGEXP.exec(str)) != null) { | ||
var m = res[0] | ||
var escaped = res[1] | ||
var offset = res.index | ||
const m = res[0] | ||
const escaped = res[1] | ||
const offset = res.index | ||
path += str.slice(index, offset) | ||
@@ -325,9 +325,9 @@ index = offset + m.length | ||
var next = str[index] | ||
var prefix = res[2] | ||
var name = res[3] | ||
var capture = res[4] | ||
var group = res[5] | ||
var modifier = res[6] | ||
var asterisk = res[7] | ||
const next = str[index] | ||
const prefix = res[2] | ||
const name = res[3] | ||
const capture = res[4] | ||
const group = res[5] | ||
const modifier = res[6] | ||
const asterisk = res[7] | ||
@@ -340,7 +340,7 @@ // Push the current path onto the tokens. | ||
var partial = prefix != null && next != null && next !== prefix | ||
var repeat = modifier === '+' || modifier === '*' | ||
var optional = modifier === '?' || modifier === '*' | ||
var delimiter = res[2] || defaultDelimiter | ||
var pattern = capture || group | ||
const partial = prefix != null && next != null && next !== prefix | ||
const repeat = modifier === '+' || modifier === '*' | ||
const optional = modifier === '?' || modifier === '*' | ||
const delimiter = res[2] || defaultDelimiter | ||
const pattern = capture || group | ||
@@ -379,3 +379,3 @@ tokens.push({ | ||
function encodeURIComponentPretty(str) { | ||
return encodeURI(str).replace(/[\/?#]/g, (c) => { | ||
return encodeURI(str).replace(/[/?#]/g, (c) => { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase() | ||
@@ -402,6 +402,6 @@ }) | ||
// Compile all the tokens into regexps. | ||
var matches = new Array(tokens.length) | ||
const matches = new Array(tokens.length) | ||
// Compile all the patterns before compilation. | ||
for (var i = 0; i < tokens.length; i++) { | ||
for (let i = 0; i < tokens.length; i++) { | ||
if (typeof tokens[i] === 'object') { | ||
@@ -412,10 +412,10 @@ matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$') | ||
return function(obj, opts) { | ||
var path = '' | ||
var data = obj || {} | ||
var options = opts || {} | ||
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent | ||
return function (obj, opts) { | ||
let path = '' | ||
const data = obj || {} | ||
const options = opts || {} | ||
const encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent | ||
for (var i = 0; i < tokens.length; i++) { | ||
var token = tokens[i] | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i] | ||
@@ -428,4 +428,4 @@ if (typeof token === 'string') { | ||
var value = data[token.name] | ||
var segment | ||
const value = data[token.name] | ||
let segment | ||
@@ -458,3 +458,3 @@ if (value == null) { | ||
for (var j = 0; j < value.length; j++) { | ||
for (let j = 0; j < value.length; j++) { | ||
segment = encode(value[j]) | ||
@@ -492,3 +492,3 @@ | ||
function escapeString(str) { | ||
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1') | ||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1') | ||
} | ||
@@ -503,3 +503,3 @@ | ||
function escapeGroup(group) { | ||
return group.replace(/([=!:$\/()])/g, '\\$1') | ||
return group.replace(/([=!:$/()])/g, '\\$1') | ||
} | ||
@@ -514,5 +514,5 @@ | ||
*/ | ||
function formatUrl (url, query) { | ||
function formatUrl(url, query) { | ||
let protocol | ||
let index = url.indexOf('://') | ||
const index = url.indexOf('://') | ||
if (index !== -1) { | ||
@@ -552,5 +552,5 @@ protocol = url.substring(0, index) | ||
*/ | ||
function formatQuery (query) { | ||
function formatQuery(query) { | ||
return Object.keys(query).sort().map((key) => { | ||
var val = query[key] | ||
const val = query[key] | ||
if (val == null) { | ||
@@ -557,0 +557,0 @@ return '' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
107846
35
2044