global-prefix
Advanced tools
+45
-37
| /*! | ||
| * 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()); | ||
| } | ||
| }); |
+2
-2
| The MIT License (MIT) | ||
| Copyright (c) 2015-2016, Jon Schlinkert. | ||
| Copyright (c) 2015-2017, Jon Schlinkert. | ||
@@ -21,2 +21,2 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| THE SOFTWARE. |
+17
-16
| { | ||
| "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)" | ||
| ] | ||
| } | ||
| } |
+14
-12
@@ -1,2 +0,2 @@ | ||
| # global-prefix [](https://www.npmjs.com/package/global-prefix) [](https://npmjs.org/package/global-prefix) [](https://travis-ci.org/jonschlinkert/global-prefix) [](https://ci.appveyor.com/project/jonschlinkert/global-prefix) | ||
| # global-prefix [](https://www.npmjs.com/package/global-prefix) [](https://npmjs.org/package/global-prefix) [](https://npmjs.org/package/global-prefix) [](https://travis-ci.org/jonschlinkert/global-prefix) [](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._ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
7.28%2
-33.33%80
11.11%0
-100%78
2.63%0
-100%+ Added
- Removed
Updated
Updated
Updated