Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the dev installation directory configurable (~/.node-gyp) #21

Closed
TooTallNate opened this issue Feb 12, 2012 · 30 comments
Closed

Make the dev installation directory configurable (~/.node-gyp) #21

TooTallNate opened this issue Feb 12, 2012 · 30 comments

Comments

@TooTallNate
Copy link
Contributor

Not a real high priority to me, but 👍 if you want this feature.

@TooTallNate
Copy link
Contributor Author

Could probably add a --dev-dir flag or something real quick.

@Soares
Copy link

Soares commented May 4, 2012

I'd suggest just using process.env.XDG_CONFIG_HOME || process.env.HOME as a simple solution.

@apaprocki
Copy link

Getting hit by this because I'm behind a proxy which doesn't allow GET from nodejs.org. It would be great to support a -g option to install globally similar to npm install -g and node-gyp would simply look in the global dir first before the home dir.

@TooTallNate
Copy link
Contributor Author

@apaprocki This option would still require you to download node header files, this would just be where to store them. I think what you're looking for is the --nodedir option, which can be used to specify the location of a node source tree to compile the addon against (that option already exists).

@apaprocki
Copy link

@TooTallNate Yes, --nodedir would be useful. Above, I was thinking about the case where an admin (or user with sufficient proxy privileges) would install the dev files in the global dir so that every user on the machine does not need to download/install a local copy in their home dir.

@TooTallNate
Copy link
Contributor Author

@apaprocki Ok I see what you mean now. Yes, could do what you are describing with this proposed --devdir flag. Frankly, it should be pretty easy if anyone feels like whipping up a patch.

@mindon
Copy link

mindon commented Aug 31, 2012

suggest detecting NODE_ROOT variable in env variables as nodeDir when there's no --nodedir

if ( gyp.opts.nodedir || process.env.NODE_ROOT ) {
  // --nodedir was specified. use that for the dev files
  nodeDir = gyp.opts.nodedir ? gyp.opts.nodedir.replace(/^~/, osenv.home()) : process.env.NODE_ROOT

  log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir)
  createBuildDir()
 } else {
  // ....
 }

then we don't need to configure with --nodedir every time

@mroch
Copy link

mroch commented Nov 8, 2012

@TooTallNate: what do you think of @mindon's proposal? I can send a pull request...

We'd appreciate this change here at Facebook. Our build process is pretty crazy. Being able to set an environment variable is preferable to a flag for us because npm defaults to node-gyp rebuild, and some modules have the node-gyp command hardcoded, making it impossible to override the default args without patching their package.json.

@zcbenz
Copy link
Contributor

zcbenz commented Feb 19, 2013

@TooTallNate: Any news on this? I just hit this problem while building native modules against my custom headers, if there is something like --nodedir or an environment variable then I don't need to fork node-gyp.

@TooTallNate
Copy link
Contributor Author

The --nodedir flag is there

On Tuesday, February 19, 2013, Cheng Zhao wrote:

@TooTallNate https://github.com/TooTallNate: Any news on this? I just
hit this problem while building native modules against my custom headers,
if there is something like --nodedir or an environment variable then I
don't need to fork node-gyp.


Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-13774715.

@zcbenz
Copy link
Contributor

zcbenz commented Feb 19, 2013

Oops, I meant --devdir. Using --nodedir will assume headers are already downloaded and will skip the install step, I think a flag like --devdir is still needed.

@TooTallNate
Copy link
Contributor Author

Well you can kinda hack it at the moment by setting the HOME env variable, but a proper patch adding --devdir would be accepted as well.

@charlieok
Copy link

I love the way npm handles config params:
https://npmjs.org/doc/config.html

Same values can be set via flags, env vars, per-user files, global files, builtins set by ./configure params, and defaults. It even provides commands a script can use to create and populate the config files (which is what I ended up doing, but I could have also set up vars or managed the configs in version control). Wish more software were so flexible in this regard.

I'm putting together a build process that wraps a large collection of various software packages. node/npm was a breeze because of its flexible options. Right now node-gyp is sticking out like a sore thumb because of the ~/.node-gyp directory it's leaving behind when I don't want anything in $HOME.

@toolness
Copy link

toolness commented May 6, 2013

Hey, just wanted to mention that I'm installing bcrypt as part of a user-data script on Amazon EC2, which uses node-gyp to compile some binaries. However, because node-gyp expects either HOME or USERPROFILE to be defined in the environment, and EC2 doesn't set either of these environment variables itself when running the userdata script as root, the installation fails with the following traceback:

path.js:313
        throw new TypeError('Arguments to path.resolve must be strings');
              ^
TypeError: Arguments to path.resolve must be strings
    at Object.exports.resolve (path.js:313:15)
    at new Gyp (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:49:22)
    at gyp (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:39:10)
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:20:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

I was able to resolve this by defining HOME in my script, but it took me a while to figure this out. Perhaps this story can be used as a use-case in figuring out a solution to this problem--or at the very least, perhaps someone who stumbles into the same problem as me finds this comment in the future helpful.

@mojodna
Copy link

mojodna commented Oct 28, 2013

👍

npm's cache config is along the lines of what I'd expect here: https://npmjs.org/doc/cli/npm-cache.html#CONFIGURATION

