fix ~ shorthand problems

This commit is contained in:
Pooya Parsa 2017-05-21 20:11:00 +04:30
parent dabfe68009
commit da725cb11e
2 changed files with 5 additions and 4 deletions

View File

@ -95,9 +95,9 @@ class Module {
let module let module
try { try {
if (typeof src === 'string') { if (typeof src === 'string') {
// Using ~ shorthand modules are resolved from project srcDir // Using ~ shorthand to resolve from project srcDir
if (src.indexOf('~') === 0) { if (src.indexOf('~') === 0) {
src = path.resolve(this.options.srcDir, src.substr(1)) src = path.resolve(this.options.srcDir, src.replace(/^~\/?/, ''))
} }
// eslint-disable-next-line no-eval // eslint-disable-next-line no-eval
module = eval('require')(src) module = eval('require')(src)
@ -107,13 +107,14 @@ class Module {
console.error('[Nuxt] Unable to resolve module', src) console.error('[Nuxt] Unable to resolve module', src)
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(e) console.error(e)
return process.exit(0)
} }
// Validate module // Validate module
/* istanbul ignore if */ /* istanbul ignore if */
if (!(module instanceof Function)) { if (!(module instanceof Function)) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('[Nuxt] Module should be a function', module) console.error('[Nuxt] Module should be a function', module)
process.exit(0)
} }
// Add module to this.modules // Add module to this.modules
this.modules.push(module) this.modules.push(module)

View File

@ -25,7 +25,7 @@ class Server {
let src = m let src = m
// Using ~ shorthand to resolve from project srcDir // Using ~ shorthand to resolve from project srcDir
if (src.indexOf('~') === 0) { if (src.indexOf('~') === 0) {
src = path.resolve(this.nuxt.options.srcDir, src.substr(1)) src = path.resolve(this.nuxt.options.srcDir, src.replace(/^~\/?/, ''))
} }
// eslint-disable-next-line no-eval // eslint-disable-next-line no-eval
m = eval('require')(src) m = eval('require')(src)