Browse Source

Make require() from the repl be relative to cwd

v0.7.4-release
isaacs 15 years ago
committed by Ryan Dahl
parent
commit
a26f7d753d
  1. 9
      lib/repl.js

9
lib/repl.js

@ -17,11 +17,18 @@ var evalcx = process.binding('evals').Script.runInNewContext;
var path = require("path"); var path = require("path");
var scope; var scope;
function cwdRequire (id) {
if (id.match(/^\.\.\//) || id.match(/^\.\//)) {
id = path.join(process.cwd(), id);
}
return require(id);
}
function setScope (self) { function setScope (self) {
scope = {}; scope = {};
for (var i in global) scope[i] = global[i]; for (var i in global) scope[i] = global[i];
scope.module = module; scope.module = module;
scope.require = require; scope.require = cwdRequire;
} }

Loading…
Cancel
Save