diff options
author | Kent C. Dodds <kent@doddsfamily.us> | 2015-09-11 10:13:06 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-10-09 02:24:34 +0300 |
commit | 22a3af055f934f8de20ebd5f4a286447dda84f81 (patch) | |
tree | b659c9d623892f84da6d5b0115a163ac5692ad3f /node_modules | |
parent | 4a974404f2172750bf594dc0007b5fe78854cb89 (diff) |
lifecycle: Swap out custom logic with add-to-path module
PR-URL: https://github.com/npm/npm/pull/9553
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/add-to-path/.eslintignore | 5 | ||||
-rw-r--r-- | node_modules/add-to-path/.npmignore | 12 | ||||
-rw-r--r-- | node_modules/add-to-path/CODE_OF_CONDUCT.md | 15 | ||||
-rw-r--r-- | node_modules/add-to-path/LICENSE | 19 | ||||
-rw-r--r-- | node_modules/add-to-path/README.md | 45 | ||||
-rw-r--r-- | node_modules/add-to-path/dist/get-path-var.js | 20 | ||||
-rw-r--r-- | node_modules/add-to-path/dist/index.js | 54 | ||||
-rw-r--r-- | node_modules/add-to-path/package.json | 110 | ||||
-rw-r--r-- | node_modules/add-to-path/src/get-path-var.js | 18 | ||||
-rw-r--r-- | node_modules/add-to-path/src/get-path-var.test.js | 22 | ||||
-rw-r--r-- | node_modules/add-to-path/src/index.js | 51 | ||||
-rw-r--r-- | node_modules/add-to-path/src/index.test.js | 83 |
12 files changed, 454 insertions, 0 deletions
diff --git a/node_modules/add-to-path/.eslintignore b/node_modules/add-to-path/.eslintignore new file mode 100644 index 000000000..a2b41c8fa --- /dev/null +++ b/node_modules/add-to-path/.eslintignore @@ -0,0 +1,5 @@ +node_modules +coverage +dist +local-examples +other diff --git a/node_modules/add-to-path/.npmignore b/node_modules/add-to-path/.npmignore new file mode 100644 index 000000000..78b0f2067 --- /dev/null +++ b/node_modules/add-to-path/.npmignore @@ -0,0 +1,12 @@ +.idea +node_modules +coverage +local-examples +demo +.editorconfig +.gitignore +.travis.yml +CONTRIBUTING.md +karma.conf.js +webpack.config.js +other diff --git a/node_modules/add-to-path/CODE_OF_CONDUCT.md b/node_modules/add-to-path/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..c2ebaabcf --- /dev/null +++ b/node_modules/add-to-path/CODE_OF_CONDUCT.md @@ -0,0 +1,15 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.1.0, available at [http://contributor-covenant.org/version/1/1/0/](http://contributor-covenant.org/version/1/1/0/) diff --git a/node_modules/add-to-path/LICENSE b/node_modules/add-to-path/LICENSE new file mode 100644 index 000000000..d13cc4b26 --- /dev/null +++ b/node_modules/add-to-path/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) + +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/add-to-path/README.md b/node_modules/add-to-path/README.md new file mode 100644 index 000000000..f568ab5ec --- /dev/null +++ b/node_modules/add-to-path/README.md @@ -0,0 +1,45 @@ +# add-to-path + +Status: +[![npm version](https://img.shields.io/npm/v/add-to-path.svg?style=flat-square)](https://www.npmjs.org/package/add-to-path) +[![npm downloads](https://img.shields.io/npm/dm/add-to-path.svg?style=flat-square)](http://npm-stat.com/charts.html?package=add-to-path&from=2015-09-01) +[![Build Status](https://img.shields.io/travis/kentcdodds/node-add-to-path.svg?style=flat-square)](https://travis-ci.org/kentcdodds/node-add-to-path) +[![Code Coverage](https://img.shields.io/codecov/c/github/kentcdodds/node-add-to-path.svg?style=flat-square)](https://codecov.io/github/kentcdodds/node-add-to-path) + +This micro-lib allows you to alter the `$PATH` in a cross-platform way. + +## Main Usage + +```javascript +var path = require('path'); +var addToPath = require('add-to-path'); +var restorePath = addToPath(path.join(process.cwd(), 'node_modules', '.bin')); +// process.env.PATH now starts with the `.bin` in your `node_modules` directory :-) +// unless you happen to be running on windows, in which case it *might* be process.env.Path :-) +// but you don't have to think about that... +// want to restore the path to what it was before you mucked with it? +// just call the function you get back: +restorePath(); + +// wanna add several paths at once? Done! +addToPath(['/foo/bar/.bin', '/bar/foo/.bin']); +``` + + +## options + +### platform + +Allows you to specify your own platform. Defaults to `process.platform`. Currently the only meaningful value is +`'win32'`. This option is mainly available for testing purposes. + +### append + +Defaults to `undefined`, but when set to `true` will add the directory you pass to the end (rather than the beginning). + +# Other info + +LICENSE -> MIT + +Much of the original code for this came from [npm/npm](https://github.com/npm/npm) + diff --git a/node_modules/add-to-path/dist/get-path-var.js b/node_modules/add-to-path/dist/get-path-var.js new file mode 100644 index 000000000..3694f3f7c --- /dev/null +++ b/node_modules/add-to-path/dist/get-path-var.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = getPathVar; + +function getPathVar(platform) { + var PATH = 'PATH'; + platform = platform || process.platform; + + if (platform === 'win32') { + PATH = 'Path'; + Object.keys(process.env).some(function (e) { + var matches = e.match(/^PATH$/i); + if (matches) { + PATH = e; + } + return matches; + }); + } + return PATH; +}
\ No newline at end of file diff --git a/node_modules/add-to-path/dist/index.js b/node_modules/add-to-path/dist/index.js new file mode 100644 index 000000000..50340681f --- /dev/null +++ b/node_modules/add-to-path/dist/index.js @@ -0,0 +1,54 @@ +'use strict'; + +var getPathVar = require('./get-path-var'); +var env = process.env; +module.exports = addToPath; + +function addToPath(pathToAdd, options) { + var platform, PATH, originalPath, pathArray; + if (!isNonEmptyString(pathToAdd)) { + throw new Error('path-to-add error: Must pass a non-empty string. You passed: ' + pathToAdd); + } + options = options || {}; + platform = options.platform || process.platform; + PATH = getPathVar(platform); + + originalPath = env[PATH]; + pathArray = getPathArray(pathToAdd); + + addExistingPath(pathArray, env[PATH], options.append); + + env[PATH] = pathArray.join(platform === 'win32' ? ';' : ':'); + + return function restorePath() { + env[PATH] = originalPath; + }; +} + +function getPathArray(pathToAdd) { + if (Array.isArray(pathToAdd)) { + return pathToAdd; + } else { + return [pathToAdd]; + } +} + +function addExistingPath(array, path, appendMode) { + if (!path) { + return; + } + if (appendMode) { + array.unshift(path); + } else { + array.push(path); + } +} + +function isNonEmptyString(arg, noArrays) { + if (!noArrays && Array.isArray(arg)) { + return arg.every(function (a) { + return isNonEmptyString(a, true); + }); + } + return typeof arg === 'string' && arg.length > 0; +}
\ No newline at end of file diff --git a/node_modules/add-to-path/package.json b/node_modules/add-to-path/package.json new file mode 100644 index 000000000..da0208d8e --- /dev/null +++ b/node_modules/add-to-path/package.json @@ -0,0 +1,110 @@ +{ + "_args": [ + [ + "add-to-path@~1.1.2", + "/Users/rebecca/code/npm" + ] + ], + "_from": "add-to-path@>=1.1.2 <1.2.0", + "_id": "add-to-path@1.1.2", + "_inCache": true, + "_location": "/add-to-path", + "_nodeVersion": "4.0.0", + "_npmUser": { + "email": "kent@doddsfamily.us", + "name": "kentcdodds" + }, + "_npmVersion": "2.14.6", + "_phantomChildren": {}, + "_requested": { + "name": "add-to-path", + "raw": "add-to-path@~1.1.2", + "rawSpec": "~1.1.2", + "scope": null, + "spec": ">=1.1.2 <1.2.0", + "type": "range" + }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/add-to-path/-/add-to-path-1.1.2.tgz", + "_shasum": "fe3dc73daa309c9fb93c4a6a336e7f69f4c68afc", + "_shrinkwrap": null, + "_spec": "add-to-path@~1.1.2", + "_where": "/Users/rebecca/code/npm", + "author": { + "email": "kent@doddsfamily.us", + "name": "Kent C. Dodds", + "url": "http://kentcdodds.com/" + }, + "bugs": { + "url": "https://github.com/kentcdodds/node-add-to-path/issues" + }, + "config": { + "ghooks": { + "commit-msg": "./node_modules/.bin/validate-commit-msg && npm run eslint && npm t && npm run check-coverage && echo 'pre-commit checks good 👍'" + } + }, + "czConfig": { + "path": "node_modules/cz-conventional-changelog/" + }, + "dependencies": {}, + "description": "Cross-platform method to add a directory to your $PATH", + "devDependencies": { + "babel": "5.8.23", + "chai": "3.2.0", + "chai-string": "1.1.2", + "codecov.io": "0.1.6", + "commitizen": "1.0.4", + "cz-conventional-changelog": "1.1.0", + "eslint": "1.3.1", + "eslint-config-kentcdodds": "4.0.0", + "eslint-plugin-mocha": "0.5.1", + "ghooks": "0.3.2", + "istanbul": "0.3.19", + "mocha": "2.3.2", + "publish-latest": "1.0.2", + "semantic-release": "^4.3.4", + "validate-commit-msg": "1.0.0" + }, + "directories": {}, + "dist": { + "shasum": "fe3dc73daa309c9fb93c4a6a336e7f69f4c68afc", + "tarball": "http://registry.npmjs.org/add-to-path/-/add-to-path-1.1.2.tgz" + }, + "gitHead": "8506cb6733d5595c53fbebaadefcc1c361d8d3d6", + "homepage": "https://github.com/kentcdodds/node-add-to-path#readme", + "installable": true, + "keywords": [ + "cross-platform", + "path" + ], + "license": "MIT", + "main": "dist/index.js", + "maintainers": [ + { + "name": "kentcdodds", + "email": "kent@doddsfamily.us" + } + ], + "name": "add-to-path", + "optionalDependencies": {}, + "repository": { + "type": "git", + "url": "git+https://github.com/kentcdodds/node-add-to-path.git" + }, + "scripts": { + "build": "cd src && babel index.js get-path-var.js -d ../dist && cd ..", + "check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100", + "commit": "git-cz", + "eslint": "eslint src/index.js src/get-path-var.js -c other/src.eslintrc && eslint src/*.test.js", + "postpublish": "publish-latest", + "prebuild": "rm -rf dist && mkdir dist", + "prepublish": "npm run build", + "report-coverage": "echo 'Reporting coverage stats' && cat ./coverage/lcov.info | codecov", + "semantic-release": "semantic-release pre && npm publish && semantic-release post", + "start": "mocha src/*.test.js -w . --compilers js:babel/register", + "test": "istanbul cover -x *.test.js _mocha -- -R spec src/*.test.js --compilers js:babel/register" + }, + "version": "1.1.2" +} diff --git a/node_modules/add-to-path/src/get-path-var.js b/node_modules/add-to-path/src/get-path-var.js new file mode 100644 index 000000000..aba0b9938 --- /dev/null +++ b/node_modules/add-to-path/src/get-path-var.js @@ -0,0 +1,18 @@ +module.exports = getPathVar; + +function getPathVar(platform) { + var PATH = 'PATH'; + platform = platform || process.platform; + + if (platform === 'win32') { + PATH = 'Path'; + Object.keys(process.env).some(e => { + var matches = e.match(/^PATH$/i); + if (matches) { + PATH = e; + } + return matches; + }); + } + return PATH; +} diff --git a/node_modules/add-to-path/src/get-path-var.test.js b/node_modules/add-to-path/src/get-path-var.test.js new file mode 100644 index 000000000..8bad0e7cc --- /dev/null +++ b/node_modules/add-to-path/src/get-path-var.test.js @@ -0,0 +1,22 @@ +import {expect} from 'chai'; +import getPathVar from './get-path-var'; + +describe('get-path-var', () => { + it('should provide me with PATH when the platform is not `win32`', () => { + expect(getPathVar('darwin')).to.equal('PATH'); + }); + + describe('`win32` platform', () => { + it('should provide me with Path if process.env does not contain PATH', () => { + const originalPath = process.env.PATH; + delete process.env.PATH; + expect(getPathVar('win32')).to.equal('Path'); + process.env.PATH = originalPath; + }); + + it('should provide me with PATH when process.env contains PATH', () => { + expect(getPathVar('win32')).to.equal('PATH'); + }); + }); +}); + diff --git a/node_modules/add-to-path/src/index.js b/node_modules/add-to-path/src/index.js new file mode 100644 index 000000000..0f3941d76 --- /dev/null +++ b/node_modules/add-to-path/src/index.js @@ -0,0 +1,51 @@ +var getPathVar = require('./get-path-var'); +var env = process.env; +module.exports = addToPath; + +function addToPath(pathToAdd, options) { + var platform, PATH, originalPath, pathArray; + if (!isNonEmptyString(pathToAdd)) { + throw new Error('path-to-add error: Must pass a non-empty string. You passed: ' + pathToAdd); + } + options = options || {}; + platform = options.platform || process.platform; + PATH = getPathVar(platform); + + originalPath = env[PATH]; + pathArray = getPathArray(pathToAdd); + + addExistingPath(pathArray, env[PATH], options.append); + + env[PATH] = pathArray.join(platform === 'win32' ? ';' : ':'); + + return function restorePath() { + env[PATH] = originalPath; + }; +} + +function getPathArray(pathToAdd) { + if (Array.isArray(pathToAdd)) { + return pathToAdd; + } else { + return [pathToAdd]; + } +} + +function addExistingPath(array, path, appendMode) { + if (!path) { + return; + } + if (appendMode) { + array.unshift(path); + } else { + array.push(path); + } +} + +function isNonEmptyString(arg, noArrays) { + if (!noArrays && Array.isArray(arg)) { + return arg.every(a => isNonEmptyString(a, true)); + } + return typeof arg === 'string' && arg.length > 0; +} + diff --git a/node_modules/add-to-path/src/index.test.js b/node_modules/add-to-path/src/index.test.js new file mode 100644 index 000000000..592807913 --- /dev/null +++ b/node_modules/add-to-path/src/index.test.js @@ -0,0 +1,83 @@ +import chai from 'chai'; +import addToPath from './index'; +import getPathVar from './get-path-var'; + +const expect = chai.expect; +const PATH = getPathVar(); +const env = process.env; + +chai.use(require('chai-string')); + +describe('add-to-path', () => { + let originalPath; + const pathToAdd = '/foo/bar/.bin'; + + beforeEach(() => { + originalPath = env[PATH]; + }); + + describe('platform independent', () => { + it('should throw an error when passed a non-string', () => { + expect(() => { + addToPath(); + }).to.throw(/must pass a non-empty string/ig); + }); + + it('should throw an error when passed an empty string', () => { + expect(() => { + addToPath(2); + }).to.throw(/must pass a non-empty string/ig); + }); + + it('should return a function to restore the path', () => { + const restorePath = addToPath(pathToAdd); + expect(env[PATH]).to.startWith(pathToAdd); + restorePath(); + expect(env[PATH]).to.not.contain(pathToAdd); + }); + + it('should handle the case where there is no pre-existing path', () => { + delete env[PATH]; + addToPath(pathToAdd); + expect(env[PATH]).to.equal(pathToAdd); + }); + + it('should handle an array of strings', () => { + const platform = 'darwin'; + const separator = ':'; + const paths = [pathToAdd, '/bar/foo/.bin']; + addToPath(paths, {platform}); + expect(env[PATH]).to.startWith(paths.join(separator)); + }); + + it('should allow you to append to the path', () => { + addToPath(pathToAdd, {append: true}); + expect(env[PATH]).to.endWith(pathToAdd); + }); + }); + + describe('on darwin platform', () => { + const platform = 'darwin'; + const separator = ':'; + + it('should alter the path to add what is provided', () => { + expect(addToPath(pathToAdd, {platform})); + expect(env[PATH]).to.startWith(pathToAdd + separator); + }); + }); + + describe('on win32 platform', () => { + const platform = 'win32'; + const separator = ';'; + + it('should alter the path to add what is provided', () => { + expect(addToPath(pathToAdd, {platform})); + expect(env[PATH]).to.startWith(pathToAdd + separator); + }); + }); + + afterEach(() => { + env[PATH] = originalPath; + }); +}); + |