Skip to content

Commit

Permalink
fix(@embark/coderunner): use custom require function in vm context
Browse files Browse the repository at this point in the history
Supply a custom require function to the vm context for `doEval` so that module
resolution succeeds for both DApp dependencies and Embark dependencies.
  • Loading branch information
michaelsbradleyjr authored and iurimatias committed Jan 9, 2019
1 parent c6c6af0 commit 2dea50a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib/core/modules/coderunner/runCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ const noop = function() {};
class RunCode {
constructor({logger}) {
this.logger = logger;
const customRequire = (mod) => {
return require(customRequire.resolve(mod));
};
customRequire.resolve = (mod) => {
return require.resolve(
mod,
{paths: [fs.dappPath('node_modules'), fs.embarkPath('node_modules')]}
);
};
const newGlobal = Object.create(global);
newGlobal.fs = fs;
this.context = Object.assign({}, {
global: newGlobal, console, exports, require, module, __filename, __dirname, process,
setTimeout, setInterval, clearTimeout, clearInterval
global: newGlobal, console, exports, require: customRequire, module,
__filename, __dirname, process, setTimeout, setInterval, clearTimeout,
clearInterval
});
}

Expand Down

0 comments on commit 2dea50a

Please sign in to comment.