From 78433b599ed448fb4ca975d919e79d050798a354 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sun, 6 Jan 2019 08:02:28 +0000 Subject: [PATCH] refactor: use is prefix for booleans (#4674) --- packages/core/src/resolver.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index 048c208e41..d3c605dc35 100644 --- a/packages/core/src/resolver.js +++ b/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' @@ -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 }