Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use is prefix for booleans #4674

Merged
merged 4 commits into from Jan 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions packages/core/src/resolver.js
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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) {
manniL marked this conversation as resolved.
Show resolved Hide resolved
resolvedPath = this.resolveAlias(path)
}

Expand Down Expand Up @@ -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
}
Expand Down