fix(core): use options.extensions for resolvePath

This commit is contained in:
Pooya Parsa 2018-01-11 22:19:54 +03:30
parent 811201925d
commit f30ef38c70

View File

@ -3,9 +3,10 @@ const enableDestroy = require('server-destroy')
const Module = require('module') const Module = require('module')
const { isPlainObject } = require('lodash') const { isPlainObject } = require('lodash')
const chalk = require('chalk') const chalk = require('chalk')
const { existsSync } = require('fs-extra')
const { Options } = require('../common') const { Options } = require('../common')
const { sequence, printError, printWarn } = require('../common/utils') const { sequence, printError, printWarn } = require('../common/utils')
const { join, resolve } = require('path') const { resolve } = require('path')
const { version } = require('../../package.json') const { version } = require('../../package.json')
const ModuleContainer = require('./module') const ModuleContainer = require('./module')
const Renderer = require('./renderer') const Renderer = require('./renderer')
@ -182,22 +183,30 @@ module.exports = class Nuxt {
resolvePath(path) { resolvePath(path) {
// Try to resolve using NPM resolve path first // Try to resolve using NPM resolve path first
try { try {
let resolvedPath = Module._resolveFilename(path, { const resolvedPath = Module._resolveFilename(path, {
paths: this.options.modulesDir paths: this.options.modulesDir
}) })
return resolvedPath return resolvedPath
} catch (e) { } catch (error) {
// Continue to try other methods 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) { 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) { } 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) { async close(callback) {