Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Made the location of dotfiles honor XDG_CONFIG_HOME #2418

Closed
wants to merge 1 commit into from

3 participants

@Soares

(And also XDG_CACHE_HOME)

The XDG specification allows users to specify configuration/data/cache locations so that their home directory need not be cluttered by a plethora of dotfiles (like .npm and .npmrc). npm should honor such settings.

@isaacs
Owner

It seems like it'd be better to just use this instead of the "HOME" when it's read in lib/utils/config-defs.js

var home = ( process.platform === "win32"
           ? process.env.USERPROFILE
           : process.env.HOME )

if (home) process.env.HOME = home
else home = temp

Then you don't have to sniff for the env so many other places.

Should the files still have dots if they're in there? If not, then that gets a bit complex and annoying.

@Soares

As a rule of thumb, stuff in "~/.config" doesn't have any further dots. (You can just "ls .config" and see what you've got installed). It is a bit annoying, which is why I tossed in the "config_file" function.

It's a necessary evil: we can't discard the dots until everyone is using XDG_CONFIG_HOME, and that won't happen until more apps start honoring it.

@isaacs
Owner

I don't agree that evil is necessary. The patch here is too complicated, and I'm going to forget what it's doing.

I'm not opposed to the idea in principle, but the implementation needs to be much more simple. Until that happens, we can keep being one of the programs that doesn't honor it.

@isaacs isaacs closed this
@isaacs
Owner

There are no plans.

If someone wants to write a very minimal and simple patch to have npm make XDG happy, then I'll merge it. But I really don't care about XDG even a little bit.

@eheintzmann

If you are waiting for a patch, maybe this bug should be reopened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 5, 2012
  1. @Soares
This page is out of date. Refresh to see the latest.
View
8 lib/completion.js
@@ -29,10 +29,18 @@ completion.completion = function (opts, cb) {
bashExists = !er
next()
})
+ fs.stat(path.resolve(process.env.XDG_CONFIG_HOME, "bashrc"), function (er, b) {
+ bashExists = !er
+ next()
+ })
fs.stat(path.resolve(process.env.HOME, ".zshrc"), function (er, b) {
zshExists = !er
next()
})
+ fs.stat(path.resolve(process.env.XDG_CONFIG_HOME, "zshrc"), function (er, b) {
+ zshExists = !er
+ next()
+ })
function next () {
if (zshExists === null || bashExists === null) return
var out = []
View
22 lib/utils/config-defs.js
@@ -74,6 +74,22 @@ var home = ( process.platform === "win32"
? process.env.USERPROFILE
: process.env.HOME )
+var config_file = function(name, alt) {
+ var config = process.env.XDG_CONFIG_HOME;
+ if (config === undefined) {
+ return path.resolve(home || alt, "." + name);
+ }
+ return path.resolve(config || alt, name)
+}
+
+var cache_file = function(name) {
+ var cache = process.env.XDG_CACHE_HOME;
+ if (cache === undefined) {
+ return path.resolve(home || temp, "." + name);
+ }
+ return path.resolve(cache || temp, name)
+}
+
if (home) process.env.HOME = home
else home = temp
@@ -139,7 +155,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, cache : process.platform === "win32"
? path.resolve(process.env.APPDATA || home || temp, "npm-cache")
- : path.resolve( home || temp, ".npm")
+ : cache_file("npm-cache", temp)
, "cache-max": Infinity
, "cache-min": 0
@@ -209,8 +225,8 @@ Object.defineProperty(exports, "defaults", {get: function () {
, usage : false
, user : process.platform === "win32" ? 0 : "nobody"
, username : ""
- , userconfig : path.resolve(home, ".npmrc")
- , userignorefile : path.resolve(home, ".npmignore")
+ , userconfig : config_file("npmrc")
+ , userignorefile : config_file("npmignore")
, umask: 022
, version : false
, versions : false
View
10 node_modules/node-gyp/lib/node-gyp.js
@@ -35,6 +35,14 @@ function gyp () {
return new Gyp
}
+function config_file(name) {
+ var config = process.env.XDG_CONFIG_FILE;
+ if (config !== undefined) {
+ return path.resolve(config, name);
+ }
+ return path.resolve(homeDir, "." + name);
+}
+
function Gyp () {
var me = this
@@ -42,7 +50,7 @@ function Gyp () {
// 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')
+ this.devDir = config_file("node-gyp")
this.commands = {}
Something went wrong with that request. Please try again.