fix: passing module as a function

This commit is contained in:
Pooya Parsa 2017-05-24 17:32:33 +04:30
parent 4028abc1e1
commit 6e44648bfc

View File

@ -85,28 +85,27 @@ class Module {
// Allows passing runtime options to each module
const options = moduleOpts.options || {}
const originalSrc = moduleOpts.src || moduleOpts
let src = originalSrc
// Resolve module
let module
let module = originalSrc
try {
if (typeof src === 'string') {
if (typeof module === 'string') {
// Using ~ or ./ shorthand modules are resolved from project srcDir
if (src.indexOf('~') === 0 || src.indexOf('./') === 0) {
src = path.join(this.options.srcDir, src.substr(1))
if (module.indexOf('~') === 0 || module.indexOf('./') === 0) {
module = path.join(this.options.srcDir, module.substr(1))
}
// eslint-disable-next-line no-eval
module = eval('require')(src)
module = eval('require')(module)
}
} catch (e) /* istanbul ignore next */ {
// eslint-disable-next-line no-console
console.error('[nuxt] Unable to resolve module', src)
console.error('[nuxt] Unable to resolve module', module)
// eslint-disable-next-line no-console
console.error(e)
process.exit(0)
}
// Validate module
/* istanbul ignore if */
if (!(module instanceof Function)) {
if (typeof module !== 'function') {
// eslint-disable-next-line no-console
console.error(`[nuxt] Module [${originalSrc}] should export a function`)
process.exit(1)