From c3bba0cceba71145036ab94b4915364b7ad766a4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 22 Sep 2014 23:10:06 +0200 Subject: [PATCH] Load ~/.powrc too --- lib/rack_application.js | 20 ++++++++++++-------- lib/util.js | 2 ++ src/rack_application.coffee | 25 +++++++++++++++++-------- src/util.coffee | 1 + 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/rack_application.js b/lib/rack_application.js index 643b1d8..decfe6c 100644 --- a/lib/rack_application.js +++ b/lib/rack_application.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.6.2 (function() { - var RackApplication, async, basename, bufferLines, fs, join, nack, pause, resolve, sourceScriptEnv, _ref, _ref1; + var RackApplication, async, basename, bufferLines, fs, join, nack, pause, quote, resolve, sourceScriptEnv, _ref, _ref1; async = require("async"); @@ -8,7 +8,7 @@ nack = require("nack"); - _ref = require("./util"), bufferLines = _ref.bufferLines, pause = _ref.pause, sourceScriptEnv = _ref.sourceScriptEnv; + _ref = require("./util"), bufferLines = _ref.bufferLines, pause = _ref.pause, sourceScriptEnv = _ref.sourceScriptEnv, quote = _ref.quote; _ref1 = require("path"), join = _ref1.join, basename = _ref1.basename, resolve = _ref1.resolve; @@ -80,14 +80,18 @@ }; RackApplication.prototype.loadScriptEnvironment = function(env, callback) { - var _this = this; - - return async.reduce([".powrc", ".envrc", ".powenv"], env, function(env, filename, callback) { - var script; + var before, envFiles, home, + _this = this; - return fs.exists(script = join(_this.root, filename), function(scriptExists) { + home = process.env["HOME"]; + envFiles = [join(home, ".powrc"), join(this.root, ".powrc"), join(this.root, ".envrc"), join(this.root, ".powenv")]; + before = "cd " + (quote(this.root)); + return async.reduce(envFiles, env, function(env, script, callback) { + return fs.exists(script, function(scriptExists) { if (scriptExists) { - return sourceScriptEnv(script, env, callback); + return sourceScriptEnv(script, env, { + before: before + }, callback); } else { return callback(null, env); } diff --git a/lib/util.js b/lib/util.js index 19ba8b4..ca4e7f7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -246,6 +246,8 @@ return "'" + string.replace(/\'/g, "'\\''") + "'"; }; + exports.quote = quote; + makeTemporaryFilename = function() { var filename, random, timestamp, tmpdir, _ref; diff --git a/src/rack_application.coffee b/src/rack_application.coffee index d8bd0bf..35b77c6 100644 --- a/src/rack_application.coffee +++ b/src/rack_application.coffee @@ -28,7 +28,7 @@ async = require "async" fs = require "fs" nack = require "nack" -{bufferLines, pause, sourceScriptEnv} = require "./util" +{bufferLines, pause, sourceScriptEnv, quote} = require "./util" {join, basename, resolve} = require "path" module.exports = class RackApplication @@ -88,15 +88,24 @@ module.exports = class RackApplication @statCallbacks.push callback - # Collect environment variables from `.powrc` and `.powenv`, in that - # order, if present. The idea is that `.powrc` files can be checked - # into a source code repository for global configuration, leaving - # `.powenv` free for any necessary local overrides. + # Collect environment variables from `~/.powrc`, `.powrc` and `.powenv`, + # in that order, if present. The idea is that `.powrc` files can be checked + # into a source code repository for global configuration, leaving `.powenv` + # free for any necessary local overrides. The files will be executed from + # the project root. loadScriptEnvironment: (env, callback) -> - async.reduce [".powrc", ".envrc", ".powenv"], env, (env, filename, callback) => - fs.exists script = join(@root, filename), (scriptExists) -> + home = process.env["HOME"] + envFiles = [ + join(home, ".powrc"), + join(@root, ".powrc"), + join(@root, ".envrc"), + join(@root, ".powenv"), + ] + before = "cd #{quote @root}" + async.reduce envFiles, env, (env, script, callback) => + fs.exists script, (scriptExists) -> if scriptExists - sourceScriptEnv script, env, callback + sourceScriptEnv script, env, {before}, callback else callback null, env , callback diff --git a/src/util.coffee b/src/util.coffee index d303ab2..9aaf390 100644 --- a/src/util.coffee +++ b/src/util.coffee @@ -170,6 +170,7 @@ exec = (command, options, callback) -> # Single-quote a string for command line execution. quote = (string) -> "'" + string.replace(/\'/g, "'\\''") + "'" +exports.quote = quote # Generate and return a unique temporary filename based on the # current process's PID, the number of milliseconds elapsed since the