mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Merge remote-tracking branch 'origin/master' into dev
This commit is contained in:
commit
dfef5252de
@ -1,5 +1,5 @@
|
||||
import Module from 'module'
|
||||
import path from 'path'
|
||||
import { resolve, join } from 'path'
|
||||
|
||||
import enableDestroy from 'server-destroy'
|
||||
import _ from 'lodash'
|
||||
@ -158,44 +158,56 @@ export default class Nuxt {
|
||||
}))
|
||||
}
|
||||
|
||||
resolveAlias(_path) {
|
||||
if (_path.indexOf('@@') === 0 || _path.indexOf('~~') === 0) {
|
||||
return path.join(this.options.rootDir, _path.substr(2))
|
||||
}
|
||||
|
||||
if (_path.indexOf('@') === 0 || _path.indexOf('~') === 0) {
|
||||
return path.join(this.options.srcDir, _path.substr(1))
|
||||
}
|
||||
|
||||
return path.resolve(this.options.srcDir, _path)
|
||||
}
|
||||
|
||||
resolvePath(_path) {
|
||||
// Try to resolve using NPM resolve path first
|
||||
resolveModule(path) {
|
||||
try {
|
||||
const resolvedPath = Module._resolveFilename(_path, {
|
||||
const resolvedPath = Module._resolveFilename(path, {
|
||||
paths: this.options.modulesDir
|
||||
})
|
||||
|
||||
return resolvedPath
|
||||
} catch (error) {
|
||||
if (error.code !== 'MODULE_NOT_FOUND') {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
return null
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let __path = this.resolveAlias(_path)
|
||||
resolveAlias(path) {
|
||||
const modulePath = this.resolveModule(path)
|
||||
|
||||
if (fs.existsSync(__path)) {
|
||||
return __path
|
||||
// Try to resolve it as if it were a regular node_module
|
||||
// Package first. Fixes issue with @<org> scoped packages
|
||||
if (modulePath != null) {
|
||||
return modulePath
|
||||
}
|
||||
|
||||
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
|
||||
return join(this.options.rootDir, path.substr(2))
|
||||
}
|
||||
|
||||
if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
|
||||
return join(this.options.srcDir, path.substr(1))
|
||||
}
|
||||
|
||||
return resolve(this.options.srcDir, path)
|
||||
}
|
||||
|
||||
resolvePath(path) {
|
||||
const _path = this.resolveAlias(path)
|
||||
|
||||
if (fs.existsSync(_path)) {
|
||||
return _path
|
||||
}
|
||||
|
||||
for (let ext of this.options.extensions) {
|
||||
if (fs.existsSync(__path + '.' + ext)) {
|
||||
return __path + '.' + ext
|
||||
if (fs.existsSync(_path + '.' + ext)) {
|
||||
return _path + '.' + ext
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Cannot resolve "${_path}" from "${__path}"`)
|
||||
throw new Error(`Cannot resolve "${path}" from "${_path}"`)
|
||||
}
|
||||
|
||||
requireModule(_path, opts = {}) {
|
||||
|
Loading…
Reference in New Issue
Block a user