diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/app-root-path | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/app-root-path')
| -rw-r--r-- | node_modules/app-root-path/.npmignore | 6 | ||||
| -rw-r--r-- | node_modules/app-root-path/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/app-root-path/README.md | 143 | ||||
| -rw-r--r-- | node_modules/app-root-path/browser-shim.js | 19 | ||||
| -rw-r--r-- | node_modules/app-root-path/coverage.lcov | 108 | ||||
| -rw-r--r-- | node_modules/app-root-path/index.js | 4 | ||||
| -rw-r--r-- | node_modules/app-root-path/lib/app-root-path.js | 30 | ||||
| -rw-r--r-- | node_modules/app-root-path/lib/resolve.js | 78 | ||||
| -rw-r--r-- | node_modules/app-root-path/package.json | 64 |
9 files changed, 473 insertions, 0 deletions
diff --git a/node_modules/app-root-path/.npmignore b/node_modules/app-root-path/.npmignore new file mode 100644 index 00000000..d2adac50 --- /dev/null +++ b/node_modules/app-root-path/.npmignore @@ -0,0 +1,6 @@ +test/ +coverage/ +.gitignore +.travis.yml +.idea +.nyc_output
\ No newline at end of file diff --git a/node_modules/app-root-path/LICENSE b/node_modules/app-root-path/LICENSE new file mode 100644 index 00000000..788d3c0f --- /dev/null +++ b/node_modules/app-root-path/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Chris Morrell + +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/app-root-path/README.md b/node_modules/app-root-path/README.md new file mode 100644 index 00000000..f99049cb --- /dev/null +++ b/node_modules/app-root-path/README.md @@ -0,0 +1,143 @@ +# App Root Path Module + +[![Build Status][build-status-img]][build-status] [![Dependency Status][david-dm-img]][david-dm] [![Code Coverage Status][codecov-img]][codecov] + +> **Please Note:** Due to the very limited scope of this module, I do not anticipate needing to make very many changes to it. Expect long stretches of zero updates—that does not mean that the module is outdated. + +This simple module helps you access your application's root path from anywhere in the application without resorting to relative paths like `require("../../path")`. + +## Installation + +``` bash +$ npm i -S app-root-path +``` + +## Usage + +To simply access the app's root path, use the module as though it were a string: + +``` js +var appRoot = require('app-root-path'); +var myModule = require(appRoot + '/lib/my-module.js'); +``` + +> _Side note: the module actually returns an object, but that object implements the `toString` method, so you can use it as though it were a string. There are a few edge cases where this might not be the case (most notably `console.log`), but they shouldn't affect actual use of the module, where you're almost always concatenating with an additional string._ + +A helper function is also provided: + +``` js +var reqlib = require('app-root-path').require; +var myModule = reqlib('/lib/my-module.js'); +``` + +It's a little hacky, but you can also put this method on your application's `global` object to use it everywhere in your project: + +``` js +// In app.js +global.reqlib = require('app-root-path').require; + +// In lib/module/component/subcomponent.js +var myModule = reqlib('/lib/my-module.js'); +``` + +Finally, you can also just resolve a module path: + +``` js +var myModulePath = require('app-root-path').resolve('/lib/my-module.js'); +``` + +You can explicitly set the path, using the environmental variable `APP_ROOT_PATH` or by calling `require('app-root-path').setPath('/my/app/is/here')` + +## How It Works (under the hood) + +> No need to read this unless your curious—or you run into a (very unlikely) case where the module does not work as expected. + +This module uses two different methods to determine the app's root path, depending on the circumstances. + +### Primary Method + +If the module is located inside your project's directory, somewhere within the `node_modules` directory (whether directly, or inside a submodule), we effectively do (the actual code takes cross-platform path names/etc into consideration): + +``` js +path.resolve(__dirname).split('/node_modules')[0]; +``` + +This will take a path like `/var/www/node_modules/submodule/node_modules/app-root-path` and return `/var/www`. In nearly all cases, this is just what you need. + +### Secondary Method (for edge cases) + +The node module loader will also look in a few other places for modules (for example, ones that you install globally with `npm install -g`). These can be in one of: + + - `$HOME/.node_modules` + - `$HOME/.node_libraries` + - `$PREFIX/lib/node` + +Or, anywhere in the `NODE_PATH` environmental variable ([see documentation](http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders)). + +In these cases, we fall back to an alternate trick: + +``` js +path.dirname(require.main.filename); +``` + +When a file is run directly from Node, `require.main` is set to that file's `module`. Each module has a `filename` property that refers to the filename of that module, so by fetching the directory name for that file, we at least get the directory of file passed to `node`. In some cases (process managers and test suites, for example) this doesn't actually give the correct directory, though, so this method is only used as a fallback. + +### Edge-Case: Global CLIs + +If your module is installed as a global CLI, for example in `/usr/local/lib/node_modules/yourmodule`, then +`require.main.filename` will report `/usr/local/lib/node_modules/yourmodule/bin`, which is probably not what +you want. `app-root-path` is aware of this edge-case and will strip the `/bin` automatically. + +## Change Log + +### 2.0.1 + - Minor tweaks to how electron-specific logic runs. Should help with packagers that try to resolve all `require()` statements during packaging. + +### 2.0.0 + - Removed official support for node < 4.0 + - Removed support for passing `module.require` to `appRootPath.require` (which has been deprecated for a while) + - Implemented [semantic-release](https://github.com/semantic-release/semantic-release) from here on out + - Added browserify-compatible shim + +### 1.3.0 + - Updated [electron](https://github.com/atom/electron) to match changes in version 1.0 of that project + +### 1.2.1 + - Had to bump package version because 1.2.0 got published to npm as @beta + +### 1.2.0 + - Special logic to resolve correctly when in an [electron](https://github.com/atom/electron) renderer process + +### 1.1.0 + - Special logic to handle an edge case when used in a globally-installed CLI project + - Fixed a bug where `setPath()` did not update `require('app-root-path').path` + - Moved some logic outside of the `resolve()` function so that it's not called multiple times + +### 1.0.0 + - No changes. Just updated the version to signify a locked API (see [semver](http://semver.org/)). + +### 0.1.1 + - Added Windows support (and, theoretically, other operating systems that have a directory separator that's not "/") + +### 0.1.0 + - Completely rewrote the path resolution method to account for most possible scenarios. This shouldn't cause and backwards compatibility issues, but always test your code. + - Removed the need to pass a modules's `require()` method to the `appRootPath.require()` function. Which it's true that each module has its own `require()` method, in practice it doesn't matter, and it's **much** simpler this way. + - Added tests + +## Development Nodes + +When using [semantic-release](https://github.com/semantic-release/semantic-release), the preferred method +for commits is: + + - `git add …` + - `git cz` (see [commitizen](https://github.com/commitizen/cz-cli)) + - `git push` + +This helps ensure that commits match the expected format. Commits to `master` will cause releases. + +[build-status]: https://travis-ci.org/inxilpro/node-app-root-path +[build-status-img]: https://travis-ci.org/inxilpro/node-app-root-path.svg +[david-dm-img]: https://david-dm.org/inxilpro/node-app-root-path.svg +[david-dm]: https://david-dm.org/inxilpro/node-app-root-path +[codecov-img]: https://codecov.io/gh/inxilpro/node-app-root-path/branch/master/graph/badge.svg +[codecov]: https://codecov.io/gh/inxilpro/node-app-root-path
\ No newline at end of file diff --git a/node_modules/app-root-path/browser-shim.js b/node_modules/app-root-path/browser-shim.js new file mode 100644 index 00000000..94348e27 --- /dev/null +++ b/node_modules/app-root-path/browser-shim.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.path = require('path').dirname(require.main.filename); + +exports.resolve = function(pathToModule) { + return exports.path + pathToModule; +}; + +exports.require = function(pathToModule) { + return require(exports.resolve(pathToModule)); +}; + +exports.toString = function() { + return exports.path; +}; + +exports.setPath = function(explicitlySetPath) { + exports.path = explicitlySetPath; +};
\ No newline at end of file diff --git a/node_modules/app-root-path/coverage.lcov b/node_modules/app-root-path/coverage.lcov new file mode 100644 index 00000000..e7f4ed85 --- /dev/null +++ b/node_modules/app-root-path/coverage.lcov @@ -0,0 +1,108 @@ +TN: +SF:/home/travis/build/inxilpro/node-app-root-path/lib/app-root-path.js +FN:3,(anonymous_0) +FN:9,(anonymous_1) +FN:13,(anonymous_2) +FN:17,(anonymous_3) +FN:21,(anonymous_4) +FNF:5 +FNH:5 +FNDA:1,(anonymous_0) +FNDA:3,(anonymous_1) +FNDA:1,(anonymous_2) +FNDA:4,(anonymous_3) +FNDA:2,(anonymous_4) +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:8,1 +DA:10,3 +DA:14,1 +DA:18,4 +DA:22,2 +DA:23,2 +DA:29,1 +LF:11 +LH:11 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/home/travis/build/inxilpro/node-app-root-path/lib/resolve.js +FN:22,resolve +FN:48,(anonymous_1) +FNF:2 +FNH:2 +FNDA:16,resolve +FNDA:39,(anonymous_1) +DA:4,1 +DA:7,1 +DA:11,1 +DA:12,0 +DA:14,1 +DA:16,1 +DA:19,1 +DA:22,1 +DA:24,16 +DA:25,1 +DA:29,15 +DA:30,1 +DA:31,1 +DA:32,1 +DA:36,14 +DA:37,1 +DA:40,13 +DA:41,13 +DA:42,13 +DA:48,13 +DA:49,39 +DA:50,4 +DA:56,13 +DA:57,13 +DA:58,7 +DA:59,7 +DA:60,7 +DA:61,7 +DA:67,13 +DA:68,6 +DA:72,13 +DA:73,1 +DA:77,13 +LF:33 +LH:32 +BRDA:11,0,0,0 +BRDA:11,0,1,1 +BRDA:24,1,0,1 +BRDA:24,1,1,15 +BRDA:29,2,0,1 +BRDA:29,2,1,14 +BRDA:29,3,0,15 +BRDA:29,3,1,1 +BRDA:29,3,2,1 +BRDA:36,4,0,1 +BRDA:36,4,1,13 +BRDA:36,5,0,14 +BRDA:36,5,1,1 +BRDA:49,6,0,4 +BRDA:49,6,1,35 +BRDA:49,7,0,39 +BRDA:49,7,1,36 +BRDA:57,8,0,7 +BRDA:57,8,1,6 +BRDA:57,9,0,13 +BRDA:57,9,1,9 +BRDA:59,10,0,7 +BRDA:59,10,1,0 +BRDA:67,11,0,6 +BRDA:67,11,1,7 +BRDA:67,12,0,13 +BRDA:67,12,1,9 +BRDA:72,13,0,1 +BRDA:72,13,1,12 +BRDA:72,14,0,13 +BRDA:72,14,1,4 +BRDA:72,14,2,1 +BRF:32 +BRH:30 +end_of_record diff --git a/node_modules/app-root-path/index.js b/node_modules/app-root-path/index.js new file mode 100644 index 00000000..7fd5bde5 --- /dev/null +++ b/node_modules/app-root-path/index.js @@ -0,0 +1,4 @@ +'use strict'; + +var lib = require('./lib/app-root-path.js'); +module.exports = lib(__dirname);
\ No newline at end of file diff --git a/node_modules/app-root-path/lib/app-root-path.js b/node_modules/app-root-path/lib/app-root-path.js new file mode 100644 index 00000000..03596e55 --- /dev/null +++ b/node_modules/app-root-path/lib/app-root-path.js @@ -0,0 +1,30 @@ +'use strict'; + +module.exports = function(dirname) { + var path = require('path'); + var resolve = require('./resolve.js'); + var appRootPath = resolve(dirname); + + var publicInterface = { + resolve: function(pathToModule) { + return path.join(appRootPath, pathToModule); + }, + + require: function(pathToModule) { + return require(publicInterface.resolve(pathToModule)); + }, + + toString: function() { + return appRootPath; + }, + + setPath: function(explicitlySetPath) { + appRootPath = path.resolve(explicitlySetPath); + publicInterface.path = appRootPath; + }, + + path: appRootPath + }; + + return publicInterface; +};
\ No newline at end of file diff --git a/node_modules/app-root-path/lib/resolve.js b/node_modules/app-root-path/lib/resolve.js new file mode 100644 index 00000000..0acc918d --- /dev/null +++ b/node_modules/app-root-path/lib/resolve.js @@ -0,0 +1,78 @@ +'use strict'; + +// Dependencies +var path = require('path'); + +// Load global paths +var globalPaths = require('module').globalPaths; + +// Guess at NPM's global install dir +var npmGlobalPrefix; +if ('win32' === process.platform) { + npmGlobalPrefix = path.dirname(process.execPath); +} else { + npmGlobalPrefix = path.dirname(path.dirname(process.execPath)); +} +var npmGlobalModuleDir = path.resolve(npmGlobalPrefix, 'lib', 'node_modules'); + +// Save OS-specific path separator +var sep = path.sep; + +// Resolver +module.exports = function resolve(dirname) { + // Check for environmental variable + if (process.env.APP_ROOT_PATH) { + return path.resolve(process.env.APP_ROOT_PATH); + } + + // Defer to main process in electron renderer + if ('undefined' !== typeof window && window.process && 'renderer' === window.process.type) { + var electron = 'electron'; + var remote = require(electron).remote; + return remote.require('app-root-path').path; + } + + // Defer to AWS Lambda when executing there + if (process.env.LAMBDA_TASK_ROOT && process.env.AWS_EXECUTION_ENV) { + return process.env.LAMBDA_TASK_ROOT; + } + + var resolved = path.resolve(dirname); + var alternateMethod = false; + var appRootPath = null; + + // Make sure that we're not loaded from a global include path + // Eg. $HOME/.node_modules + // $HOME/.node_libraries + // $PREFIX/lib/node + globalPaths.forEach(function(globalPath) { + if (!alternateMethod && 0 === resolved.indexOf(globalPath)) { + alternateMethod = true; + } + }); + + // If the app-root-path library isn't loaded globally, + // and node_modules exists in the path, just split __dirname + var nodeModulesDir = sep + 'node_modules'; + if (!alternateMethod && -1 !== resolved.indexOf(nodeModulesDir)) { + var parts = resolved.split(nodeModulesDir); + if (parts.length) { + appRootPath = parts[0]; + parts = null; + } + } + + // If the above didn't work, or this module is loaded globally, then + // resort to require.main.filename (See http://nodejs.org/api/modules.html) + if (alternateMethod || null == appRootPath) { + appRootPath = path.dirname(require.main.filename); + } + + // Handle global bin/ directory edge-case + if (alternateMethod && -1 !== appRootPath.indexOf(npmGlobalModuleDir) && (appRootPath.length - 4) === appRootPath.indexOf(sep + 'bin')) { + appRootPath = appRootPath.slice(0, -4); + } + + // Return + return appRootPath; +}; diff --git a/node_modules/app-root-path/package.json b/node_modules/app-root-path/package.json new file mode 100644 index 00000000..e0a99f65 --- /dev/null +++ b/node_modules/app-root-path/package.json @@ -0,0 +1,64 @@ +{ + "name": "app-root-path", + "version": "2.1.0", + "description": "Determine an app's root path from anywhere inside the app", + "main": "index.js", + "browser": "browser-shim.js", + "scripts": { + "test": "nyc mocha -R spec", + "report-coverage": "npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov", + "release": "semantic-release pre && npm publish && semantic-release post" + }, + "repository": { + "type": "git", + "url": "https://github.com/inxilpro/node-app-root-path.git" + }, + "keywords": [ + "root", + "path", + "utility", + "util", + "node", + "module", + "modules", + "node_modules", + "require", + "app" + ], + "author": "Chris Morrell <http://cmorrell.com>", + "license": "MIT", + "bugs": { + "url": "https://github.com/inxilpro/node-app-root-path/issues" + }, + "homepage": "https://github.com/inxilpro/node-app-root-path", + "devDependencies": { + "codecov": "^1.0.1", + "coveralls": "^2.11.2", + "cracks": "^3.1.2", + "cz-conventional-changelog": "^1.2.0", + "ghooks": "^1.3.2", + "istanbul": "^0.3.4", + "mocha": "^2.0.1", + "mocha-lcov-reporter": "0.0.1", + "mockery": "^1.7.0", + "nyc": "^8.1.0", + "semantic-release": "^4.3.5", + "validate-commit-msg": "^2.8.0" + }, + "engines": { + "node": ">= 4.0.0" + }, + "release": { + "branch": "master" + }, + "config": { + "ghooks": { + "commit-msg": "validate-commit-msg", + "post-merge": "npm install", + "post-rewrite": "npm install" + }, + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } +}
\ No newline at end of file |
