Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

global-prefix

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

global-prefix - npm Package Compare versions

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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc