refactor: use is prefix for booleans (#4674)

This commit is contained in:
Alexander Lichter 2019-01-06 08:02:28 +00:00 committed by Pooya Parsa
parent 605b76073b
commit 78433b599e

View File

@ -1,6 +1,7 @@
import Module from 'module'
import { resolve, join } from 'path'
import fs from 'fs-extra'
import consola from 'consola'
import esm from 'esm'
import { startsWithRootAlias, startsWithSrcAlias } from '@nuxt/utils'
@ -46,7 +47,15 @@ export default class Resolver {
return resolve(this.options.srcDir, path)
}
resolvePath(path, { alias, module, isStyle } = {}) {
resolvePath(path, { alias, isAlias = alias, module, isModule = module, isStyle } = {}) {
// TODO: Remove in Nuxt 3
if (alias) {
consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.')
}
if (module) {
consola.warn('Using module is deprecated and will be removed in Nuxt 3. Use `isModule` instead.')
}
// Fast return in case of path exists
if (fs.existsSync(path)) {
return path
@ -55,12 +64,12 @@ export default class Resolver {
let resolvedPath
// Try to resolve it as a regular module
if (module !== false) {
if (isModule !== false) {
resolvedPath = this.resolveModule(path)
}
// Try to resolve alias
if (!resolvedPath && alias !== false) {
if (!resolvedPath && isAlias !== false) {
resolvedPath = this.resolveAlias(path)
}
@ -102,14 +111,23 @@ export default class Resolver {
throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`)
}
requireModule(path, { esm, alias, intropDefault } = {}) {
requireModule(path, { esm, useESM = esm, alias, isAlias = alias, intropDefault } = {}) {
let resolvedPath = path
let requiredModule
// TODO: Remove in Nuxt 3
if (alias) {
consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.')
}
if (esm) {
consola.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `useESM` instead.')
}
let lastError
// Try to resolve path
try {
resolvedPath = this.resolvePath(path, { alias })
resolvedPath = this.resolvePath(path, { isAlias })
} catch (e) {
lastError = e
}