chore: eslint

This commit is contained in:
Pooya Parsa 2017-06-05 13:27:41 +04:30
parent bd54ddd2a7
commit b37c7cbd8d
2 changed files with 21 additions and 19 deletions

View File

@ -2,21 +2,21 @@
import path from 'path'
import fs from 'fs'
import {uniq} from 'lodash'
import { uniq } from 'lodash'
import hash from 'hash-sum'
import {chainFn, sequence} from './utils'
import { chainFn, sequence } from './utils'
const debug = require('debug')('nuxt:module')
class Module {
constructor(nuxt) {
constructor (nuxt) {
this.nuxt = nuxt
this.options = nuxt.options
this.requiredModules = []
this.initing = this.ready()
}
async ready() {
async ready () {
if (this.initing) {
await this.initing
return this
@ -26,7 +26,7 @@ class Module {
return this
}
addVendor(vendor) {
addVendor (vendor) {
/* istanbul ignore if */
if (!vendor) {
return
@ -34,7 +34,7 @@ class Module {
this.options.build.vendor = uniq(this.options.build.vendor.concat(vendor))
}
addTemplate(template) {
addTemplate (template) {
/* istanbul ignore if */
if (!template) {
return
@ -60,7 +60,7 @@ class Module {
return templateObj
}
addPlugin(template) {
addPlugin (template) {
const {dst} = this.addTemplate(template)
// Add to nuxt plugins
this.options.plugins.push({
@ -69,24 +69,24 @@ class Module {
})
}
addServerMiddleware(middleware) {
addServerMiddleware (middleware) {
this.options.serverMiddleware.push(middleware)
}
extendBuild(fn) {
extendBuild (fn) {
this.options.build.extend = chainFn(this.options.build.extend, fn)
}
extendRoutes(fn) {
extendRoutes (fn) {
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
}
requireModule(moduleOpts) {
requireModule (moduleOpts) {
// Require once
return this.addModule(moduleOpts, true)
}
addModule(moduleOpts, requireOnce) {
addModule (moduleOpts, requireOnce) {
/* istanbul ignore if */
if (!moduleOpts) {
return

View File

@ -5,6 +5,7 @@ import serialize from 'serialize-javascript'
import generateETag from 'etag'
import fresh from 'fresh'
import { getContext, setAnsiColors, encodeHtml } from './utils'
const debug = require('debug')('nuxt:render')
// force blue color
debug.color = 4
@ -57,7 +58,7 @@ export async function render (req, res) {
res.statusCode = 404
return res.end()
}
const { html, error, redirected, resourceHints } = await this.renderRoute(req.url, context)
const {html, error, redirected, resourceHints} = await this.renderRoute(req.url, context)
if (redirected) {
return html
}
@ -67,7 +68,7 @@ export async function render (req, res) {
// ETag header
if (!error && this.options.render.etag) {
const etag = generateETag(html, this.options.render.etag)
if (fresh(req.headers, { etag })) {
if (fresh(req.headers, {etag})) {
res.statusCode = 304
res.end()
return
@ -75,7 +76,7 @@ export async function render (req, res) {
res.setHeader('ETag', etag)
}
// HTTP2 push headers
if(!error && this.options.render.http2.push) {
if (!error && this.options.render.http2.push) {
// Parse resourceHints to extract HTTP.2 prefetch/push headers
// https://w3c.github.io/preload/#server-push-http-2
const regex = /link rel="([^"]*)" href="([^"]*)" as="([^"]*)"/g
@ -133,7 +134,7 @@ export async function renderRoute (url, context = {}) {
}
const resourceHints = context.renderResourceHints()
HEAD += resourceHints + context.renderStyles()
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, {isJSON: true})}</script>`
APP += context.renderScripts()
const html = this.appTemplate({
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
@ -168,14 +169,15 @@ export async function renderAndGetWindow (url, opts = {}) {
runScripts: 'dangerously',
beforeParse (window) {
// Mock window.scrollTo
window.scrollTo = () => {}
window.scrollTo = () => {
}
}
}
if (opts.virtualConsole !== false) {
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
}
url = url || 'http://localhost:3000'
const { window } = await jsdom.JSDOM.fromURL(url, options)
const {window} = await jsdom.JSDOM.fromURL(url, options)
// If Nuxt could not be loaded (error from the server-side)
const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__')
if (!nuxtExists) {