global-prefix
Advanced tools
Comparing version 1.0.2 to 3.0.0
101
index.js
/*! | ||
* global-prefix <https://github.com/jonschlinkert/global-prefix> | ||
* | ||
* Copyright (c) 2015-2017 Jon Schlinkert. | ||
* Copyright (c) 2015-present Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
@@ -10,53 +10,45 @@ */ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var expand = require('expand-tilde'); | ||
var homedir = require('homedir-polyfill'); | ||
var ini = require('ini'); | ||
var prefix; | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const ini = require('ini'); | ||
let prefix; | ||
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); | ||
} | ||
const getPrefix = () => { | ||
if (process.env.PREFIX) return process.env.PREFIX; | ||
if (prefix) return prefix; | ||
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); | ||
// Start by checking if the global prefix is set by the user | ||
let home = os.homedir(); | ||
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(); | ||
} | ||
// os.homedir() returns undefined if $HOME is not set; path.resolve requires strings | ||
if (home) { | ||
prefix = tryConfigPath(path.resolve(home, '.npmrc')); | ||
} | ||
if (prefix) { | ||
return expand(prefix); | ||
return prefix; | ||
} | ||
} | ||
function fallback() { | ||
var isWindows = require('is-windows'); | ||
if (isWindows()) { | ||
// Otherwise find the path of npm | ||
let npm = tryNpmPath(); | ||
if (npm) { | ||
// Check the built-in npm config file | ||
prefix = tryConfigPath(path.resolve(npm, '..', '..', 'npmrc')); | ||
if (prefix) { | ||
// Now the global npm config can also be checked. | ||
prefix = tryConfigPath(path.resolve(prefix, 'etc', 'npmrc')) || prefix; | ||
} | ||
} | ||
if (!prefix) { | ||
let { APPDATA, DESTDIR, OSTYPE } = process.env; | ||
// c:\node\node.exe --> prefix=c:\node\ | ||
prefix = process.env.APPDATA | ||
? path.join(process.env.APPDATA, 'npm') | ||
: path.dirname(process.execPath); | ||
} else { | ||
if (process.platform === 'win32' || OSTYPE === 'msys' || OSTYPE === 'cygwin') { | ||
prefix = APPDATA ? path.join(APPDATA, 'npm') : path.dirname(process.execPath); | ||
return prefix; | ||
} | ||
// /usr/local/bin/node --> prefix=/usr/local | ||
@@ -66,6 +58,8 @@ prefix = path.dirname(path.dirname(process.execPath)); | ||
// destdir only is respected on Unix | ||
if (process.env.DESTDIR) { | ||
prefix = path.join(process.env.DESTDIR, prefix); | ||
if (DESTDIR) { | ||
prefix = path.join(DESTDIR, prefix); | ||
} | ||
} | ||
return prefix; | ||
} | ||
@@ -76,4 +70,3 @@ | ||
return fs.realpathSync(require('which').sync('npm')); | ||
} catch (err) {} | ||
return null; | ||
} catch (err) { /* do nothing */ } | ||
} | ||
@@ -83,7 +76,4 @@ | ||
try { | ||
var data = fs.readFileSync(configPath, 'utf-8'); | ||
var config = ini.parse(data); | ||
if (config.prefix) return config.prefix; | ||
} catch (err) {} | ||
return null; | ||
return ini.parse(fs.readFileSync(configPath, 'utf-8')).prefix; | ||
} catch (err) { /* do nothing */ } | ||
} | ||
@@ -95,7 +85,6 @@ | ||
Object.defineProperty(module, 'exports', { | ||
enumerable: true, | ||
get: function() { | ||
return prefix || (prefix = getPrefix()); | ||
Reflect.defineProperty(module, 'exports', { | ||
get() { | ||
return getPrefix(); | ||
} | ||
}); |
{ | ||
"name": "global-prefix", | ||
"description": "Get the npm global path prefix.", | ||
"version": "1.0.2", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/jonschlinkert/global-prefix", | ||
@@ -27,3 +27,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=6" | ||
}, | ||
@@ -34,11 +34,9 @@ "scripts": { | ||
"dependencies": { | ||
"expand-tilde": "^2.0.2", | ||
"homedir-polyfill": "^1.0.1", | ||
"ini": "^1.3.4", | ||
"is-windows": "^1.0.1", | ||
"which": "^1.2.14" | ||
"ini": "^1.3.5", | ||
"kind-of": "^6.0.2", | ||
"which": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^0.1.12", | ||
"mocha": "^3.4.2" | ||
"gulp-format-md": "^2.0.0", | ||
"mocha": "^5.2.0" | ||
}, | ||
@@ -53,26 +51,3 @@ "keywords": [ | ||
"resolve" | ||
], | ||
"verb": { | ||
"run": true, | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"global-modules", | ||
"global-paths" | ||
] | ||
}, | ||
"reflinks": [ | ||
"verb" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
] | ||
} |
@@ -5,2 +5,4 @@ # 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) | ||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
## Install | ||
@@ -25,26 +27,23 @@ | ||
### Related projects | ||
<details> | ||
<summary><strong>Contributing</strong></summary> | ||
* [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules "The directory used by npm for globally installed npm modules.") | ||
* [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique "global" directories based on the user's platform and environment. The… [more](https://github.com/jonschlinkert/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths "Returns an array of unique "global" directories based on the user's platform and environment. The resulting paths can be used for doing lookups for generators or other globally installed npm packages. Node.js / JavaScript.") | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Contributing | ||
</details> | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
<details> | ||
<summary><strong>Running Tests</strong></summary> | ||
### Contributors | ||
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: | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 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) | | ||
| 1 | [jorrit](https://github.com/jorrit) | | ||
| 1 | [mathiasvr](https://github.com/mathiasvr) | | ||
| 1 | [tunnckoCore](https://github.com/tunnckoCore) | | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
### Building docs | ||
</details> | ||
<details> | ||
<summary><strong>Building docs</strong></summary> | ||
_(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.)_ | ||
@@ -58,10 +57,24 @@ | ||
### Running tests | ||
</details> | ||
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: | ||
### Related projects | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
You might also be interested in these projects: | ||
* [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules "The directory used by npm for globally installed npm modules.") | ||
* [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique "global" directories based on the user's platform and environment. The… [more](https://github.com/jonschlinkert/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths "Returns an array of unique "global" directories based on the user's platform and environment. The resulting paths can be used for doing lookups for generators or other globally installed npm packages. Node.js / JavaScript.") | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 23 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 15 | [doowb](https://github.com/doowb) | | ||
| 2 | [phated](https://github.com/phated) | | ||
| 1 | [rmbaad](https://github.com/rmbaad) | | ||
| 1 | [avengerpenguin](https://github.com/avengerpenguin) | | ||
| 1 | [jorrit](https://github.com/jorrit) | | ||
| 1 | [mathiasvr](https://github.com/mathiasvr) | | ||
| 1 | [tunnckoCore](https://github.com/tunnckoCore) | | ||
### Author | ||
@@ -71,8 +84,9 @@ | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
### License | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
@@ -82,2 +96,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 28, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 11, 2018._ |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
3
92
5
0
8272
68
+ Addedkind-of@^6.0.2
+ Addedkind-of@6.0.3(transitive)
- Removedexpand-tilde@^2.0.2
- Removedhomedir-polyfill@^1.0.1
- Removedis-windows@^1.0.1
- Removedexpand-tilde@2.0.2(transitive)
- Removedhomedir-polyfill@1.0.3(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedparse-passwd@1.0.0(transitive)
Updatedini@^1.3.5
Updatedwhich@^1.3.1