diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-12-07 14:05:23 -0800 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-01-19 11:32:08 -0500 |
commit | d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5 (patch) | |
tree | 321928c015be00cdbe11715297d2d2fc45802263 /deps/npm/node_modules/find-npm-prefix | |
parent | bfe41fe88e7421f441067a79fb7512cf5935a2bb (diff) | |
download | android-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.tar.gz android-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.tar.bz2 android-node-v8-d3b1c971bcf0177b17c649c3aeca1a94cbc3fff5.zip |
deps: upgrade npm to 5.6.0
PR-URL: https://github.com/nodejs/node/pull/17777
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/find-npm-prefix')
-rw-r--r-- | deps/npm/node_modules/find-npm-prefix/LICENSE | 15 | ||||
-rw-r--r-- | deps/npm/node_modules/find-npm-prefix/README.md | 28 | ||||
-rw-r--r-- | deps/npm/node_modules/find-npm-prefix/find-prefix.js | 54 | ||||
-rw-r--r-- | deps/npm/node_modules/find-npm-prefix/package.json | 59 | ||||
-rw-r--r-- | deps/npm/node_modules/find-npm-prefix/test/find-prefix.js | 79 |
5 files changed, 235 insertions, 0 deletions
diff --git a/deps/npm/node_modules/find-npm-prefix/LICENSE b/deps/npm/node_modules/find-npm-prefix/LICENSE new file mode 100644 index 0000000000..7953647e77 --- /dev/null +++ b/deps/npm/node_modules/find-npm-prefix/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright npm, Inc + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/deps/npm/node_modules/find-npm-prefix/README.md b/deps/npm/node_modules/find-npm-prefix/README.md new file mode 100644 index 0000000000..77bf4b7242 --- /dev/null +++ b/deps/npm/node_modules/find-npm-prefix/README.md @@ -0,0 +1,28 @@ +# find-npm-prefix + +Find the npm project directory associated with for a given directory + +## USAGE + +``` +const findPrefix = require('find-npm-prefix') + +findPrefix(process.cwd).then(prefix => { + … +}) +``` + +## findPrefix(dir) → Promise(prefix) + +This computes the npm prefix, that is, the directory that npm adds and +removes modules from for a given path. + +It takes a directory as an argument and returns a promise of the associated +prefix directory. + +## Algorithm + +1. If the directory is a `node_modules` folder, scan up the tree till you find a non-`node_modules` directory and return that. +2. Else, look for the first parent directory that contains a `node_modules` or a `package.json` + 1. If one is found, that's the prefix. + 2. If none are found, return the original directory we were given diff --git a/deps/npm/node_modules/find-npm-prefix/find-prefix.js b/deps/npm/node_modules/find-npm-prefix/find-prefix.js new file mode 100644 index 0000000000..089572ec11 --- /dev/null +++ b/deps/npm/node_modules/find-npm-prefix/find-prefix.js @@ -0,0 +1,54 @@ +'use strict' +// try to find the most reasonable prefix to use + +module.exports = findPrefix + +const fs = require('fs') +const path = require('path') +const Bluebird = require('bluebird') +const readdir = Bluebird.promisify(fs.readdir) + +function findPrefix (dir) { + return Bluebird.try(() => { + dir = path.resolve(dir) + + // this is a weird special case where an infinite recurse of + // node_modules folders resolves to the level that contains the + // very first node_modules folder + let walkedUp = false + while (path.basename(dir) === 'node_modules') { + dir = path.dirname(dir) + walkedUp = true + } + if (walkedUp) return dir + + return findPrefix_(dir) + }) +} + +function findPrefix_ (dir, original) { + if (!original) original = dir + + const parent = path.dirname(dir) + // this is a platform independent way of checking if we're in the root + // directory + if (parent === dir) return original + + return readdir(dir).then(files => { + if (files.indexOf('node_modules') !== -1 || + files.indexOf('package.json') !== -1) { + return dir + } + + return findPrefix_(parent, original) + }, er => { + // an error right away is a bad sign. + // unless the prefix was simply a non + // existent directory. + if (er && dir === original && er.code !== 'ENOENT') { + throw er + } else { + return original + } + }) +} diff --git a/deps/npm/node_modules/find-npm-prefix/package.json b/deps/npm/node_modules/find-npm-prefix/package.json new file mode 100644 index 0000000000..4007b90c3c --- /dev/null +++ b/deps/npm/node_modules/find-npm-prefix/package.json @@ -0,0 +1,59 @@ +{ + "_from": "find-npm-prefix@latest", + "_id": "find-npm-prefix@1.0.1", + "_inBundle": false, + "_integrity": "sha512-I9R7ZnsjlKRvXBJjA1PE4wAkSc24YChoomWdEPTZgeB4DHxf87OutNGV5McFj6WwPghH97nZRejH58XvY6ga6Q==", + "_location": "/find-npm-prefix", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "find-npm-prefix@latest", + "name": "find-npm-prefix", + "escapedName": "find-npm-prefix", + "rawSpec": "latest", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/find-npm-prefix/-/find-npm-prefix-1.0.1.tgz", + "_shasum": "af0faa74e19294b3c8634bae0e91017bb5adfac2", + "_spec": "find-npm-prefix@latest", + "_where": "/Users/rebecca/code/npm", + "author": { + "name": "Rebecca Turner", + "email": "me@re-becca.org", + "url": "http://re-becca.org/" + }, + "bugs": { + "url": "https://github.com/npm/find-npm-prefix/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Find the npm project directory associated with for a given directory", + "devDependencies": { + "require-inject": "^1.4.2", + "standard": "^10.0.3", + "tap": "^10.7.3" + }, + "directories": { + "test": "test" + }, + "homepage": "https://github.com/npm/find-npm-prefix#readme", + "keywords": [], + "license": "ISC", + "main": "find-prefix.js", + "name": "find-npm-prefix", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/find-npm-prefix.git" + }, + "scripts": { + "test": "standard && tap --100 test" + }, + "version": "1.0.1" +} diff --git a/deps/npm/node_modules/find-npm-prefix/test/find-prefix.js b/deps/npm/node_modules/find-npm-prefix/test/find-prefix.js new file mode 100644 index 0000000000..de2ab41cb9 --- /dev/null +++ b/deps/npm/node_modules/find-npm-prefix/test/find-prefix.js @@ -0,0 +1,79 @@ +'use strict' +const Bluebird = require('bluebird') +const test = require('tap').test +const requireInject = require('require-inject') +const findPrefix = requireInject('../find-prefix.js', { + fs: { + readdir: mockReaddir + } +}) + +test('find-prefix', t => { + const tests = { + '/Users/example/code/test1/node_modules': '/Users/example/code/test1', + '/Users/example/code/test1/node_modules/node_modules': '/Users/example/code/test1', + '/Users/example/code/test1/sub1': '/Users/example/code/test1', + '/Users/example/code/test1/sub1/sub1a': '/Users/example/code/test1', + '/Users/example/code/test2': '/Users/example/code/test2', + '/Users/example/code/test2/sub2': '/Users/example/code/test2', + '/Users/example/code': '/Users/example/code', + '/Users/example': '/Users/example', + '/does/not/exist': '/does/not/exist' + } + t.plan(Object.keys(tests).length) + return Bluebird.map(Object.keys(tests), dir => { + return findPrefix(dir).then(pre => { + t.is(pre, tests[dir], dir) + }) + }) +}) + +test('fail-prefix', t => { + return findPrefix('/Users/example/eperm').then(pre => { + t.fail('no eperm') + }).catch(err => { + t.is(err.code, 'EPERM', 'got perm error') + }) +}) + +const fixture = { + 'Users': { + 'example': { + 'code': { + 'test1': { + 'node_modules': { + 'node_modules': {} + }, + 'sub1': { + 'sub1a': {} + } + }, + 'test2': { + 'package.json': {}, + 'sub2': {} + } + } + } + } +} + +function mockReaddir (dir, cb) { + if (/eperm/.test(dir)) { + const err = new Error('Can not read: ' + dir) + err.code = 'EPERM' + return cb(err) + } + const parts = dir.split(/\//).slice(1) + let cwd = fixture + let part + while ((part = parts.shift())) { + if (part in cwd) { + cwd = cwd[part] + } else { + const err = new Error('Does not exist: ' + dir + ' * ' + part) + err.code = 'ENOENT' + return cb(err) + } + } + return cb(null, Object.keys(cwd)) +} |