global-prefix
Advanced tools
Comparing version 0.1.3 to 0.1.4
76
index.js
@@ -10,9 +10,7 @@ /*! | ||
/** | ||
* This is the code used internally by npm to | ||
* resolve the global prefix. | ||
*/ | ||
var fs = require('fs') | ||
var path = require('path'); | ||
var osenv = require('osenv'); | ||
var ini = require('ini'); | ||
var isWindows = require('is-windows'); | ||
var path = require('path'); | ||
var prefix; | ||
@@ -22,17 +20,63 @@ | ||
prefix = process.env.PREFIX; | ||
} else if (isWindows === true || isWindows()) { | ||
// c:\node\node.exe --> prefix=c:\node\ | ||
prefix = process.env.APPDATA | ||
? path.join(process.env.APPDATA, 'npm') | ||
: path.dirname(process.execPath); | ||
} else { | ||
// /usr/local/bin/node --> prefix=/usr/local | ||
prefix = path.dirname(path.dirname(process.execPath)); | ||
// Start by checking if the global prefix is set by the user | ||
var userConfig = path.resolve(osenv.home(), '.npmrc'); | ||
prefix = readPrefix(userConfig); | ||
// destdir only is respected on Unix | ||
if (process.env.DESTDIR) { | ||
prefix = path.join(process.env.DESTDIR, prefix); | ||
if (!prefix) { | ||
// Otherwise find the path of npm | ||
var npm = npmPath(); | ||
if (npm) { | ||
// Check the built-in npm config file | ||
var builtinConfig = path.resolve(npm, '..', '..', 'npmrc'); | ||
prefix = readPrefix(builtinConfig); | ||
if (prefix) { | ||
// Now the global npm config can also be checked. | ||
var globalConfig = path.resolve(prefix, 'etc', 'npmrc'); | ||
prefix = readPrefix(globalConfig) || prefix; | ||
} | ||
} | ||
if (!prefix) fallback(); | ||
} | ||
} | ||
function fallback() { | ||
var isWindows = require('is-windows'); | ||
if (isWindows()) { | ||
// c:\node\node.exe --> prefix=c:\node\ | ||
prefix = process.env.APPDATA | ||
? path.join(process.env.APPDATA, 'npm') | ||
: path.dirname(process.execPath); | ||
} else { | ||
// /usr/local/bin/node --> prefix=/usr/local | ||
prefix = path.dirname(path.dirname(process.execPath)); | ||
// destdir only is respected on Unix | ||
if (process.env.DESTDIR) { | ||
prefix = path.join(process.env.DESTDIR, prefix); | ||
} | ||
} | ||
} | ||
function npmPath() { | ||
try { | ||
return fs.realpathSync(require('which').sync('npm')) | ||
} catch (ex) { | ||
} | ||
return false | ||
} | ||
function readPrefix(configPath) { | ||
try { | ||
var data = fs.readFileSync(configPath, 'utf-8'); | ||
var config = ini.parse(data); | ||
if (config.prefix) return config.prefix; | ||
} catch (ex) { | ||
// file not found | ||
} | ||
return false; | ||
} | ||
module.exports = prefix; |
{ | ||
"name": "global-prefix", | ||
"description": "Get the npm global path prefix.", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/jonschlinkert/global-prefix", | ||
@@ -23,7 +23,10 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"is-windows": "^0.1.1" | ||
"ini": "^1.3.4", | ||
"is-windows": "^0.2.0", | ||
"osenv": "^0.1.3", | ||
"which": "^1.2.10" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^0.1.7", | ||
"mocha": "^2.4.5" | ||
"gulp-format-md": "^0.1.9", | ||
"mocha": "^2.5.3" | ||
}, | ||
@@ -30,0 +33,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68
4163
4
3
1
0
8
+ Addedini@^1.3.4
+ Addedosenv@^0.1.3
+ Addedwhich@^1.2.10
+ Addedini@1.3.8(transitive)
+ Addedis-windows@0.2.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedwhich@1.3.1(transitive)
- Removedis-windows@0.1.1(transitive)
Updatedis-windows@^0.2.0