mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +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 Module from 'module'
|
||||||
import path from 'path'
|
import { resolve, join } from 'path'
|
||||||
|
|
||||||
import enableDestroy from 'server-destroy'
|
import enableDestroy from 'server-destroy'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
@ -158,44 +158,56 @@ export default class Nuxt {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveAlias(_path) {
|
resolveModule(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
|
|
||||||
try {
|
try {
|
||||||
const resolvedPath = Module._resolveFilename(_path, {
|
const resolvedPath = Module._resolveFilename(path, {
|
||||||
paths: this.options.modulesDir
|
paths: this.options.modulesDir
|
||||||
})
|
})
|
||||||
|
|
||||||
return resolvedPath
|
return resolvedPath
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code !== 'MODULE_NOT_FOUND') {
|
if (error.code === 'MODULE_NOT_FOUND') {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let __path = this.resolveAlias(_path)
|
resolveAlias(path) {
|
||||||
|
const modulePath = this.resolveModule(path)
|
||||||
|
|
||||||
if (fs.existsSync(__path)) {
|
// Try to resolve it as if it were a regular node_module
|
||||||
return __path
|
// 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) {
|
for (let ext of this.options.extensions) {
|
||||||
if (fs.existsSync(__path + '.' + ext)) {
|
if (fs.existsSync(_path + '.' + ext)) {
|
||||||
return __path + '.' + ext
|
return _path + '.' + ext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Cannot resolve "${_path}" from "${__path}"`)
|
throw new Error(`Cannot resolve "${path}" from "${_path}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
requireModule(_path, opts = {}) {
|
requireModule(_path, opts = {}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user