chore: fix all eslint error and warnings

This commit is contained in:
Clark Du 2020-08-17 20:12:34 +01:00
parent 052364c689
commit c63091b68d
17 changed files with 32 additions and 21 deletions

View File

@ -1,5 +1,5 @@
// Add polyfill imports to the first file encountered. // Add polyfill imports to the first file encountered.
module.exports = ({ types }) => { module.exports = ({ _types }) => {
let entryFile let entryFile
return { return {
name: 'inject-polyfills', name: 'inject-polyfills',

View File

@ -1,5 +1,4 @@
import { resolve } from 'path' import { resolve } from 'path'
import { createWatcher } from './watch'
export interface NuxtRoute { export interface NuxtRoute {
path: '' path: ''

View File

@ -1,5 +1,6 @@
import { join } from 'path' import { join } from 'path'
import fsExtra from 'fs-extra' import fsExtra from 'fs-extra'
import consola from 'consola'
import { BundleBuilder } from 'src/webpack' import { BundleBuilder } from 'src/webpack'
import { Nuxt } from '../core' import { Nuxt } from '../core'
import { compileTemplates, scanTemplates, NuxtTemplate } from './template' import { compileTemplates, scanTemplates, NuxtTemplate } from './template'
@ -40,7 +41,7 @@ function watch (builder: Builder) {
const nuxtAppWatcher = createWatcher(nuxt.options.appDir) const nuxtAppWatcher = createWatcher(nuxt.options.appDir)
// nuxtAppWatcher.debug() // nuxtAppWatcher.debug()
nuxtAppWatcher.watchAll(async () => { nuxtAppWatcher.watchAll(async () => {
console.log('Re-generate templates') consola.log('Re-generate templates')
await compileTemplates(builder.templates, nuxt.options.buildDir) await compileTemplates(builder.templates, nuxt.options.buildDir)
}) })
@ -56,7 +57,7 @@ function watch (builder: Builder) {
await generate(builder) await generate(builder)
}) })
appWatcher.watch('pages/', async () => { appWatcher.watch('pages/', async () => {
console.log('Re-generate routes') consola.log('Re-generate routes')
await compileTemplates(builder.templates, nuxt.options.buildDir) await compileTemplates(builder.templates, nuxt.options.buildDir)
}) })
} }

View File

@ -1,7 +1,6 @@
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import ignore from 'ignore' import ignore from 'ignore'
import { NormalizedConfiguration } from 'src/config'
type IgnoreInstance = ReturnType<typeof ignore> type IgnoreInstance = ReturnType<typeof ignore>
type IgnoreOptions = Parameters<typeof ignore>[0] type IgnoreOptions = Parameters<typeof ignore>[0]

View File

@ -1,9 +1,10 @@
import { join, relative, dirname } from 'path' import { join, relative, dirname } from 'path'
import fsExtra from 'fs-extra' import fsExtra from 'fs-extra'
import globby from 'globby' import globby from 'globby'
import consola from 'consola'
import lodashTemplate from 'lodash/template' import lodashTemplate from 'lodash/template'
interface NuxtTemplate { export interface NuxtTemplate {
src: string // Absolute path to source file src: string // Absolute path to source file
path: string // Relative path of destination path: string // Relative path of destination
data?: any data?: any
@ -13,12 +14,12 @@ async function compileTemplate ({ src, path, data }: NuxtTemplate, destDir: stri
const srcContents = await fsExtra.readFile(src, 'utf-8') const srcContents = await fsExtra.readFile(src, 'utf-8')
const compiledSrc = lodashTemplate(srcContents, {})(data) const compiledSrc = lodashTemplate(srcContents, {})(data)
const dest = join(destDir, path) const dest = join(destDir, path)
console.log('Compile template', dest) consola.log('Compile template', dest)
await fsExtra.mkdirp(dirname(dest)) await fsExtra.mkdirp(dirname(dest))
await fsExtra.writeFile(dest, compiledSrc) await fsExtra.writeFile(dest, compiledSrc)
} }
export async function compileTemplates (templates: NuxtTemplate[], destDir: string) { export function compileTemplates (templates: NuxtTemplate[], destDir: string) {
return Promise.all(templates.map(t => compileTemplate(t, destDir))) return Promise.all(templates.map(t => compileTemplate(t, destDir)))
} }
@ -32,7 +33,7 @@ export async function scanTemplates (dir: string, data?: Object) {
})) }))
} }
export async function watchTemplate (template: NuxtTemplate, watcher: any, cb: Function) { export function watchTemplate (template: NuxtTemplate, _watcher: any, _cb: Function) {
template.data = new Proxy(template.data, { template.data = new Proxy(template.data, {
// TODO: deep watch option changes // TODO: deep watch option changes
}) })

View File

@ -1,7 +1,8 @@
import { relative } from 'path' import { relative } from 'path'
import chokidar, { WatchOptions } from 'chokidar' import chokidar, { WatchOptions } from 'chokidar'
import consola from 'consola'
export function createWatcher (dir: string|string[], options?: WatchOptions) { export function createWatcher (dir: string, options?: WatchOptions) {
const watcher = chokidar.watch(dir, { const watcher = chokidar.watch(dir, {
ignored: [], ignored: [],
ignoreInitial: true, ignoreInitial: true,
@ -9,7 +10,7 @@ export function createWatcher (dir: string|string[], options?: WatchOptions) {
}) })
const watchAll = (cb: Function, filter?: Function) => { const watchAll = (cb: Function, filter?: Function) => {
watcher.on('raw', (event, path: string, details) => { watcher.on('raw', (event, path: string, _details) => {
if (options.ignored.find(ignore => path.match(ignore))) { if (options.ignored.find(ignore => path.match(ignore))) {
return // 🖕 chokidar ignored option return // 🖕 chokidar ignored option
} }
@ -24,9 +25,9 @@ export function createWatcher (dir: string|string[], options?: WatchOptions) {
const watch = (pattern: string| RegExp, cb: Function) => watchAll(cb, e => e.path.match(pattern)) const watch = (pattern: string| RegExp, cb: Function) => watchAll(cb, e => e.path.match(pattern))
const debug = (tag: string = '[Watcher]') => { const debug = (tag: string = '[Watcher]') => {
console.log(tag, 'Watching ', dir) consola.log(tag, 'Watching ', dir)
watchAll((e) => { watchAll((e) => {
console.log(tag, e.event, e.path) consola.log(tag, e.event, e.path)
}) })
} }

View File

@ -150,7 +150,7 @@ export default class NuxtCommand extends Hookable {
return nuxt return nuxt
} }
async getBuilder (nuxt: Nuxt) { getBuilder (nuxt: Nuxt) {
return new Builder(nuxt) return new Builder(nuxt)
} }

View File

@ -34,7 +34,7 @@ export default {
if (options.target === TARGETS.server) { if (options.target === TARGETS.server) {
throw new Error('You cannot use `nuxt serve` with ' + TARGETS.server + ' target, please use `nuxt start`') throw new Error('You cannot use `nuxt serve` with ' + TARGETS.server + ' target, please use `nuxt start`')
} }
const distStat = await fs.stat(options.generate.dir).catch(err => null) // eslint-disable-line handle-callback-err const distStat = await fs.stat(options.generate.dir).catch(_err => null) // eslint-disable-line handle-callback-err
if (!distStat || !distStat.isDirectory()) { if (!distStat || !distStat.isDirectory()) {
throw new Error('Output directory `' + basename(options.generate.dir) + '/` does not exists, please run `nuxt export` before `nuxt serve`.') throw new Error('Output directory `' + basename(options.generate.dir) + '/` does not exists, please run `nuxt export` before `nuxt serve`.')
} }

View File

@ -22,7 +22,7 @@ export default {
alias: 'm', alias: 'm',
type: 'string', type: 'string',
description: 'Build/Start app for modern browsers, e.g. server, client and false', description: 'Build/Start app for modern browsers, e.g. server, client and false',
prepare (cmd, options, argv) { prepare (_cmd, options, argv) {
if (argv.modern !== undefined) { if (argv.modern !== undefined) {
options.modern = normalizeArg(argv.modern) options.modern = normalizeArg(argv.modern)
} }
@ -32,7 +32,7 @@ export default {
alias: 't', alias: 't',
type: 'string', type: 'string',
description: 'Build/start app for a different target, e.g. server, serverless and static', description: 'Build/start app for a different target, e.g. server, serverless and static',
prepare (cmd, options, argv) { prepare (_cmd, options, argv) {
if (argv.target) { if (argv.target) {
options.target = argv.target options.target = argv.target
} }

View File

@ -84,6 +84,7 @@ interface CommonConfiguration {
_modules: NuxtModule[] _modules: NuxtModule[]
_nuxtConfigFile?: string _nuxtConfigFile?: string
alias: Record<string, string> alias: Record<string, string>
appDir: string,
buildDir: string buildDir: string
buildModules: NuxtModule[] buildModules: NuxtModule[]
createRequire?: (module: NodeJS.Module) => NodeJS.Require createRequire?: (module: NodeJS.Module) => NodeJS.Require

View File

@ -73,7 +73,7 @@ interface RenderOptions {
export default (): RenderOptions => ({ export default (): RenderOptions => ({
bundleRenderer: { bundleRenderer: {
shouldPrefetch: () => false, shouldPrefetch: () => false,
shouldPreload: (fileWithoutQuery, asType) => ['script', 'style'].includes(asType), shouldPreload: (_fileWithoutQuery, asType) => ['script', 'style'].includes(asType),
runInNewContext: undefined runInNewContext: undefined
}, },
crossorigin: undefined, crossorigin: undefined,

View File

@ -4,8 +4,11 @@ export interface ServerProcessEnv extends NodeJS.ProcessEnv {
HOST?: string HOST?: string
PORT?: string PORT?: string
UNIX_SOCKET?: string UNIX_SOCKET?: string
// eslint-disable-next-line camelcase
npm_package_config_nuxt_port?: string npm_package_config_nuxt_port?: string
// eslint-disable-next-line camelcase
npm_package_config_nuxt_host?: string npm_package_config_nuxt_host?: string
// eslint-disable-next-line camelcase
npm_package_config_unix_socket?: string npm_package_config_unix_socket?: string
} }

View File

@ -16,6 +16,7 @@ interface InputConfiguration {
layoutTransition?: string | DefaultConfiguration['layoutTransition'] layoutTransition?: string | DefaultConfiguration['layoutTransition']
loading?: true | false | DefaultConfiguration['loading'] loading?: true | false | DefaultConfiguration['loading']
manifest?: { manifest?: {
// eslint-disable-next-line camelcase
theme_color?: string theme_color?: string
} }
pageTransition?: string | DefaultConfiguration['pageTransition'] pageTransition?: string | DefaultConfiguration['pageTransition']

View File

@ -14,7 +14,11 @@ import ModuleContainer from './module'
import Resolver from './resolver' import Resolver from './resolver'
declare global { declare global {
var __NUXT_DEV__: boolean namespace NodeJS {
interface Global {
__NUXT_DEV__: boolean
}
}
} }
export default class Nuxt extends Hookable { export default class Nuxt extends Hookable {

View File

@ -49,7 +49,7 @@ function cleanChildrenRoutes (routes: NuxtRouteConfig[], isChild = false, routeN
routes.forEach((route) => { routes.forEach((route) => {
route.path = isChild ? route.path.replace('/', '') : route.path route.path = isChild ? route.path.replace('/', '') : route.path
if (route.path.includes('?')) { if (route.path.includes('?')) {
const names = typeof route.name === 'string' && route.name.split(routeNameSplitter) || [] const names = typeof route.name === 'string' ? route.name.split(routeNameSplitter) : []
const paths = route.path.split('/') const paths = route.path.split('/')
if (!isChild) { if (!isChild) {
paths.shift() paths.shift()

View File

@ -22,6 +22,7 @@ export const timeout = function timeout <T> (
) { ) {
let timerId: NodeJS.Timeout let timerId: NodeJS.Timeout
const warpPromise = promiseFinally(fn, () => clearTimeout(timerId)) const warpPromise = promiseFinally(fn, () => clearTimeout(timerId))
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const timerPromise = new Promise((resolve, reject) => { const timerPromise = new Promise((resolve, reject) => {
timerId = setTimeout(() => reject(new Error(msg)), ms) timerId = setTimeout(() => reject(new Error(msg)), ms)
}) })

View File

@ -136,7 +136,7 @@ export default function nodeExternals (options) {
: readDir(modulesDir).filter(isNotBinary) : readDir(modulesDir).filter(isNotBinary)
// return an externals function // return an externals function
return function ({ context, request }, callback) { return function ({ context: _context, request }, callback) {
const moduleName = getModuleName(request, includeAbsolutePaths) const moduleName = getModuleName(request, includeAbsolutePaths)
if ( if (
contains(nodeModules, moduleName) && contains(nodeModules, moduleName) &&