Skip to content

Commit

Permalink
Merge pull request #834 from SimenB/parent-require
Browse files Browse the repository at this point in the history
Fallback to regular require if `module.parent.require` is unavailable
  • Loading branch information
patrick-steele-idem authored Sep 19, 2017
2 parents 582e699 + 686037f commit 2afc986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions express.js
Original file line number Diff line number Diff line change
@@ -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');
}
7 changes: 6 additions & 1 deletion src/express.js
Original file line number Diff line number Diff line change
@@ -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];

Expand Down

0 comments on commit 2afc986

Please sign in to comment.