Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

readdir-scoped-modules

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readdir-scoped-modules - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

7

package.json
{
"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
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc