mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(app): lint all templates (#4175)
This commit is contained in:
parent
81b25ee2e2
commit
96bdcaba01
29
.eslintrc.js
29
.eslintrc.js
@ -6,5 +6,32 @@ module.exports = {
|
||||
},
|
||||
extends: [
|
||||
'@nuxtjs'
|
||||
]
|
||||
],
|
||||
overrides: [{
|
||||
files: [ 'test/fixtures/*/.nuxt*/**' ],
|
||||
rules: {
|
||||
'vue/name-property-casing': ['error', 'kebab-case']
|
||||
}
|
||||
}, {
|
||||
files: [ 'test/fixtures/*/.nuxt*/**/+(App|index).js' ],
|
||||
rules: {
|
||||
'import/order': 'ignore'
|
||||
}
|
||||
}, {
|
||||
files: [ 'test/fixtures/*/.nuxt*/**/client.js' ],
|
||||
rules: {
|
||||
'no-console': ['error', { allow: ['error'] }]
|
||||
}
|
||||
}, {
|
||||
files: [ 'test/fixtures/*/.nuxt*/**/router.js' ],
|
||||
rules: {
|
||||
'no-console': ['error', { allow: ['warn'] }]
|
||||
}
|
||||
}, {
|
||||
files: [ 'test/fixtures/*/.nuxt*/**/*.html' ],
|
||||
rules: {
|
||||
'semi': ['error', 'always', { 'omitLastInOneLineBlock': true }],
|
||||
'no-var': 'warn'
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
"dev": "yarn build --watch",
|
||||
"coverage": "codecov",
|
||||
"lint": "eslint --ext .js,.mjs,.vue .",
|
||||
"lint:app": "eslint-multiplexer eslint --ignore-path lib/app/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
||||
"lint:app": "eslint-multiplexer eslint --ignore-path packages/app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
||||
"nuxt": "node -r esm ./packages/cli/bin/nuxt.js",
|
||||
"test": "yarn test:fixtures && yarn test:unit",
|
||||
"test:fixtures": "jest test/fixtures",
|
||||
|
@ -12,12 +12,14 @@ import '<%= relativeToBuild(resolvePath(c.src || c)) %>'
|
||||
}
|
||||
}).join('\n') %>
|
||||
|
||||
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' : '' %>
|
||||
|
||||
<% 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) {
|
||||
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
|
||||
const layoutEl = h(this.layout || 'nuxt')
|
||||
|
@ -1,6 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import middleware from './middleware'
|
||||
import { createApp, NuxtError } from './index'
|
||||
import {
|
||||
applyAsyncData,
|
||||
sanitizeComponent,
|
||||
@ -16,6 +15,7 @@ import {
|
||||
getQueryDiff,
|
||||
globalHandleError
|
||||
} from './utils'
|
||||
import { createApp, NuxtError } from './index'
|
||||
|
||||
const noopData = () => { return {} }
|
||||
const noopFetch = () => {}
|
||||
@ -29,7 +29,7 @@ let router
|
||||
// Try to rehydrate SSR data from window
|
||||
const NUXT = window.<%= globals.context %> || {}
|
||||
|
||||
Object.assign(Vue.config, <%= serialize(vue.config) %>)
|
||||
Object.assign(Vue.config, <%= serialize(vue.config) %>)<%= isTest ? '// eslint-disable-line' : '' %>
|
||||
|
||||
<% if (debug || mode === 'spa') { %>
|
||||
// Setup global Vue error handler
|
||||
@ -107,10 +107,10 @@ function mapTransitions(Components, to, from) {
|
||||
|
||||
// Combine transitions & prefer `leave` transitions of 'from' route
|
||||
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] })
|
||||
}
|
||||
|
||||
return transitions
|
||||
@ -138,7 +138,7 @@ async function loadAsyncComponents (to, from, next) {
|
||||
const watchQuery = Component.options.watchQuery
|
||||
if (watchQuery === true) return true
|
||||
if (Array.isArray(watchQuery)) {
|
||||
return watchQuery.some((key) => this._diffQuery[key])
|
||||
return watchQuery.some(key => this._diffQuery[key])
|
||||
}
|
||||
return false
|
||||
})
|
||||
@ -150,10 +150,10 @@ async function loadAsyncComponents (to, from, next) {
|
||||
// Call next()
|
||||
next()
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ function resolveComponents(router) {
|
||||
}
|
||||
|
||||
function callMiddleware(Components, context, layout) {
|
||||
let midd = <%= devalue(router.middleware) %>
|
||||
let midd = <%= devalue(router.middleware) %><%= isTest ? '// eslint-disable-line' : '' %>
|
||||
let unknownMiddleware = false
|
||||
|
||||
// If layout is undefined, only call global middleware
|
||||
@ -337,21 +337,21 @@ async function render (to, from, next) {
|
||||
Component._dataRefresh = false
|
||||
// Check if Component need to be refreshed (call asyncData & fetch)
|
||||
// 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
|
||||
} else if (!this._pathChanged && this._queryChanged) {
|
||||
const watchQuery = Component.options.watchQuery
|
||||
if (watchQuery === true) {
|
||||
Component._dataRefresh = true
|
||||
} else if (Array.isArray(watchQuery)) {
|
||||
Component._dataRefresh = watchQuery.some((key) => this._diffQuery[key])
|
||||
Component._dataRefresh = watchQuery.some(key => this._diffQuery[key])
|
||||
}
|
||||
}
|
||||
if (!this._hadError && this._isMounted && !Component._dataRefresh) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
let promises = []
|
||||
const promises = []
|
||||
|
||||
const hasAsyncData = (
|
||||
Component.options.asyncData &&
|
||||
@ -408,10 +408,9 @@ async function render (to, from, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
} 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)
|
||||
}
|
||||
_lastPaths = []
|
||||
@ -486,7 +485,7 @@ function fixPrepatch(to, ___) {
|
||||
typeof instance.constructor.options.data === 'function'
|
||||
) {
|
||||
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])
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*<%= isTest ? ' @vue/component' : '' %>
|
||||
** From https://github.com/egoist/vue-no-ssr
|
||||
** With the authorization of @egoist
|
||||
*/
|
||||
|
@ -1,7 +1,14 @@
|
||||
<%= isTest ? '// @vue/component' : '' %>
|
||||
export default {
|
||||
name: 'nuxt-child',
|
||||
functional: true,
|
||||
props: ['keepAlive', 'keepAliveProps'],
|
||||
props: {
|
||||
nuxtChildKey: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
keepAlive: Boolean
|
||||
},
|
||||
render(h, { parent, data, props }) {
|
||||
data.nuxtChild = true
|
||||
const _parent = parent
|
||||
@ -17,14 +24,14 @@ export default {
|
||||
}
|
||||
data.nuxtChildDepth = depth
|
||||
const transition = transitions[depth] || defaultTransition
|
||||
let transitionProps = {}
|
||||
const transitionProps = {}
|
||||
transitionsKeys.forEach((key) => {
|
||||
if (typeof transition[key] !== 'undefined') {
|
||||
transitionProps[key] = transition[key]
|
||||
}
|
||||
})
|
||||
|
||||
let listeners = {}
|
||||
const listeners = {}
|
||||
listenersKeys.forEach((key) => {
|
||||
if (typeof transition[key] === 'function') {
|
||||
listeners[key] = transition[key].bind(_parent)
|
||||
@ -43,7 +50,7 @@ export default {
|
||||
let routerView = [
|
||||
h('router-view', data)
|
||||
]
|
||||
if (typeof props.keepAlive !== 'undefined') {
|
||||
if (props.keepAlive) {
|
||||
routerView = [
|
||||
h('keep-alive', { props: props.keepAliveProps }, routerView)
|
||||
]
|
||||
|
@ -4,7 +4,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" fill="#DBE1EC" viewBox="0 0 48 48"><path d="M22 30h4v4h-4zm0-16h4v12h-4zm1.99-10C12.94 4 4 12.95 4 24s8.94 20 19.99 20S44 35.05 44 24 35.04 4 23.99 4zM24 40c-8.84 0-16-7.16-16-16S15.16 8 24 8s16 7.16 16 16-7.16 16-16 16z" /></svg>
|
||||
|
||||
<div class="title">{{ message }}</div>
|
||||
<p class="description" v-if="statusCode === 404">
|
||||
<p v-if="statusCode === 404" class="description">
|
||||
<nuxt-link class="error-link" to="/"><%= messages.back_to_home %></nuxt-link>
|
||||
</p>
|
||||
<% if(debug) { %>
|
||||
@ -21,7 +21,12 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'nuxt-error',
|
||||
props: ['error'],
|
||||
props: {
|
||||
error: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
head() {
|
||||
return {
|
||||
title: this.message,
|
||||
|
@ -1,3 +1,4 @@
|
||||
<%= isTest ? '// @vue/component' : '' %>
|
||||
export default {
|
||||
name: 'nuxt-link',
|
||||
functional: true,
|
||||
|
@ -1,10 +1,13 @@
|
||||
<template>
|
||||
<div class="nuxt-progress" :style="{
|
||||
<div
|
||||
class="nuxt-progress"
|
||||
:style="{
|
||||
'width': percent + '%',
|
||||
'height': height,
|
||||
'background-color': canSuccess ? color : failedColor,
|
||||
'opacity': show ? 1 : 0
|
||||
}"></div>
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -17,11 +20,11 @@ export default {
|
||||
percent: 0,
|
||||
show: false,
|
||||
canSuccess: true,
|
||||
throttle: <%= loading.throttle %>,
|
||||
duration: <%= loading.duration %>,
|
||||
throttle: <%= loading.throttle || 200 %>,
|
||||
duration: <%= loading.duration || 1000 %>,
|
||||
height: '<%= loading.height %>',
|
||||
color: '<%= loading.color %>',
|
||||
failedColor: '<%= loading.failedColor %>',
|
||||
failedColor: '<%= loading.failedColor %>'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<%= isTest ? '// @vue/component' : '' %>
|
||||
import Vue from 'vue'
|
||||
import NuxtChild from './nuxt-child'
|
||||
import { compile } from '../utils'
|
||||
|
||||
<% if (components.ErrorPage) { %>
|
||||
<% if (('~@').includes(components.ErrorPage.charAt(0))) { %>
|
||||
@ -10,12 +11,14 @@ import NuxtError from '<%= "../" + components.ErrorPage %>'
|
||||
<% } else { %>
|
||||
import NuxtError from './nuxt-error.vue'
|
||||
<% } %>
|
||||
|
||||
import { compile } from '../utils'
|
||||
import NuxtChild from './nuxt-child'
|
||||
|
||||
export default {
|
||||
name: 'nuxt',
|
||||
props: ['nuxtChildKey', 'keepAlive'],
|
||||
props: {
|
||||
nuxtChildKey: String,
|
||||
keepAlive: Boolean
|
||||
},
|
||||
render(h) {
|
||||
// If there is some error
|
||||
if (this.nuxt.err) {
|
||||
|
@ -11,8 +11,10 @@ import { setContext, getLocation, getRouteData } from './utils'
|
||||
<% if (store) { %>import { createStore } from './store.js'<% } %>
|
||||
|
||||
/* 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 */' : '' %>
|
||||
|
||||
// Component: <no-ssr>
|
||||
Vue.component(NoSSR.name, NoSSR)
|
||||
@ -40,7 +42,7 @@ const defaultTransition = <%=
|
||||
.replace('enterCancelled(', 'function(').replace('beforeLeave(', 'function(').replace('leave(', 'function(')
|
||||
.replace('afterLeave(', 'function(').replace('leaveCancelled(', 'function(').replace('beforeAppear(', 'function(')
|
||||
.replace('appear(', 'function(').replace('afterAppear(', 'function(').replace('appearCancelled(', 'function(')
|
||||
%>
|
||||
%><%= isTest ? '// eslint-disable-line' : '' %>
|
||||
|
||||
async function createApp(ssrContext) {
|
||||
const router = await createRouter(ssrContext)
|
||||
@ -56,7 +58,8 @@ async function createApp (ssrContext) {
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
// 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,
|
||||
// making them available everywhere as `this.$router` and `this.$store`.
|
||||
const app = {
|
||||
@ -124,6 +127,7 @@ async function createApp (ssrContext) {
|
||||
beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined
|
||||
})
|
||||
|
||||
<% if (plugins.length) { %>
|
||||
const inject = function (key, value) {
|
||||
if (!key) throw new Error('inject(key, value) has no key provided')
|
||||
if (!value) throw new Error('inject(key, value) has no value provided')
|
||||
@ -149,6 +153,7 @@ async function createApp (ssrContext) {
|
||||
}
|
||||
})
|
||||
}
|
||||
<% } %>
|
||||
|
||||
<% if (store) { %>
|
||||
if (process.client) {
|
||||
@ -160,12 +165,14 @@ async function createApp (ssrContext) {
|
||||
<% } %>
|
||||
|
||||
// Plugin execution
|
||||
<%= isTest ? '/* eslint-disable camelcase */' : '' %>
|
||||
<% plugins.filter(p => p.ssr).forEach((plugin) => { %>
|
||||
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
|
||||
<% if (plugins.filter(p => !p.ssr).length) { %>
|
||||
if (process.client) { <% plugins.filter((p) => !p.ssr).forEach((plugin) => { %>
|
||||
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
|
||||
}<% } %>
|
||||
<%= isTest ? '/* eslint-enable camelcase */' : '' %>
|
||||
|
||||
// If server-side, wait for async component to be resolved first
|
||||
if (process.server && ssrContext && ssrContext.url) {
|
||||
@ -186,8 +193,8 @@ async function createApp (ssrContext) {
|
||||
|
||||
return {
|
||||
app,
|
||||
router,
|
||||
<% if(store) { %>store<% } %>
|
||||
<% if(store) { %>store,<% } %>
|
||||
router
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,38 @@
|
||||
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) => {
|
||||
route._name = '_' + hash(route.component)
|
||||
components.push({ _name: route._name, component: route.component, name: route.name, chunkName: route.chunkName })
|
||||
// @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 ? '' : ', ')
|
||||
})
|
||||
return res
|
||||
}
|
||||
const _components = []
|
||||
const _routes = recursiveRoutes(router.routes, '\t\t', _components)
|
||||
const _routes = recursiveRoutes(router.routes, ' ', _components, 2)
|
||||
%><%= uniqBy(_components, '_name').map((route) => {
|
||||
if (!route.component) return ''
|
||||
const path = relativeToBuild(route.component)
|
||||
@ -56,7 +63,7 @@ const scrollBehavior = function (to, from, savedPosition) {
|
||||
if (to.matched.length < 2) {
|
||||
// scroll to the top of the page
|
||||
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
|
||||
position = { x: 0, y: 0 }
|
||||
}
|
||||
@ -99,9 +106,9 @@ export function createRouter () {
|
||||
linkActiveClass: '<%= router.linkActiveClass %>',
|
||||
linkExactActiveClass: '<%= router.linkExactActiveClass %>',
|
||||
scrollBehavior,
|
||||
routes: [
|
||||
<%= _routes %>
|
||||
],
|
||||
<%= isTest ? '/* eslint-disable quotes */' : '' %>
|
||||
routes: [<%= _routes %>],
|
||||
<%= isTest ? '/* eslint-enable quotes */' : '' %>
|
||||
<% if (router.parseQuery) { %>parseQuery: <%= serialize(router.parseQuery).replace('parseQuery(', 'function(') %>,<% } %>
|
||||
<% if (router.stringifyQuery) { %>stringifyQuery: <%= serialize(router.stringifyQuery).replace('stringifyQuery(', 'function(') %>,<% } %>
|
||||
fallback: <%= router.fallback %>
|
||||
|
@ -1,18 +1,18 @@
|
||||
import Vue from 'vue'
|
||||
import { stringify } from 'querystring'
|
||||
import Vue from 'vue'
|
||||
import omit from 'lodash/omit'
|
||||
import middleware from './middleware'
|
||||
import { createApp, NuxtError } from './index'
|
||||
import { applyAsyncData, sanitizeComponent, getMatchedComponents, getContext, middlewareSeries, promisify, urlJoin } from './utils'
|
||||
import { createApp, NuxtError } from './index'
|
||||
|
||||
const debug = require('debug')('nuxt:render')
|
||||
debug.color = 4 // force blue color
|
||||
|
||||
const isDev = <%= isDev %>
|
||||
|
||||
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
|
||||
// If nuxt generate
|
||||
if (!ssrContext.res) {
|
||||
@ -21,8 +21,9 @@ const createNext = (ssrContext) => (opts) => {
|
||||
}
|
||||
opts.query = stringify(opts.query)
|
||||
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)
|
||||
}
|
||||
// Avoid loop redirect
|
||||
if (opts.path === ssrContext.url) {
|
||||
@ -59,7 +60,7 @@ export default async (ssrContext) => {
|
||||
|
||||
const beforeRender = async () => {
|
||||
// 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) { %>
|
||||
// Add the state from the vuex store
|
||||
ssrContext.nuxt.state = store.state
|
||||
@ -67,7 +68,7 @@ export default async (ssrContext) => {
|
||||
}
|
||||
const renderErrorPage = async () => {
|
||||
// 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'
|
||||
await _app.loadLayout(errLayout)
|
||||
_app.setLayout(errLayout)
|
||||
@ -104,7 +105,7 @@ export default async (ssrContext) => {
|
||||
/*
|
||||
** Call global middleware (nuxt.config.js)
|
||||
*/
|
||||
let midd = <%= serialize(router.middleware).replace('middleware(', 'function(') %>
|
||||
let midd = <%= serialize(router.middleware).replace('middleware(', 'function(') %><%= isTest ? '// eslint-disable-line' : '' %>
|
||||
midd = midd.map((name) => {
|
||||
if (typeof name === 'function') return name
|
||||
if (typeof middleware[name] !== 'function') {
|
||||
@ -186,12 +187,12 @@ export default async (ssrContext) => {
|
||||
if (!Components.length) return render404Page()
|
||||
|
||||
// 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) => {
|
||||
ssrContext.asyncData[Component.cid] = asyncDataResult
|
||||
applyAsyncData(Component)
|
||||
@ -205,8 +206,7 @@ export default async (ssrContext) => {
|
||||
// Call fetch(context)
|
||||
if (Component.options.fetch) {
|
||||
promises.push(Component.options.fetch(app.context))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
promises.push(null)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ export function globalHandleError(error) {
|
||||
}
|
||||
|
||||
export function interopDefault(promise) {
|
||||
return promise.then(m => m.default || m);
|
||||
return promise.then(m => m.default || m)
|
||||
}
|
||||
|
||||
export function applyAsyncData(Component, asyncData) {
|
||||
@ -99,7 +99,8 @@ export function resolveRouteComponents(route) {
|
||||
if (typeof Component === 'function' && !Component.options) {
|
||||
Component = await Component()
|
||||
}
|
||||
return match.components[key] = sanitizeComponent(Component)
|
||||
match.components[key] = sanitizeComponent(Component)
|
||||
return match.components[key]
|
||||
})
|
||||
)
|
||||
}
|
||||
@ -117,7 +118,6 @@ export async function getRouteData(route) {
|
||||
}
|
||||
|
||||
export async function setContext(app, context) {
|
||||
const route = (context.to ? context.to : context.route)
|
||||
// If context not defined, create it
|
||||
if (!app.context) {
|
||||
app.context = {
|
||||
@ -129,7 +129,7 @@ export async function setContext(app, context) {
|
||||
payload: context.payload,
|
||||
error: context.error,
|
||||
base: '<%= router.base %>',
|
||||
env: <%= JSON.stringify(env) %>
|
||||
env: <%= JSON.stringify(env) %><%= isTest ? '// eslint-disable-line' : '' %>
|
||||
}
|
||||
// Only set once
|
||||
if (context.req) app.context.req = context.req
|
||||
@ -230,7 +230,7 @@ export function promisify(fn, context) {
|
||||
|
||||
// Imported from vue-router
|
||||
export function getLocation(base, mode) {
|
||||
var path = window.location.pathname
|
||||
let path = window.location.pathname
|
||||
if (mode === 'hash') {
|
||||
return window.location.hash.replace(/^#\//, '')
|
||||
}
|
||||
@ -294,17 +294,17 @@ const PATH_REGEXP = new RegExp([
|
||||
* @return {!Array}
|
||||
*/
|
||||
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)
|
||||
index = offset + m.length
|
||||
|
||||
@ -314,13 +314,13 @@ function parse(str, options) {
|
||||
continue
|
||||
}
|
||||
|
||||
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]
|
||||
|
||||
// Push the current path onto the tokens.
|
||||
if (path) {
|
||||
@ -328,11 +328,11 @@ function parse(str, options) {
|
||||
path = ''
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
tokens.push({
|
||||
name: name || key++,
|
||||
@ -366,7 +366,7 @@ function parse(str, options) {
|
||||
* @return {string}
|
||||
*/
|
||||
function encodeURIComponentPretty(str) {
|
||||
return encodeURI(str).replace(/[\/?#]/g, (c) => {
|
||||
return encodeURI(str).replace(/[/?#]/g, (c) => {
|
||||
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
|
||||
})
|
||||
}
|
||||
@ -388,23 +388,23 @@ function encodeAsterisk(str) {
|
||||
*/
|
||||
function tokensToFunction(tokens) {
|
||||
// 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') {
|
||||
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
|
||||
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]
|
||||
|
||||
if (typeof token === 'string') {
|
||||
path += token
|
||||
@ -412,8 +412,8 @@ function tokensToFunction(tokens) {
|
||||
continue
|
||||
}
|
||||
|
||||
var value = data[token.name]
|
||||
var segment
|
||||
const value = data[token.name]
|
||||
let segment
|
||||
|
||||
if (value == null) {
|
||||
if (token.optional) {
|
||||
@ -441,7 +441,7 @@ function tokensToFunction(tokens) {
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < value.length; j++) {
|
||||
for (let j = 0; j < value.length; j++) {
|
||||
segment = encode(value[j])
|
||||
|
||||
if (!matches[i].test(segment)) {
|
||||
@ -474,7 +474,7 @@ function tokensToFunction(tokens) {
|
||||
* @return {string}
|
||||
*/
|
||||
function escapeString(str) {
|
||||
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
|
||||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
|
||||
}
|
||||
|
||||
/**
|
||||
@ -484,7 +484,7 @@ function escapeString(str) {
|
||||
* @return {string}
|
||||
*/
|
||||
function escapeGroup(group) {
|
||||
return group.replace(/([=!:$\/()])/g, '\\$1')
|
||||
return group.replace(/([=!:$/()])/g, '\\$1')
|
||||
}
|
||||
|
||||
/**
|
||||
@ -496,7 +496,7 @@ function escapeGroup(group) {
|
||||
*/
|
||||
function formatUrl(url, query) {
|
||||
let protocol
|
||||
let index = url.indexOf('://')
|
||||
const index = url.indexOf('://')
|
||||
if (index !== -1) {
|
||||
protocol = url.substring(0, index)
|
||||
url = url.substring(index + 3)
|
||||
@ -533,7 +533,7 @@ function formatUrl (url, query) {
|
||||
*/
|
||||
function formatQuery(query) {
|
||||
return Object.keys(query).sort().map((key) => {
|
||||
var val = query[key]
|
||||
const val = query[key]
|
||||
if (val == null) {
|
||||
return ''
|
||||
}
|
||||
|
@ -97,8 +97,8 @@
|
||||
|
||||
<script>
|
||||
window.addEventListener('error', function () {
|
||||
var e = document.getElementById("nuxt-loading");
|
||||
if (e) e.className += " error";
|
||||
var e = document.getElementById('nuxt-loading');
|
||||
if (e) e.className += ' error';
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -33,7 +33,8 @@ import {
|
||||
sequence,
|
||||
relativeTo,
|
||||
waitFor,
|
||||
determineGlobals
|
||||
determineGlobals,
|
||||
stripWhitespace
|
||||
} from '@nuxt/common'
|
||||
|
||||
import PerfLoader from './webpack/utils/perf-loader'
|
||||
@ -214,6 +215,7 @@ export default class Builder {
|
||||
splitChunks: this.options.build.splitChunks,
|
||||
uniqBy,
|
||||
isDev: this.options.dev,
|
||||
isTest: this.options.test,
|
||||
debug: this.options.debug,
|
||||
vue: { config: this.options.vue.config },
|
||||
mode: this.options.mode,
|
||||
@ -432,7 +434,8 @@ export default class Builder {
|
||||
},
|
||||
interpolate: /<%=([\s\S]+?)%>/g
|
||||
})
|
||||
content = templateFunction(
|
||||
content = stripWhitespace(
|
||||
templateFunction(
|
||||
Object.assign({}, templateVars, {
|
||||
options: options || {},
|
||||
custom,
|
||||
@ -440,6 +443,7 @@ export default class Builder {
|
||||
dst
|
||||
})
|
||||
)
|
||||
)
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
throw new Error(`Could not compile template ${src}: ${err.message}`)
|
||||
|
@ -10,6 +10,7 @@ const nuxtDir = fs.existsSync(path.resolve(__dirname, '..', '..', 'package.js'))
|
||||
export default {
|
||||
// Information about running environment
|
||||
dev: Boolean(env.dev),
|
||||
test: Boolean(env.test),
|
||||
debug: undefined, // = dev
|
||||
|
||||
// Mode
|
||||
|
@ -389,3 +389,18 @@ const DYNAMIC_ROUTE_REGEX = /^\/(:|\*)/
|
||||
* @return {array}
|
||||
*/
|
||||
export const wrapArray = value => Array.isArray(value) ? value : [value]
|
||||
|
||||
const WHITESPACE_REPLACEMENTS = [
|
||||
[/[ \t\f\r]+\n/g, '\n'], // strip empty indents
|
||||
[/{\n{2,}/g, '{\n'], // strip start padding from blocks
|
||||
[/\n{2,}([ \t\f\r]*})/g, '\n$1'], // strip end padding from blocks
|
||||
[/\n{3,}/g, '\n\n'], // strip multiple blank lines (1 allowed)
|
||||
[/\n{2,}$/g, '\n'] // strip blank lines EOF (0 allowed)
|
||||
]
|
||||
|
||||
export const stripWhitespace = function stripWhitespace(string) {
|
||||
WHITESPACE_REPLACEMENTS.forEach(([regex, newSubstr]) => {
|
||||
string = string.replace(regex, newSubstr)
|
||||
})
|
||||
return string
|
||||
}
|
||||
|
1
test/fixtures/cli/cli.build.config.js
vendored
1
test/fixtures/cli/cli.build.config.js
vendored
@ -1,4 +1,5 @@
|
||||
export default {
|
||||
test: true,
|
||||
hooks(hook) {
|
||||
hook('build:done', () => {
|
||||
process.stdout.write('Compiled successfully')
|
||||
|
5
test/fixtures/cli/cli.gen.config.js
vendored
5
test/fixtures/cli/cli.gen.config.js
vendored
@ -1,7 +1,8 @@
|
||||
export default {
|
||||
buildDir: '.nuxt-generate/.build',
|
||||
test: true,
|
||||
buildDir: '.nuxt-generate/build',
|
||||
generate: {
|
||||
dir: '.nuxt-generate/.generate'
|
||||
dir: '.nuxt-generate/generate'
|
||||
},
|
||||
hooks(hook) {
|
||||
hook('generate:done', (generator, errors) => {
|
||||
|
@ -30,6 +30,7 @@ export const loadFixture = async function (fixture, overrides) {
|
||||
|
||||
config.rootDir = rootDir
|
||||
config.dev = false
|
||||
config.test = true
|
||||
|
||||
return defaultsDeep({}, overrides, config)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user