Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make require() from the repl be relative to cwd

  • Loading branch information...
commit f42cccf6eff6ee0f9271f83f8054d9d4b45c3a38 1 parent cc12f51
@isaacs authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/repl.js
View
9 lib/repl.js
@@ -17,11 +17,18 @@ var evalcx = process.binding('evals').Script.runInNewContext;
var path = require("path");
var scope;
+function cwdRequire (id) {
+ if (id.match(/^\.\.\//) || id.match(/^\.\//)) {
+ id = path.join(process.cwd(), id);
+ }
+ return require(id);
+}
+
function setScope (self) {
scope = {};
for (var i in global) scope[i] = global[i];
scope.module = module;
- scope.require = require;
+ scope.require = cwdRequire;
}
Please sign in to comment.
Something went wrong with that request. Please try again.