From f30ef38c7058827f9f41d00e57155975e15cbdf3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 11 Jan 2018 22:19:54 +0330 Subject: [PATCH] fix(core): use options.extensions for resolvePath --- lib/core/nuxt.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index fe35e62b9b..ce7f7227a6 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -3,9 +3,10 @@ const enableDestroy = require('server-destroy') const Module = require('module') const { isPlainObject } = require('lodash') const chalk = require('chalk') +const { existsSync } = require('fs-extra') const { Options } = require('../common') const { sequence, printError, printWarn } = require('../common/utils') -const { join, resolve } = require('path') +const { resolve } = require('path') const { version } = require('../../package.json') const ModuleContainer = require('./module') const Renderer = require('./renderer') @@ -182,22 +183,30 @@ module.exports = class Nuxt { resolvePath(path) { // Try to resolve using NPM resolve path first try { - let resolvedPath = Module._resolveFilename(path, { + const resolvedPath = Module._resolveFilename(path, { paths: this.options.modulesDir }) return resolvedPath - } catch (e) { - // Continue to try other methods + } catch (error) { + if (error.code === 'MODULE_NOT_FOUND') { + // Continue to try other methods + } else { + throw error + } } - // Shorthand to resolve from project dirs + let _path = path if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) { - return join(this.options.rootDir, path.substr(2)) + _path = resolve(this.options.rootDir, path.substr(2)) } else if (path.indexOf('@') === 0 || path.indexOf('~') === 0) { - return join(this.options.srcDir, path.substr(1)) + _path = resolve(this.options.srcDir, path.substr(1)) } - return resolve(this.options.srcDir, path) + for (let ext of [''].concat(this.options.extensions)) { + if (existsSync(_path + ext)) { + return _path + ext + } + } } async close(callback) {