diff options
author | Rebecca Turner <turner@mikomi.org> | 2014-09-30 00:11:02 +0400 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:26:36 +0300 |
commit | 9ada7beefc1e1b166395494cd242398424451e55 (patch) | |
tree | b9b0de33d13112350310b2fb9805ffe8e0ce2017 /node_modules/readdir-scoped-modules | |
parent | 7e5da238ee869201fdb9027c27b79b0f76b440a8 (diff) |
read-package-tree@4.1.0
Diffstat (limited to 'node_modules/readdir-scoped-modules')
13 files changed, 178 insertions, 0 deletions
diff --git a/node_modules/readdir-scoped-modules/LICENSE b/node_modules/readdir-scoped-modules/LICENSE new file mode 100644 index 000000000..19129e315 --- /dev/null +++ b/node_modules/readdir-scoped-modules/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) Isaac Z. Schlueter and Contributors + +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/node_modules/readdir-scoped-modules/README.md b/node_modules/readdir-scoped-modules/README.md new file mode 100644 index 000000000..ade57a186 --- /dev/null +++ b/node_modules/readdir-scoped-modules/README.md @@ -0,0 +1,17 @@ +# readdir-scoped-modules + +Like `fs.readdir` but handling `@org/module` dirs as if they were +a single entry. + +Used by npm. + +## USAGE + +```javascript +var readdir = require('readdir-scoped-modules') + +readdir('node_modules', function (er, entries) { + // entries will be something like + // ['a', '@org/foo', '@org/bar'] +}) +``` diff --git a/node_modules/readdir-scoped-modules/package.json b/node_modules/readdir-scoped-modules/package.json new file mode 100644 index 000000000..2fd6aa95b --- /dev/null +++ b/node_modules/readdir-scoped-modules/package.json @@ -0,0 +1,61 @@ +{ + "name": "readdir-scoped-modules", + "version": "1.0.1", + "description": "Like `fs.readdir` but handling `@org/module` dirs as if they were a single entry.", + "main": "readdir.js", + "directories": { + "test": "test" + }, + "dependencies": { + "debuglog": "^1.0.1", + "dezalgo": "^1.0.0", + "graceful-fs": "^3.0.4", + "once": "^1.3.0" + }, + "devDependencies": { + "tap": "0.4" + }, + "scripts": { + "test": "tap test/*.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/readdir-scoped-modules.git" + }, + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "license": "ISC", + "bugs": { + "url": "https://github.com/npm/readdir-scoped-modules/issues" + }, + "homepage": "https://github.com/npm/readdir-scoped-modules", + "gitHead": "451d38946c5b6b6c0db33a890f33536a11ed79f7", + "_id": "readdir-scoped-modules@1.0.1", + "_shasum": "5c2a77f3e08250a8fddf53fa58cdc17900b808b9", + "_from": "readdir-scoped-modules@1.0.1", + "_npmVersion": "2.1.9", + "_nodeVersion": "0.10.33", + "_npmUser": { + "name": "othiym23", + "email": "ogd@aoaioxxysz.net" + }, + "maintainers": [ + { + "name": "isaacs", + "email": "i@izs.me" + }, + { + "name": "othiym23", + "email": "ogd@aoaioxxysz.net" + } + ], + "dist": { + "shasum": "5c2a77f3e08250a8fddf53fa58cdc17900b808b9", + "tarball": "http://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.0.1.tgz" + }, + "_resolved": "https://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.0.1.tgz", + "readme": "ERROR: No README data found!" +} diff --git a/node_modules/readdir-scoped-modules/readdir.js b/node_modules/readdir-scoped-modules/readdir.js new file mode 100644 index 000000000..efbe5526d --- /dev/null +++ b/node_modules/readdir-scoped-modules/readdir.js @@ -0,0 +1,71 @@ +var fs = require ('graceful-fs') +var dz = require ('dezalgo') +var once = require ('once') +var path = require ('path') +var debug = require ('debuglog') ('rds') + +module . exports = readdir + +function readdir (dir, cb) { + fs . readdir (dir, function (er, kids) { + if (er) + return cb (er) + + debug ('dir=%j, kids=%j', dir, kids) + readScopes (dir, kids, function (er, data) { + if (er) + return cb (er) + + // Sort for bonus consistency points + data = data . sort (function (a, b) { + return a > b ? 1 : -1 + }) + + return cb (null, data) + }) + }) +} + +// Turn [ 'a', '@scope' ] into +// ['a', '@scope/foo', '@scope/bar'] +function readScopes (root, kids, cb) { + var scopes = kids . filter (function (kid) { + return kid . charAt (0) === '@' + }) + + kids = kids . filter (function (kid) { + return kid . charAt (0) !== '@' + }) + + debug ('scopes=%j', scopes) + + if (scopes . length === 0) + dz (cb) (null, kids) // prevent maybe-sync zalgo release + + cb = once (cb) + var l = scopes . length + scopes . forEach (function (scope) { + var scopedir = path . resolve (root, scope) + debug ('root=%j scope=%j scopedir=%j', root, scope, scopedir) + fs . readdir (scopedir, then . bind (null, scope)) + }) + + function then (scope, er, scopekids) { + if (er) + return cb (er) + + // XXX: Not sure how old this node bug is. Maybe superstition? + scopekids = scopekids . filter (function (scopekid) { + return !(scopekid === '.' || scopekid === '..' || !scopekid) + }) + + kids . push . apply (kids, scopekids . map (function (scopekid) { + return scope + '/' + scopekid + })) + + debug ('scope=%j scopekids=%j kids=%j', scope, scopekids, kids) + + if (--l === 0) + cb (null, kids) + } +} diff --git a/node_modules/readdir-scoped-modules/test/basic.js b/node_modules/readdir-scoped-modules/test/basic.js new file mode 100644 index 000000000..715c40d58 --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/basic.js @@ -0,0 +1,14 @@ +var test = require ('tap') . test +var readdir = require ('../readdir.js') + +test ('basic', function (t) { + // should not get {a,b}/{x,y}, but SHOULD get @org/ and @scope children + var expect = [ '@org/x', '@org/y', '@scope/x', '@scope/y', 'a', 'b' ] + + readdir (__dirname + '/fixtures', function (er, kids) { + if (er) + throw er + t.same(kids, expect) + t.end() + }) +}) diff --git a/node_modules/readdir-scoped-modules/test/fixtures/@org/x/.keep b/node_modules/readdir-scoped-modules/test/fixtures/@org/x/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/@org/x/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/@org/y/.keep b/node_modules/readdir-scoped-modules/test/fixtures/@org/y/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/@org/y/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/@scope/x/.keep b/node_modules/readdir-scoped-modules/test/fixtures/@scope/x/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/@scope/x/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/@scope/y/.keep b/node_modules/readdir-scoped-modules/test/fixtures/@scope/y/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/@scope/y/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/a/x/.keep b/node_modules/readdir-scoped-modules/test/fixtures/a/x/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/a/x/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/a/y/.keep b/node_modules/readdir-scoped-modules/test/fixtures/a/y/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/a/y/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/b/x/.keep b/node_modules/readdir-scoped-modules/test/fixtures/b/x/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/b/x/.keep diff --git a/node_modules/readdir-scoped-modules/test/fixtures/b/y/.keep b/node_modules/readdir-scoped-modules/test/fixtures/b/y/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/node_modules/readdir-scoped-modules/test/fixtures/b/y/.keep |