From 470f04efebbd05fee38b85202d1a830c90382c45 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Sun, 27 May 2012 00:43:00 -0700 Subject: [PATCH] added support for inheriting config env variable from npm So you can pass node-gyp-specific flags to npm, and node-gyp will automatically use them: $ npm install weak --nodedir=`pwd` --prefix=`pwd` Part of #70. --- lib/node-gyp.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/node-gyp.js b/lib/node-gyp.js index 33c5445a61..ad92e817a7 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -112,6 +112,25 @@ proto.parseArgv = function parseOpts (argv) { }, this) this.todo = commands + + // support for inheriting config env variables from npm + var npm_config_prefix = 'npm_config_' + Object.keys(process.env).forEach(function (name) { + if (name.indexOf(npm_config_prefix) !== 0) return + var val = process.env[name] + if (name === npm_config_prefix + 'loglevel') { + // "loglevel" is a special case; check for "verbose" + if (val === 'verbose') { + this.opts.verbose = true + } + } else { + // take the config name and check if it's one that node-gyp cares about + name = name.substring(npm_config_prefix.length) + if (name in this.configDefs) { + this.opts[name] = val + } + } + }, this) } /**