Skip to content

Commit a26f7d7

Browse files
isaacsry
authored andcommitted
Make require() from the repl be relative to cwd
1 parent 82813f2 commit a26f7d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/repl.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ var evalcx = process.binding('evals').Script.runInNewContext;
1717
var path = require("path");
1818
var scope;
1919

20+
function cwdRequire (id) {
21+
if (id.match(/^\.\.\//) || id.match(/^\.\//)) {
22+
id = path.join(process.cwd(), id);
23+
}
24+
return require(id);
25+
}
26+
2027
function setScope (self) {
2128
scope = {};
2229
for (var i in global) scope[i] = global[i];
2330
scope.module = module;
24-
scope.require = require;
31+
scope.require = cwdRequire;
2532
}
2633

2734

0 commit comments

Comments
 (0)