global-prefix
Advanced tools
Comparing version 0.1.5 to 1.0.0
82
index.js
/*! | ||
* global-prefix <https://github.com/jonschlinkert/global-prefix> | ||
* | ||
* Copyright (c) 2015 Jon Schlinkert. | ||
* Copyright (c) 2015-2017 Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
@@ -10,37 +10,39 @@ */ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var homedir = require('homedir-polyfill'); | ||
var path = require('path'); | ||
var ini = require('ini'); | ||
var fs = require('fs') | ||
var prefix; | ||
if (process.env.PREFIX) { | ||
prefix = process.env.PREFIX; | ||
} else { | ||
// Start by checking if the global prefix is set by the user | ||
var home = homedir(); | ||
if (home) { | ||
// homedir() returns undefined if $HOME not set; path.resolve requires strings | ||
var userConfig = path.resolve(home, '.npmrc'); | ||
prefix = readPrefix(userConfig); | ||
} | ||
function getPrefix() { | ||
if (process.env.PREFIX) { | ||
prefix = process.env.PREFIX; | ||
} else { | ||
// Start by checking if the global prefix is set by the user | ||
var home = homedir(); | ||
if (home) { | ||
// homedir() returns undefined if $HOME not set; path.resolve requires strings | ||
var userConfig = path.resolve(home, '.npmrc'); | ||
prefix = tryConfigPath(userConfig); | ||
} | ||
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) { | ||
// Otherwise find the path of npm | ||
var npm = tryNpmPath(); | ||
if (npm) { | ||
// Check the built-in npm config file | ||
var builtinConfig = path.resolve(npm, '..', '..', 'npmrc'); | ||
prefix = tryConfigPath(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) { | ||
// Now the global npm config can also be checked. | ||
var globalConfig = path.resolve(prefix, 'etc', 'npmrc'); | ||
prefix = tryConfigPath(globalConfig) || prefix; | ||
} | ||
} | ||
if (!prefix) fallback(); | ||
} | ||
if (!prefix) fallback(); | ||
} | ||
return prefix; | ||
} | ||
@@ -66,11 +68,10 @@ | ||
function npmPath() { | ||
function tryNpmPath() { | ||
try { | ||
return fs.realpathSync(require('which').sync('npm')); | ||
} catch (ex) { | ||
} | ||
return false; | ||
} catch (err) {} | ||
return null; | ||
} | ||
function readPrefix(configPath) { | ||
function tryConfigPath(configPath) { | ||
try { | ||
@@ -80,8 +81,15 @@ var data = fs.readFileSync(configPath, 'utf-8'); | ||
if (config.prefix) return config.prefix; | ||
} catch (ex) { | ||
// file not found | ||
} | ||
return false; | ||
} catch (err) {} | ||
return null; | ||
} | ||
module.exports = prefix; | ||
/** | ||
* Expose `prefix` | ||
*/ | ||
Object.defineProperty(module, 'exports', { | ||
enumerable: true, | ||
get: function() { | ||
return prefix || (prefix = getPrefix()); | ||
} | ||
}); |
{ | ||
"name": "global-prefix", | ||
"description": "Get the npm global path prefix.", | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/jonschlinkert/global-prefix", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"contributors": [ | ||
"Alexandr Bogachev (https://github.com/rmbaad)", | ||
"Brian Woodward (https://twitter.com/doowb)", | ||
"Charlike Mike Reagent (https://i.am.charlike.online)", | ||
"JasonChang (https://packagist.org/packages/jason-chang)", | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)", | ||
"Jorrit Schippers (https://www.ncode.nl)", | ||
"Mathias Rasmussen (chrome://dino)", | ||
"Ross Fenning (http://rossfenning.co.uk)" | ||
], | ||
"repository": "jonschlinkert/global-prefix", | ||
@@ -23,11 +33,10 @@ "bugs": { | ||
"dependencies": { | ||
"homedir-polyfill": "^1.0.0", | ||
"homedir-polyfill": "^1.0.1", | ||
"ini": "^1.3.4", | ||
"is-windows": "^0.2.0", | ||
"which": "^1.2.12" | ||
"is-windows": "^1.0.1", | ||
"which": "^1.2.14" | ||
}, | ||
"devDependencies": { | ||
"fs-exists-sync": "^0.1.0", | ||
"gulp-format-md": "^0.1.11", | ||
"mocha": "^3.2.0" | ||
"gulp-format-md": "^0.1.12", | ||
"mocha": "^3.4.2" | ||
}, | ||
@@ -65,11 +74,3 @@ "keywords": [ | ||
} | ||
}, | ||
"contributors": [ | ||
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)", | ||
"Alexandr Bogachev <kuksikus@gmail.com> (https://github.com/rmbaad)", | ||
"JasonChang <chaoyue.chang@qq.com> (https://packagist.org/packages/jason-chang)", | ||
"Jorrit Schippers (https://www.ncode.nl)", | ||
"Mathias Rasmussen (https://github.com/mathiasvr)", | ||
"Charlike Mike Reagent (http://i.am.charlike.online)" | ||
] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# global-prefix [![NPM version](https://img.shields.io/npm/v/global-prefix.svg?style=flat)](https://www.npmjs.com/package/global-prefix) [![NPM downloads](https://img.shields.io/npm/dm/global-prefix.svg?style=flat)](https://npmjs.org/package/global-prefix) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/global-prefix.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/global-prefix) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/global-prefix.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/global-prefix) | ||
# global-prefix [![NPM version](https://img.shields.io/npm/v/global-prefix.svg?style=flat)](https://www.npmjs.com/package/global-prefix) [![NPM monthly downloads](https://img.shields.io/npm/dm/global-prefix.svg?style=flat)](https://npmjs.org/package/global-prefix) [![NPM total downloads](https://img.shields.io/npm/dt/global-prefix.svg?style=flat)](https://npmjs.org/package/global-prefix) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/global-prefix.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/global-prefix) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/global-prefix.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/global-prefix) | ||
@@ -13,3 +13,3 @@ > Get the npm global path prefix. | ||
This is based on the code used by npm internally to resolve the global prefix. | ||
This is partially based on the code used by npm internally to resolve the global prefix. | ||
@@ -20,3 +20,3 @@ ## Usage | ||
var prefix = require('global-prefix'); | ||
//=> '/usr/local' | ||
//=> '/usr/local' (this path will differ by system and user-defined config) | ||
``` | ||
@@ -40,3 +40,5 @@ | ||
| 16 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 15 | [doowb](https://github.com/doowb) | | ||
| 1 | [rmbaad](https://github.com/rmbaad) | | ||
| 1 | [avengerpenguin](https://github.com/avengerpenguin) | | ||
| 1 | [jason-chang](https://github.com/jason-chang) | | ||
@@ -49,8 +51,8 @@ | 1 | [jorrit](https://github.com/jorrit) | | ||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ | ||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | ||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm install -g verb verb-generate-readme && verb | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
@@ -60,6 +62,6 @@ | ||
Install dev dependencies: | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
```sh | ||
$ npm install -d && npm test | ||
$ npm install && npm test | ||
``` | ||
@@ -72,11 +74,11 @@ | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](LICENSE). | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 30, 2016._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 28, 2017._ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8490
2
80
0
78
0
+ Addedis-windows@1.0.2(transitive)
- Removedis-windows@0.2.0(transitive)
Updatedhomedir-polyfill@^1.0.1
Updatedis-windows@^1.0.1
Updatedwhich@^1.2.14