readdir-scoped-modules
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "readdir-scoped-modules", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Like `fs.readdir` but handling `@org/module` dirs as if they were a single entry.", | ||
@@ -30,3 +30,6 @@ "main": "readdir.js", | ||
}, | ||
"homepage": "https://github.com/npm/readdir-scoped-modules" | ||
"homepage": "https://github.com/npm/readdir-scoped-modules", | ||
"files": [ | ||
"readdir.js" | ||
] | ||
} |
@@ -8,2 +8,3 @@ var fs = require ('graceful-fs') | ||
module . exports = readdir | ||
readdir.sync = readdirSync | ||
@@ -30,2 +31,14 @@ 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 | ||
@@ -74,1 +87,38 @@ // ['a', '@scope/foo', '@scope/bar'] | ||
} | ||
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 | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4927
95
0
4