summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readdir-scoped-modules/readdir.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/readdir-scoped-modules/readdir.js')
-rw-r--r--deps/npm/node_modules/readdir-scoped-modules/readdir.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/deps/npm/node_modules/readdir-scoped-modules/readdir.js b/deps/npm/node_modules/readdir-scoped-modules/readdir.js
index efbe5526d8..806d787051 100644
--- a/deps/npm/node_modules/readdir-scoped-modules/readdir.js
+++ b/deps/npm/node_modules/readdir-scoped-modules/readdir.js
@@ -5,6 +5,7 @@ var path = require ('path')
var debug = require ('debuglog') ('rds')
module . exports = readdir
+readdir.sync = readdirSync
function readdir (dir, cb) {
fs . readdir (dir, function (er, kids) {
@@ -26,6 +27,18 @@ function readdir (dir, cb) {
})
}
+function readdirSync (dir) {
+ var kids = fs . readdirSync (dir)
+ debug ('dir=%j, kids=%j', dir, kids)
+ var data = readScopesSync (dir, kids)
+ // Sort for bonus consistency points
+ data = data . sort (function (a, b) {
+ return a > b ? 1 : -1
+ })
+
+ return data
+}
+
// Turn [ 'a', '@scope' ] into
// ['a', '@scope/foo', '@scope/bar']
function readScopes (root, kids, cb) {
@@ -69,3 +82,40 @@ function readScopes (root, kids, cb) {
cb (null, kids)
}
}
+
+function readScopesSync (root, kids) {
+ 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)
+ return kids
+
+ var l = scopes . length
+ scopes . forEach (function (scope) {
+ var scopedir = path . resolve (root, scope)
+ debug ('root=%j scope=%j scopedir=%j', root, scope, scopedir)
+ then (scope, fs . readdirSync (scopedir))
+ })
+
+ function then (scope, scopekids) {
+ // 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)
+ }
+
+ return kids
+}