From 686037f1cffb33dbe87f5fc32831cd8553edb0ee Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 8 Sep 2017 13:27:05 +0200 Subject: [PATCH] Fallback to regular require if `module.parent.require` is unavailable Some environments (like jest) don't implement it --- express.js | 5 +++-- src/express.js | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/express.js b/express.js index 1c85a57d95..9820929ab4 100644 --- a/express.js +++ b/express.js @@ -1,8 +1,9 @@ var isDebug = require('./env').isDebug; var parentModule = module.parent; +var parentRequire = parentModule && parentModule.require || require; if (isDebug) { - module.exports = parentModule.require('marko/src/express'); + module.exports = parentRequire('marko/src/express'); } else { - module.exports = parentModule.require('marko/dist/express'); + module.exports = parentRequire('marko/dist/express'); } diff --git a/src/express.js b/src/express.js index 1e535bc837..585fc9f8fe 100644 --- a/src/express.js +++ b/src/express.js @@ -1,7 +1,12 @@ require('./'); var assign = require('object-assign'); -var express = module.parent.require('express'); + +var parentModule = module.parent; +var parentRequire = parentModule && parentModule.require || require; + +var express = parentRequire('express'); + patchResponse(express.response); delete require.cache[__filename];