Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added magic sauce for .noderc.js in $HOME and `pwd`

  • Loading branch information...
commit e1c8ad419e80cb0ebe6164be5566380f7a423782 1 parent f405daa
@regality authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/node.js
View
35 src/node.js
@@ -123,11 +123,32 @@
if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
opts.useColors = false;
}
+
+ var home = process.env.HOME;
+ var pwd = NativeModule.require('path').resolve('.');
+
+ var noderc = home + "/.noderc.js";
+ var pwdrc = pwd + "/.noderc.js";
+
+ var homeContext = home ? loadContext(noderc) : {};
+ var pwdContext = pwd ? loadContext(pwdrc) : {};
+
var repl = Module.requireRepl().start(opts);
repl.on('exit', function() {
process.exit();
});
+ for (var i in homeContext) {
+ if (homeContext.hasOwnProperty(i)) {
+ repl.context[i] = homeContext[i];
+ }
+ }
+ for (var i in pwdContext) {
+ if (pwdContext.hasOwnProperty(i)) {
+ repl.context[i] = pwdContext[i];
+ }
+ }
+
} else {
// Read all of stdin - execute it.
process.stdin.resume();
@@ -146,6 +167,20 @@
}
}
+ function loadContext(file) {
+ var Module = NativeModule.require('module');
+ var context;
+ try {
+ context = Module._load(file);
+ } catch (e) {
+ context = {};
+ }
+ if (!context || typeof context !== 'object') {
+ context = {};
+ }
+ return context;
+ }
+
startup.globalVariables = function() {
global.process = process;
global.global = global;
Please sign in to comment.
Something went wrong with that request. Please try again.