From e530fa97ab8b8929898252e4ed8966ed6925d405 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Thu, 3 Jan 2019 00:41:14 +0000 Subject: [PATCH 1/3] refactor: use is prefix for booleans --- packages/core/src/resolver.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index 7dc898379c66..8504968654d0 100644 --- a/packages/core/src/resolver.js +++ b/packages/core/src/resolver.js @@ -1,10 +1,13 @@ 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' +const logger = consola.withTag('@nuxt/resolver') + export default class Resolver { constructor(nuxt) { this.nuxt = nuxt @@ -46,7 +49,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) { + logger.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') + } + if (module) { + logger.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 +66,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,15 +113,27 @@ export default class Resolver { throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`) } - requireModule(path, { esm, alias, intropDefault } = {}) { + requireModule(path, { esm, isEsm = esm, alias, isAlias = alias, intropDefault, shouldIntropDefault = intropDefault } = {}) { let resolvedPath = path let requiredModule + // TODO: Remove in Nuxt 3 + if (alias) { + logger.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') + } + if (esm) { + logger.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `isEsm` instead.') + } + + if (intropDefault) { + logger.warn('Using intropDefault is deprecated and will be removed in Nuxt 3. Use `shouldIntropDefault` instead.') + } + const errors = [] // Try to resolve path try { - resolvedPath = this.resolvePath(path, { alias }) + resolvedPath = this.resolvePath(path, { isAlias }) } catch (e) { errors.push(e) } @@ -127,7 +150,7 @@ export default class Resolver { } // Introp default - if (intropDefault !== false && requiredModule && requiredModule.default) { + if (shouldIntropDefault !== false && requiredModule && requiredModule.default) { requiredModule = requiredModule.default } From 1ed9e90fcb7fcdfe48c24ebd84e94f400a1041a5 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sat, 5 Jan 2019 21:59:34 +0000 Subject: [PATCH 2/3] Update resolver.js --- packages/core/src/resolver.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index 8504968654d0..9debc6946dd4 100644 --- a/packages/core/src/resolver.js +++ b/packages/core/src/resolver.js @@ -6,8 +6,6 @@ import esm from 'esm' import { startsWithRootAlias, startsWithSrcAlias } from '@nuxt/utils' -const logger = consola.withTag('@nuxt/resolver') - export default class Resolver { constructor(nuxt) { this.nuxt = nuxt @@ -52,10 +50,10 @@ export default class Resolver { resolvePath(path, { alias, isAlias = alias, module, isModule = module, isStyle } = {}) { // TODO: Remove in Nuxt 3 if (alias) { - logger.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') + consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') } if (module) { - logger.warn('Using module is deprecated and will be removed in Nuxt 3. Use `isModule` instead.') + consola.warn('Using module is deprecated and will be removed in Nuxt 3. Use `isModule` instead.') } // Fast return in case of path exists @@ -113,20 +111,16 @@ export default class Resolver { throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`) } - requireModule(path, { esm, isEsm = esm, alias, isAlias = alias, intropDefault, shouldIntropDefault = intropDefault } = {}) { + requireModule(path, { esm, useESM = esm, alias, isAlias = alias, intropDefault } = {}) { let resolvedPath = path let requiredModule // TODO: Remove in Nuxt 3 if (alias) { - logger.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') + consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.') } if (esm) { - logger.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `isEsm` instead.') - } - - if (intropDefault) { - logger.warn('Using intropDefault is deprecated and will be removed in Nuxt 3. Use `shouldIntropDefault` instead.') + consola.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `useESM` instead.') } const errors = [] @@ -150,7 +144,7 @@ export default class Resolver { } // Introp default - if (shouldIntropDefault !== false && requiredModule && requiredModule.default) { + if (intropDefault !== false && requiredModule && requiredModule.default) { requiredModule = requiredModule.default } From d2a1f898c022daaaf7d7c3101675559dc761d734 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sat, 5 Jan 2019 22:03:15 +0000 Subject: [PATCH 3/3] Update resolver.js --- packages/core/src/resolver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index 184895433a15..d3c605dc352f 100644 --- a/packages/core/src/resolver.js +++ b/packages/core/src/resolver.js @@ -122,7 +122,7 @@ export default class Resolver { if (esm) { consola.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `useESM` instead.') } - + let lastError // Try to resolve path