Skip to content

Commit 9c8d275

Browse files
committed
Add --devdir flag.
Overrides the location where node-gyp will look for (and download to) the node.js SDK. For harmonization with the --nodedir flag, `osenv.home()` is now used instead of `process.env.HOME || process.env.USERPROFILE`. `osenv.home()` defaults to the built-in `os.homedir()` when available and falls back to sane defaults based on the platform. `%USERPROFILE%` is now preferred on Windows and `%HOME%` is ignored; similarly, UNIX systems ignore `$USERPROFILE` from now on. Neither behavior made much sense, IMO. Fixes: #21 PR-URL: #916 Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent f6eab1f commit 9c8d275

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Command Options
175175
| `--thin=yes` | Enable thin static libraries
176176
| `--arch=$arch` | Set target architecture (e.g. ia32)
177177
| `--tarball=$path` | Get headers from a local tarball
178+
| `--devdir=$path` | SDK download directory (default=~/.node-gyp)
178179
| `--ensure` | Don't reinstall headers if already present
179180
| `--dist-url=$url` | Download header tarball from custom URL
180181
| `--proxy=$url` | Set HTTP proxy for downloading header tarball

bin/node-gyp.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ process.title = 'node-gyp'
1212

1313
var gyp = require('../')
1414
var log = require('npmlog')
15+
var osenv = require('osenv')
16+
var path = require('path')
1517

1618
/**
1719
* Process and execute the selected commands.
@@ -20,6 +22,19 @@ var log = require('npmlog')
2022
var prog = gyp()
2123
var completed = false
2224
prog.parseArgv(process.argv)
25+
prog.devDir = prog.opts.devdir
26+
27+
var homeDir = osenv.home()
28+
if (prog.devDir) {
29+
prog.devDir = prog.devDir.replace(/^~/, homeDir)
30+
} else if (homeDir) {
31+
prog.devDir = path.resolve(homeDir, '.node-gyp')
32+
} else {
33+
throw new Error(
34+
"node-gyp requires that the user's home directory is specified " +
35+
"in either of the environmental variables HOME or USERPROFILE. " +
36+
"Overide with: --devdir /path/to/.node-gyp")
37+
}
2338

2439
if (prog.todo.length === 0) {
2540
if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {

lib/node-gyp.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ function gyp () {
4646
function Gyp () {
4747
var self = this
4848

49-
// set the dir where node-gyp dev files get installed
50-
// TODO: make this *more* configurable?
51-
// see: https://github.com/nodejs/node-gyp/issues/21
52-
var homeDir = process.env.HOME || process.env.USERPROFILE
53-
if (!homeDir) {
54-
throw new Error(
55-
"node-gyp requires that the user's home directory is specified " +
56-
"in either of the environmental variables HOME or USERPROFILE"
57-
);
58-
}
59-
this.devDir = path.resolve(homeDir, '.node-gyp')
60-
49+
this.devDir = ''
6150
this.commands = {}
6251

6352
commands.forEach(function (command) {
@@ -92,6 +81,7 @@ proto.configDefs = {
9281
, ensure: Boolean // 'install'
9382
, solution: String // 'build' (windows only)
9483
, proxy: String // 'install'
84+
, devdir: String // everywhere
9585
, nodedir: String // 'configure'
9686
, loglevel: String // everywhere
9787
, python: String // 'configure'

0 commit comments

Comments
 (0)