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

haraka-config

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haraka-config - npm Package Compare versions

Comparing version 1.2.4 to 1.3.0

5

CHANGELOG.md

@@ -7,2 +7,6 @@ # Changelog

### [1.3.0] - 2024-05-02
- feat: getDir is now recursive
### [1.2.4] - 2024-04-26

@@ -138,1 +142,2 @@

[1.2.4]: https://github.com/haraka/haraka-config/releases/tag/v1.2.4
[1.3.0]: https://github.com/haraka/haraka-config/releases/tag/v1.3.0

7

config.js

@@ -57,4 +57,9 @@ 'use strict'

getDir(name, opts, done) {
const dir = path.resolve(this.root_path, name)
// no callback, return promise
if (arguments.length < 3) return reader.read_dir(dir, opts)
reader
.read_dir(path.resolve(this.root_path, name), opts)
.read_dir(dir, opts)
.then((files) => {

@@ -61,0 +66,0 @@ done(null, files) // keep the API consistent

46

lib/reader.js

@@ -140,26 +140,28 @@ 'use strict'

read_dir(name, opts = {}) {
return new Promise((resolve, reject) => {
this._read_args[name] = { opts }
async read_dir(name, opts = {}) {
this._read_args[name] = { opts }
fsp
.stat(name)
.then((stat) => stat.isDirectory())
.then(() => fsp.readdir(name))
.then(async (fileList) => {
const contents = []
for (const file of fileList) {
const type = opts.type ?? this.getType(file)
contents.push({
path: file,
data: this.load_config(path.resolve(name, file), type, opts),
})
}
return contents
})
.then(resolve)
.catch(reject)
const contents = []
const dirs = []
if (opts.watchCb) watch.dir2(this, name)
})
const stat = await fsp.stat(name)
if (stat.isDirectory()) dirs.push(name)
for (const dir of dirs) {
for (const entry of await fsp.readdir(dir)) {
const entryPath = path.join(dir, entry)
const stat = await fsp.stat(entryPath)
if (stat.isDirectory()) dirs.push(entryPath) // recursion
if (stat.isFile()) {
const type = opts.type ?? this.getType(entry)
contents.push({
path: entryPath,
data: this.load_config(entryPath, type, opts),
})
}
}
}
if (opts.watchCb) watch.dir2(this, name)
return contents
}

@@ -166,0 +168,0 @@

@@ -92,3 +92,3 @@ const fs = require('node:fs')

// recursive is only supported on Windows (win32, win64) and macOS (darwin)
if (!/win/.test(process.platform)) watchOpts.recursive = false
if (!/win|darwin/.test(process.platform)) watchOpts.recursive = false

@@ -109,2 +109,3 @@ watchers[dirPath] = fs.watch(dirPath, watchOpts, (fse, filename) => {

})
watchers[dirPath].unref()
}

@@ -111,0 +112,0 @@

@@ -6,3 +6,3 @@ {

"description": "Haraka's config file loader",
"version": "1.2.4",
"version": "1.3.0",
"homepage": "http://haraka.github.io",

@@ -9,0 +9,0 @@ "repository": {

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