Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI

on:
push:
pull_request:
types: [opened, synchronize, reopened]

env:
CI: true
Expand All @@ -11,6 +11,11 @@ jobs:
lint:
uses: haraka/.github/.github/workflows/lint.yml@master

prettier:
uses: haraka/.github/.github/workflows/prettier.yml@master
with:
branch: ${{ github.head_ref }}

coverage:
uses: haraka/.github/.github/workflows/coverage.yml@master
secrets: inherit
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '18 7 * * 4'

jobs:
codeql:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: publish

on:
push:
branches:
- master
paths:
- package.json
release:
types: [published]

env:
CI: true
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: release

on:
push:
branches:
- master
- main
paths:
- package.json

env:
CI: true

jobs:
release:
uses: haraka/.github/.github/workflows/release.yml@master
secrets: inherit
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [1.5.0] - 2026-03-04

- dep: replaced js-yaml with yaml
- yaml supports v1.2
- js-yaml is barely maintained, replacing it removes most vuln warnings
- test: replaced mocha with node --test
- test: added test/watch
- ci: updated ci, publish & release workflows

### [1.4.2] - 2025-01-08

- dep(eslint): upgrade 8 -> 9
Expand Down Expand Up @@ -156,3 +165,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
[1.4.0]: https://github.com/haraka/haraka-config/releases/tag/v1.4.0
[1.4.1]: https://github.com/haraka/haraka-config/releases/tag/v1.4.1
[1.4.2]: https://github.com/haraka/haraka-config/releases/tag/v1.4.2
[1.5.0]: https://github.com/haraka/haraka-config/releases/tag/v1.5.0
4 changes: 2 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Contributors

This handcrafted artisinal software is brought to you by:
This handcrafted artisanal software is brought to you by:

| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/haraka/haraka-config/commits?author=msimerson">60</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/42121756?v=4"><br><a href="https://github.com/PSSGCSim">PSSGCSim</a> (<a href="https://github.com/haraka/haraka-config/commits?author=PSSGCSim">7</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/1346804?v=4"><br><a href="https://github.com/louis-lau">louis-lau</a> (<a href="https://github.com/haraka/haraka-config/commits?author=louis-lau">2</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/662371?v=4"><br><a href="https://github.com/baudehlo">baudehlo</a> (<a href="https://github.com/haraka/haraka-config/commits?author=baudehlo">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/651048?v=4"><br><a href="https://github.com/Wesitos">Wesitos</a> (<a href="https://github.com/haraka/haraka-config/commits?author=Wesitos">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/2270015?v=4"><br><a href="https://github.com/oreoluwa">oreoluwa</a> (<a href="https://github.com/haraka/haraka-config/commits?author=oreoluwa">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/83369329?v=4"><br><a href="https://github.com/polarismail">polarismail</a> (<a href="https://github.com/haraka/haraka-config/commits?author=polarismail">1</a>) |
| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/haraka/haraka-config/commits?author=msimerson">61</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/42121756?v=4"><br><a href="https://github.com/PSSGCSim">PSSGCSim</a> (<a href="https://github.com/haraka/haraka-config/commits?author=PSSGCSim">7</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/1346804?v=4"><br><a href="https://github.com/louis-lau">louis-lau</a> (<a href="https://github.com/haraka/haraka-config/commits?author=louis-lau">2</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/662371?v=4"><br><a href="https://github.com/baudehlo">baudehlo</a> (<a href="https://github.com/haraka/haraka-config/commits?author=baudehlo">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/651048?v=4"><br><a href="https://github.com/Wesitos">Wesitos</a> (<a href="https://github.com/haraka/haraka-config/commits?author=Wesitos">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/2270015?v=4"><br><a href="https://github.com/oreoluwa">oreoluwa</a> (<a href="https://github.com/haraka/haraka-config/commits?author=oreoluwa">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/83369329?v=4"><br><a href="https://github.com/polarismail">polarismail</a> (<a href="https://github.com/haraka/haraka-config/commits?author=polarismail">1</a>) |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |

<sub>this file is generated by [.release](https://github.com/msimerson/.release).
Expand Down
10 changes: 2 additions & 8 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class Config {
let [name, type, cb, options] = this.arrange_args(args)
if (!type) type = 'value'

const full_path = path.isAbsolute(name)
? name
: path.resolve(this.root_path, name)
const full_path = path.isAbsolute(name) ? name : path.resolve(this.root_path, name)

let results = reader.read_config(full_path, type, cb, options)

Expand Down Expand Up @@ -129,11 +127,7 @@ function merge_config(defaults, overrides, type) {
return merge_struct(JSON.parse(JSON.stringify(defaults)), overrides)
}

if (
Array.isArray(overrides) &&
Array.isArray(defaults) &&
overrides.length > 0
) {
if (Array.isArray(overrides) && Array.isArray(defaults) && overrides.length > 0) {
return overrides
}

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default [
},
},
rules: {
'no-unused-vars': ['warn', { 'caughtErrorsIgnorePattern': '^ignore' }],
'no-unused-vars': ['warn', { caughtErrorsIgnorePattern: '^ignore' }],
},
},
]
8 changes: 2 additions & 6 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class Reader {
}

// when loaded with require('haraka-config')
if (
__dirname.split(path.sep).slice(-3).toString() ===
'node_modules,haraka-config,lib'
) {
if (__dirname.split(path.sep).slice(-3).toString() === 'node_modules,haraka-config,lib') {
config_dir_candidates = [
path.join(__dirname, '..', '..', '..', 'config'), // haraka/Haraka/*
path.join(__dirname, '..', '..', '..'), // npm packaged modules
Expand Down Expand Up @@ -233,8 +230,7 @@ class Reader {

if (this._config_cache[cache_key]) {
for (const ck in this._config_cache[cache_key]) {
if (ck.substr(0, 1) === '!')
delete this._config_cache[path.join(cp, ck.substr(1))]
if (ck.substr(0, 1) === '!') delete this._config_cache[path.join(cp, ck.substr(1))]
}
}

Expand Down
10 changes: 2 additions & 8 deletions lib/readers/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
const regex = require('../regex')

exports.load = (...args) => {
return this.parseValue(
...args,
require('node:fs').readFileSync(args[0], 'UTF-8'),
)
return this.parseValue(...args, require('node:fs').readFileSync(args[0], 'UTF-8'))
}

exports.loadPromise = async (...args) => {
return this.parseValue(
...args,
await require('node:fs/promises').readFile(args[0], 'UTF-8'),
)
return this.parseValue(...args, await require('node:fs/promises').readFile(args[0], 'UTF-8'))
}

exports.parseValue = (name, type, options, data) => {
Expand Down
18 changes: 4 additions & 14 deletions lib/readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
const regex = require('../regex')

exports.load = (...args) => {
return this.parseIni(
...args,
require('node:fs').readFileSync(args[0], 'UTF-8'),
)
return this.parseIni(...args, require('node:fs').readFileSync(args[0], 'UTF-8'))
}

exports.loadPromise = async (...args) => {
return this.parseIni(
...args,
await require('node:fs/promises').readFile(args[0], 'UTF-8'),
)
return this.parseIni(...args, await require('node:fs/promises').readFile(args[0], 'UTF-8'))
}

exports.parseIni = (name, options = {}, data) => {
Expand Down Expand Up @@ -61,10 +55,7 @@ exports.parseIni = (name, options = {}, data) => {

const setter = this.getSetter(current_sect, regex.is_array.test(keyName))

if (
exports.isDeclaredBoolean(`${current_sect_name}.${keyName}`) ||
exports.isDeclaredBoolean(`*.${keyName}`)
) {
if (exports.isDeclaredBoolean(`${current_sect_name}.${keyName}`) || exports.isDeclaredBoolean(`*.${keyName}`)) {
current_sect[keyName] = regex.is_truth.test(keyVal)
} else if (regex.is_integer.test(keyVal)) {
setter(keyName, parseInt(keyVal, 10))
Expand Down Expand Up @@ -114,8 +105,7 @@ exports.init_booleans = (options, result) => {
let section = m[1] || 'main'
let key = m[2]

const bool_default =
section[0] === '+' ? true : key[0] === '+' ? true : false
const bool_default = section[0] === '+' ? true : key[0] === '+' ? true : false

if (section.match(/^(-|\+)/)) section = section.substr(1)
if (key.match(/^(-|\+)/)) key = key.substr(1)
Expand Down
6 changes: 3 additions & 3 deletions lib/readers/yaml.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const yaml = require('js-yaml')
const yaml = require('yaml')

exports.load = (name) => {
return yaml.load(require('node:fs').readFileSync(name, 'UTF-8'))
return yaml.parse(require('node:fs').readFileSync(name, 'UTF-8'))
}

exports.loadPromise = async (name) => {
return yaml.load(await require('node:fs/promises').readFile(name, 'UTF-8'))
return yaml.parse(await require('node:fs/promises').readFile(name, 'UTF-8'))
}

exports.empty = () => {
Expand Down
18 changes: 3 additions & 15 deletions lib/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ Watch.ensure_enoent_timer = (reader) => {
delete enoent.files[file]
const args = reader._read_args[file]
reader.load_config(file, args.type, args.options, args.cb)
watchers[file] = fs.watch(
file,
{ persistent: false },
Watch.onEvent(reader, file, args),
)
watchers[file] = fs.watch(file, { persistent: false }, Watch.onEvent(reader, file, args))
})
}
}, 60 * 1000)
Expand All @@ -38,11 +34,7 @@ Watch.file = (reader, name, type, cb, options) => {
if (watchers[name] || (options && options.no_watch)) return

try {
watchers[name] = fs.watch(
name,
{ persistent: false },
Watch.onEvent(reader, name, { type, options, cb }),
)
watchers[name] = fs.watch(name, { persistent: false }, Watch.onEvent(reader, name, { type, options, cb }))
} catch (e) {
if (e.code === 'ENOENT') {
// ignore error when ENOENT
Expand Down Expand Up @@ -126,11 +118,7 @@ Watch.onEvent = (reader, name, args) => {
// After a rename event, re-watch the file
watchers[name].close()
try {
watchers[name] = fs.watch(
name,
{ persistent: false },
Watch.onEvent(reader, name, args),
)
watchers[name] = fs.watch(name, { persistent: false }, Watch.onEvent(reader, name, args))
} catch (e) {
if (e.code === 'ENOENT') {
enoent.files[name] = true
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "haraka-config",
"license": "MIT",
"description": "Haraka's config file loader",
"version": "1.4.2",
"version": "1.5.0",
"homepage": "https://github.com/haraka/haraka-config",
"repository": {
"type": "git",
Expand All @@ -15,16 +15,16 @@
"CHANGELOG.md"
],
"engines": {
"node": ">=16"
"node": ">=20"
},
"dependencies": {
"js-yaml": "^4.1.0"
"yaml": "^2.8.2"
},
"optionalDependencies": {
"hjson": "^3.2.2"
},
"devDependencies": {
"@haraka/eslint-config": "^2.0.2"
"@haraka/eslint-config": "^2.0.3"
},
"bugs": {
"url": "https://github.com/haraka/haraka-config/issues"
Expand All @@ -35,8 +35,13 @@
"lint:fix": "npx eslint *.js lib test test/*/*.js --fix",
"prettier": "npx prettier . --check",
"prettier:fix": "npx prettier . --write --log-level=warn",
"test": "npx mocha@10 test test/readers",
"test": "node --test test/*.js test/readers/*.js",
"versions": "npx dependency-version-checker check",
"versions:fix": "npx dependency-version-checker update && npm run prettier:fix"
},
"prettier": {
"singleQuote": true,
"printWidth": 120,
"semi": false
}
}
Loading
Loading