diff options
Diffstat (limited to 'node_modules/global-prefix')
-rw-r--r-- | node_modules/global-prefix/LICENSE | 21 | ||||
-rw-r--r-- | node_modules/global-prefix/index.js | 80 | ||||
l--------- | node_modules/global-prefix/node_modules/.bin/which | 1 | ||||
-rw-r--r-- | node_modules/global-prefix/package.json | 64 |
4 files changed, 166 insertions, 0 deletions
diff --git a/node_modules/global-prefix/LICENSE b/node_modules/global-prefix/LICENSE new file mode 100644 index 000000000..1e49edf81 --- /dev/null +++ b/node_modules/global-prefix/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2016, Jon Schlinkert. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/global-prefix/index.js b/node_modules/global-prefix/index.js new file mode 100644 index 000000000..591f6be8b --- /dev/null +++ b/node_modules/global-prefix/index.js @@ -0,0 +1,80 @@ +/*! + * global-prefix <https://github.com/jonschlinkert/global-prefix> + * + * Copyright (c) 2015 Jon Schlinkert. + * Licensed under the MIT license. + */ + +'use strict'; + +var fs = require('fs') +var path = require('path'); +var osenv = require('osenv'); +var ini = require('ini'); + +var prefix; + +if (process.env.PREFIX) { + prefix = process.env.PREFIX; +} else { + // Start by checking if the global prefix is set by the user + var userConfig = path.resolve(osenv.home(), '.npmrc'); + prefix = readPrefix(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) { + // 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; diff --git a/node_modules/global-prefix/node_modules/.bin/which b/node_modules/global-prefix/node_modules/.bin/which new file mode 120000 index 000000000..091d52ad6 --- /dev/null +++ b/node_modules/global-prefix/node_modules/.bin/which @@ -0,0 +1 @@ +../../../which/bin/which
\ No newline at end of file diff --git a/node_modules/global-prefix/package.json b/node_modules/global-prefix/package.json new file mode 100644 index 000000000..28f595305 --- /dev/null +++ b/node_modules/global-prefix/package.json @@ -0,0 +1,64 @@ +{ + "name": "global-prefix", + "description": "Get the npm global path prefix.", + "version": "0.1.4", + "homepage": "https://github.com/jonschlinkert/global-prefix", + "author": "Jon Schlinkert (https://github.com/jonschlinkert)", + "repository": "jonschlinkert/global-prefix", + "bugs": { + "url": "https://github.com/jonschlinkert/global-prefix/issues" + }, + "license": "MIT", + "files": [ + "index.js" + ], + "main": "index.js", + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha" + }, + "dependencies": { + "ini": "^1.3.4", + "is-windows": "^0.2.0", + "osenv": "^0.1.3", + "which": "^1.2.10" + }, + "devDependencies": { + "gulp-format-md": "^0.1.9", + "mocha": "^2.5.3" + }, + "keywords": [ + "global", + "module", + "modules", + "npm", + "path", + "prefix", + "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 + } + } +} |