Update extendRoutes modules API

This commit is contained in:
Ivan Nikulin 2017-08-22 23:42:25 +02:00
parent 8cf5a21752
commit 416b84ccae
No known key found for this signature in database
GPG Key ID: F800F559F11A1A10
2 changed files with 20 additions and 1 deletions

View File

@ -74,7 +74,25 @@ export default class ModuleContainer extends Tapable {
}
extendRoutes (fn) {
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
const extendRoutesFromConfig = this.options.router.extendRoutes
this.options.router.extendRoutes = function (routes, resolve) {
/* istanbul ignore if */
if (!(fn instanceof Function)) {
return
}
if (typeof extendRoutesFromConfig !== 'function') {
return fn.call(this, routes, resolve)
}
let extendedRoutes = extendRoutesFromConfig.call(this, routes, resolve)
if (extendedRoutes === undefined) {
extendedRoutes = routes
}
let moduleExtendedRoutes = fn.call(this, extendedRoutes, resolve)
if (moduleExtendedRoutes === undefined) {
return extendedRoutes
}
return moduleExtendedRoutes
}
}
requireModule (moduleOpts) {

View File

@ -20,6 +20,7 @@ module.exports = function basicModule (options, resolve) {
// Extend routes
this.extendRoutes((routes, resolve) => {
// Do nothing!
return routes
})
// Require same module twice