(Context: persistent node-gyp cache on Heroku between builds.)

@terinjokes
Copy link

We'd like our build boxes to be self-contained from external systems, and that includes nodejs.org. We can easily package up the node headers alongside our package of node, but we don't have any way of configuring node-gyp to using it, short of symlinking in ~/.node-gyp, which is a bit dirty. I'd would be happy with setting an ENV variable that sets the node header path.

@jasonkarns
Copy link
Member

I would suggest following the XDG base directory spec

AFAIK, everything in ~/.node-gyp is cache data, so I would propose $XDG_CACHE_HOME/node/gyp. If anything qualifies as "appdata" then $XDG_DATA_HOME/node/gyp

grahaml pushed a commit to grahaml/node-gyp that referenced this issue Nov 26, 2014
- Allows users to specify development directory using '--dev-dir' flag
- Added check for XDG_CACHE_HOME before HOME
@rafi
Copy link

rafi commented Jun 19, 2015

Until you guys decide, it'll be great if you offer an environment variable or npm style config, e.g.

cache  = ${XDG_CACHE_HOME}/node-gyp

:)

@dantran
Copy link

dantran commented Sep 16, 2015

where are we with this issue??. Dont meant to brag, but the discusion started in 2012 :-) and there is PR

@codyps
Copy link

codyps commented Sep 21, 2015

Having an env-var as @mindon suggested would be useful for me as well. Not clear how to adjust the way npm calls node-gyp.

grahaml pushed a commit to grahaml/node-gyp that referenced this issue Sep 28, 2015
codyps added a commit to codyps/meta-nodejs that referenced this issue Oct 7, 2015
@terinjokes
Copy link

@TooTallNate echoing @jmesmon I don't know of a good way to change how npm calls node-gyp for me to add the --nodedir header. Can we get this as an environment option?

ninja-edit: Per npm-install this can be done by passing --nodedir to npm install.

@bnoordhuis
Copy link
Member

@terinjokes You can pass --nodedir to npm and npm will pass it on to node-gyp. Alternatively, you can set npm_config_nodedir=/path/to/sources in the environment.

@terinjokes
Copy link

@bnoordhuis I had just edited my comment to point that out.

gautaz added a commit to telecomsante/dnpm that referenced this issue Nov 13, 2016
@jcrben
Copy link

jcrben commented Nov 14, 2016

Does npm support npm_config_devdir? I tried to test it using a recent npm version (3.10.3) by reinstalling all my global packages but not really sure how all this stuff is tied together... installing a bunch of packages did not generate anything new in my .node-gyp file.

@bnoordhuis
Copy link
Member

It should. npm passes on options it doesn't consume itself.

@develar
Copy link

develar commented Jun 5, 2017

Since electron-builder 18.4.0 ugly solution HOME env will be not used anymore. Because in this case cache dir is doubled (yarn and npm have to download and cache deps twice). Thanks! --devdir and npm_config_devdir works in my tests. I will risk to roll out this update to users. Thanks again that now node-gyp allows to set devdir.

@jcrben
Copy link

jcrben commented Feb 10, 2018

never ended up figuring out how this works - I suppose I might dig into the code someday... these were the steps, expecting node 8.9.1 with npm 5.5.1 executingnpm install -g node-gyp to put ~/.node-gyp into the devdir (which I'm setting with export npm_config_devdir="$XDG_CACHE_HOME"/.node-gyp in my .bashrc on macOS 10.12.16
image

@jasonkarns fyi, for me, it doesn't seem like ~/.node-gyp is cache data - it's got include files and stuff to run applications, I suppose in XDG it would end up in XDG_DATA_HOME or something

@absolutelynothelix
Copy link

node-gyp/lib/node-gyp.js

Lines 41 to 45 in 470f04e

// set the dir where node-gyp dev files get installed
// TODO: make this configurable?
// see: https://github.com/TooTallNate/node-gyp/issues/21
var homeDir = process.env.HOME || process.env.USERPROFILE
this.devDir = path.resolve(homeDir, '.node-gyp')

found this issue while digging the source code on how it works. yeah, can we have a environment variable or something to move this folder? i don't want to keep this at my home folder and i've already moved almost anything in corresponding folders ($XDG_CONFIG_HOME, $XDG_CACHE_HOME and $XDG_DATA_HOME)

@richardlau
Copy link
Member

@mighty9245 You should be able to use the --devdir parameter if manually invoking node-gyp or set the npm_config_devdir environment variable to change the folder.

@absolutelynothelix
Copy link

oh, so it was implemented? sorry, looked through readme, source code and several posts in this issue since i'm not working with node-gyp and something that i built created this directory and i just wanted to prevent this in future. ok, i'll try that, thanks!

targos added a commit to targos/node-gyp that referenced this issue Aug 22, 2021
- E302 expected 2 blank lines, found 1
- E711 comparison to None should be 'if cond is not None:'
- E713 test for membership should be 'not in'
- E721 do not compare types, use 'isinstance()'
- E731 do not assign a lambda expression, use a def
- E741 ambiguous variable name
- F402 import shadowed by loop variable

Co-authored-by: Christian Clauss <cclauss@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests