Skip to content

Commit

Permalink
chore(deps): update devdependency eslint to v7
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed May 11, 2020
2 parents e1e6d45 + 498f408 commit 7efe0a7
Show file tree
Hide file tree
Showing 81 changed files with 1,502 additions and 429 deletions.
24 changes: 12 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ module.exports = {
extends: [
'@nuxtjs'
],
"globals": {
"BigInt": true
globals: {
BigInt: true
},
rules: {
'no-console': 'error',
'no-debugger': 'error',
quotes: ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }]
quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }]
},
overrides: [{
files: [ 'test/fixtures/*/.nuxt*/**' ],
files: ['test/fixtures/*/.nuxt*/**'],
rules: {
'vue/name-property-casing': 'error'
}
Expand All @@ -31,40 +31,40 @@ module.exports = {
'examples/with-vue-material/**',
'examples/with-vuetify/**',
'examples/with-vuikit/**',
'examples/with-vux/**',
'examples/with-vux/**'
],
rules: {
'vue/component-name-in-template-casing': ['warn', 'kebab-case']
}
}, {
files: [ 'test/fixtures/*/.nuxt*/**/+(App|index|server|client|nuxt).js' ],
files: ['test/fixtures/*/.nuxt*/**/+(App|index|server|client|nuxt).js'],
rules: {
'import/order': 'off'
}
}, {
files: [ 'test/fixtures/*/.nuxt*/**/client.js' ],
files: ['test/fixtures/*/.nuxt*/**/client.js'],
rules: {
'no-console': ['error', { allow: ['error'] }]
}
}, {
files: [ 'test/fixtures/*/.nuxt*/**/router.js' ],
files: ['test/fixtures/*/.nuxt*/**/router.js'],
rules: {
'no-console': ['error', { allow: ['warn'] }]
}
}, {
files: [ 'test/fixtures/*/.nuxt*/**/*.html' ],
files: ['test/fixtures/*/.nuxt*/**/*.html'],
rules: {
'semi': ['error', 'always', { 'omitLastInOneLineBlock': true }],
semi: ['error', 'always', { omitLastInOneLineBlock: true }],
'no-var': 'off'
}
}, {
files: [ 'test/fixtures/*/.nuxt*/**/nuxt-error.vue' ],
files: ['test/fixtures/*/.nuxt*/**/nuxt-error.vue'],
rules: {
'vue/singleline-html-element-content-newline': 'off'
}
}, {
// might be removed in the future, see https://github.com/standard/eslint-plugin-standard/issues/27
files: [ 'test/fixtures/*/.nuxt*/**/nuxt-link.client.js' ],
files: ['test/fixtures/*/.nuxt*/**/nuxt-link.client.js'],
rules: {
'standard/no-callback-literal': 'off'
}
Expand Down
7 changes: 3 additions & 4 deletions examples/async-data/pages/posts/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
</template>

<script>
import axios from 'axios'
export default {
async asyncData ({ params }) {
// We can use async/await ES6 feature
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
return { post: data }
const post = await fetch(`https://jsonplaceholder.typicode.com/posts/${params.id}`).then(res => res.json())
return { post }
},
head () {
return {
Expand Down
12 changes: 7 additions & 5 deletions examples/async-data/pages/posts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<NuxtLink :to="{ name: 'posts-id', params: { id: post.id } }">
{{ post.title }}
</NuxtLink>
<NuxtLink :to="{ name: 'posts-id', params: { id: post.id } }">
{{ post.title }}
</NuxtLink>
</li>
</ul>
<p>
Expand All @@ -18,14 +21,13 @@
</template>

<script>
import axios from 'axios'
export default {
asyncData ({ req, params }) {
// We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts')
.then((res) => {
return { posts: res.data.slice(0, 5) }
return fetch('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
.then((data) => {
return { posts: data.slice(0, 5) }
})
},
head: {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-feathers/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module.exports = {
'vue/no-parsing-error': [2, {
'x-invalid-end-tag': false
}],
"vue/max-attributes-per-line": [2, {
"singleline": 5,
'vue/max-attributes-per-line': [2, {
singleline: 5
}]
},
globals: {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"babel-jest": "^26.0.1",
"consola": "^2.12.1",
"cross-spawn": "^7.0.2",
"eslint": "6.8.0",
"eslint": "^7.0.0",
"eslint-multiplexer": "^2.0.0",
"esm": "^3.2.25",
"execa": "^4.0.0",
Expand Down
14 changes: 12 additions & 2 deletions packages/builder/src/builder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path'
import chalk from 'chalk'
import chokidar from 'chokidar'
import consola from 'consola'
import fsExtra from 'fs-extra'
Expand All @@ -7,7 +8,6 @@ import hash from 'hash-sum'
import pify from 'pify'
import upath from 'upath'
import semver from 'semver'
import chalk from 'chalk'

import debounce from 'lodash/debounce'
import omit from 'lodash/omit'
Expand All @@ -23,7 +23,9 @@ import {
determineGlobals,
stripWhitespace,
isIndexFileAndFolder,
scanRequireTree
scanRequireTree,
TARGETS,
isFullStatic
} from '@nuxt/utils'

import Ignore from './ignore'
Expand Down Expand Up @@ -102,6 +104,7 @@ export default class Builder {
}

forGenerate () {
this.options.target = TARGETS.static
this.bundleBuilder.forGenerate()
}

Expand All @@ -122,6 +125,13 @@ export default class Builder {
consola.info('Initial build may take a while')
} else {
consola.info('Production build')
if (this.options.render.ssr) {
consola.info(`Bundling for ${chalk.bold.yellow('server')} and ${chalk.bold.green('client')} side`)
} else {
consola.info(`Bundling only for ${chalk.bold.green('client')} side`)
}
const target = isFullStatic(this.options) ? 'full static' : this.options.target
consola.info(`Target: ${chalk.bold.cyan(target)}`)
}

// Wait for nuxt ready
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/context/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default class BuildContext {
this._builder = builder
this.nuxt = builder.nuxt
this.options = builder.nuxt.options
this.isStatic = false
this.target = builder.nuxt.options.target
}

get buildOptions () {
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/src/context/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import uniqBy from 'lodash/uniqBy'
import serialize from 'serialize-javascript'

import devalue from '@nuxt/devalue'
import { r, wp, wChunk, serializeFunction } from '@nuxt/utils'
import { r, wp, wChunk, serializeFunction, isFullStatic } from '@nuxt/utils'

export default class TemplateContext {
constructor (builder, options) {
Expand All @@ -20,6 +20,7 @@ export default class TemplateContext {
uniqBy,
isDev: options.dev,
isTest: options.test,
isFullStatic: isFullStatic(options),
debug: options.debug,
buildIndicator: options.dev && options.build.indicator,
vue: { config: options.vue.config },
Expand Down
3 changes: 3 additions & 0 deletions packages/builder/test/__utils__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const createNuxt = () => ({
build: {
watch: []
},
render: {
ssr: true
},
router: {},
dir: {
app: 'app'
Expand Down
4 changes: 3 additions & 1 deletion packages/builder/test/builder.build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('builder: builder build', () => {
nuxt.options.dir = { pages: '/var/nuxt/src/pages' }
nuxt.options.build.template = { dir: '/var/nuxt/src/template' }
nuxt.options.build.createRoutes = jest.fn()
nuxt.options.render = { ssr: true }

const bundleBuilder = { build: jest.fn() }
const builder = new Builder(nuxt, bundleBuilder)
Expand All @@ -47,7 +48,7 @@ describe('builder: builder build', () => {

const buildReturn = await builder.build()

expect(consola.info).toBeCalledTimes(1)
expect(consola.info).toBeCalledTimes(3)
expect(consola.info).toBeCalledWith('Production build')
expect(nuxt.ready).toBeCalledTimes(1)
expect(nuxt.callHook).toBeCalledTimes(3)
Expand Down Expand Up @@ -117,6 +118,7 @@ describe('builder: builder build', () => {
nuxt.options.buildDir = '/var/nuxt/build'
nuxt.options.dir = { pages: '/var/nuxt/src/pages' }
nuxt.options.build.createRoutes = jest.fn()
nuxt.options.render = { ssr: true }

const bundleBuilder = { build: jest.fn() }
const builder = new Builder(nuxt, bundleBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TemplateContext {
],
"head": "test_head",
"isDev": "test_dev",
"isFullStatic": false,
"isTest": "test_test",
"layoutTransition": Object {
"name": "test_layout_trans",
Expand Down
9 changes: 7 additions & 2 deletions packages/builder/test/context/build.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { TARGETS } from '@nuxt/utils'
import BuildContext from '../../src/context/build'

describe('builder: buildContext', () => {
test('should construct context', () => {
const builder = {
nuxt: { options: {} }
nuxt: {
options: {
target: TARGETS.server
}
}
}
const context = new BuildContext(builder)
expect(context._builder).toEqual(builder)
expect(context.nuxt).toEqual(builder.nuxt)
expect(context.options).toEqual(builder.nuxt.options)
expect(context.isStatic).toEqual(false)
expect(context.target).toEqual('server')
})

test('should return builder plugins context', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import consola from 'consola'
import { MODES, TARGETS } from '@nuxt/utils'
import { common, locking } from '../options'
import { createLock } from '../utils'

Expand Down Expand Up @@ -62,7 +64,7 @@ export default {
},
async run (cmd) {
const config = await cmd.getNuxtConfig({ dev: false, server: false, _build: true })
config.server = config.mode === 'spa' && cmd.argv.generate !== false
config.server = (config.mode === MODES.spa || config.ssr === false) && cmd.argv.generate !== false
const nuxt = await cmd.getNuxt(config)

if (cmd.argv.lock) {
Expand All @@ -73,14 +75,18 @@ export default {
}))
}

if (nuxt.options.mode === 'spa' && cmd.argv.generate !== false) {
// TODO: remove if in Nuxt 3
if (nuxt.options.mode === MODES.spa && nuxt.options.target === TARGETS.server && cmd.argv.generate !== false) {
// Build + Generate for static deployment
const generator = await cmd.getGenerator(nuxt)
await generator.generate({ build: true })
} else {
// Build only
const builder = await cmd.getBuilder(nuxt)
await builder.build()

const nextCommand = nuxt.options.target === TARGETS.static ? 'nuxt export' : 'nuxt start'
consola.info('Ready to run `' + (nextCommand) + '`')
}
}
}
50 changes: 50 additions & 0 deletions packages/cli/src/commands/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path'
import consola from 'consola'
import { TARGETS } from '@nuxt/utils'
import { common, locking } from '../options'
import { createLock } from '../utils'

export default {
name: 'export',
description: 'Export a static generated web application',
usage: 'export <dir>',
options: {
...common,
...locking,
'fail-on-error': {
type: 'boolean',
default: false,
description: 'Exit with non-zero status code if there are errors when exporting pages'
}
},
async run (cmd) {
const config = await cmd.getNuxtConfig({
dev: false,
target: TARGETS.static,
_export: true
})
const nuxt = await cmd.getNuxt(config)

if (cmd.argv.lock) {
await cmd.setLock(await createLock({
id: 'export',
dir: nuxt.options.generate.dir,
root: config.rootDir
}))
}

const generator = await cmd.getGenerator(nuxt)
await nuxt.server.listen()

const { errors } = await generator.generate({
init: true,
build: false
})

await nuxt.close()
if (cmd.argv['fail-on-error'] && errors.length > 0) {
throw new Error('Error exporting pages, exiting with non-zero code')
}
consola.info('Ready to run `nuxt serve` or deploy `' + path.basename(nuxt.options.generate.dir) + '/` directory')
}
}
Loading

0 comments on commit 7efe0a7

Please sign in to comment.