From f9e0d39306b1fa07c42e4afb943cb3a0ea733552 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 26 Apr 2024 16:49:45 -0700 Subject: [PATCH 1/3] doc(CONTRIBUTORS): updated --- CONTRIBUTORS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 06267fd..4398924 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -2,7 +2,7 @@ This handcrafted artisinal software is brought to you by: -|
msimerson (54) |
PSSGCSim (7) |
baudehlo (1) |
Wesitos (1) |
oreoluwa (1) | -| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | +|
msimerson (55)|
PSSGCSim (7)|
baudehlo (1)|
Wesitos (1)|
oreoluwa (1)| +| :---: | :---: | :---: | :---: | :---: | this file is maintained by [.release](https://github.com/msimerson/.release) From ed348230f377bec41a03976faf1e24ba40e2bb0a Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 26 Apr 2024 16:53:55 -0700 Subject: [PATCH 2/3] reader: use path.sep instead of [\\/] to be more obvious - for windows compat --- CHANGELOG.md | 7 +++++++ lib/reader.js | 2 +- package.json | 2 +- test/config.js | 32 ++++++++++++-------------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 301f1ff..2e3f73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Unreleased +### [1.2.3] - 2024-04-26 + +- reader: use path.sep instead of [\\/] to be more obvious + ### [1.2.2] - 2024-04-24 - feat: getDir can parse different types of files in a dir @@ -126,3 +130,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). [1.1.0]: https://github.com/haraka/haraka-config/releases/tag/1.1.0 [1.2.2]: https://github.com/haraka/haraka-config/releases/tag/v1.2.2 +[1.2.3]: https://github.com/haraka/haraka-config/releases/tag/v1.2.3 +[1.2.0]: https://github.com/haraka/haraka-config/releases/tag/v1.2.0 +[1.2.1]: https://github.com/haraka/haraka-config/releases/tag/v1.2.1 diff --git a/lib/reader.js b/lib/reader.js index 2d7f70b..71a2df7 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -35,7 +35,7 @@ class Reader { } // when loaded with require('haraka-config') - if (/node_modules\/haraka-config\/lib$/.test(__dirname)) { + 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 diff --git a/package.json b/package.json index c2f05c4..4d67aa9 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "haraka-config", "license": "MIT", "description": "Haraka's config file loader", - "version": "1.2.2", + "version": "1.2.3", "homepage": "http://haraka.github.io", "repository": { "type": "git", diff --git a/test/config.js b/test/config.js index e54d71d..8dc4204 100644 --- a/test/config.js +++ b/test/config.js @@ -234,11 +234,10 @@ describe('get', function () { _test_get('test', null, null, null, null) }) - it('test (non-existing, cached)', function (done) { + it('test (non-existing, cached)', function () { process.env.WITHOUT_CONFIG_CACHE = '' const cfg = this.config.get('test', null, null) assert.deepEqual(cfg, null) - done() }) it('test.ini, no opts', function () { @@ -309,13 +308,14 @@ describe('get', function () { _test_get('test.txt', null, null, null, null) }) + it('test.int', function () { + _test_get('test.int', null, null, null, 6) + }) + it('test.flat, type=', function () { _test_get('test.flat', null, null, null, 'line1') }) - // NOTE: the test.flat file had to be duplicated for these tests, to avoid - // the config cache from returning invalid results. - it('test.flat, type=value', function () { _test_get('test.value', 'value', null, null, 'line1') }) @@ -452,20 +452,15 @@ describe('getInt', function () { const tmpFile = path.resolve('test', 'config', 'dir', '4.ext') -function cleanup(done) { - fs.unlink(tmpFile, () => { - done() - }) -} - describe('getDir', function () { + beforeEach(function (done) { process.env.NODE_ENV = 'test' process.env.HARAKA = '' process.env.WITHOUT_CONFIG_CACHE = '1' clearRequireCache() this.config = require('../config') - cleanup(done) + fs.unlink(tmpFile, () => done()) }) it('loads all files in dir', function (done) { @@ -489,18 +484,15 @@ describe('getDir', function () { it('reloads when file in dir is touched', function (done) { this.timeout(3500) - if (/darwin/.test(process.platform)) { - // due to differences in fs.watch, this test is not reliable on Mac OS X - done() - return - } - const self = this + // due to differences in fs.watch, this test is not reliable on Mac OS X + if (/darwin/.test(process.platform)) return done() + let callCount = 0 - function getDir() { + const getDir = () => { const opts2 = { type: 'binary', watchCb: getDir } - self.config.getDir('dir', opts2, (err, files) => { + this.config.getDir('dir', opts2, (err, files) => { // console.log('Loading: test/config/dir'); if (err) console.error(err) callCount++ From aed5eee61f7fa565dc29c0662688a2fa9f26140a Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 26 Apr 2024 16:54:16 -0700 Subject: [PATCH 3/3] chore: format --- CONTRIBUTORS.md | 4 ++-- lib/reader.js | 5 ++++- test/config.js | 1 - test/reader.js | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4398924..4d50773 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -2,7 +2,7 @@ This handcrafted artisinal software is brought to you by: -|
msimerson (55)|
PSSGCSim (7)|
baudehlo (1)|
Wesitos (1)|
oreoluwa (1)| -| :---: | :---: | :---: | :---: | :---: | +|
msimerson (55) |
PSSGCSim (7) |
baudehlo (1) |
Wesitos (1) |
oreoluwa (1) | +| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | this file is maintained by [.release](https://github.com/msimerson/.release) diff --git a/lib/reader.js b/lib/reader.js index 71a2df7..7b667b0 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -35,7 +35,10 @@ 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 diff --git a/test/config.js b/test/config.js index 8dc4204..36a2fc6 100644 --- a/test/config.js +++ b/test/config.js @@ -453,7 +453,6 @@ describe('getInt', function () { const tmpFile = path.resolve('test', 'config', 'dir', '4.ext') describe('getDir', function () { - beforeEach(function (done) { process.env.NODE_ENV = 'test' process.env.HARAKA = '' diff --git a/test/reader.js b/test/reader.js index 6e92233..308941d 100644 --- a/test/reader.js +++ b/test/reader.js @@ -175,9 +175,9 @@ describe('reader', function () { path.resolve('test/config/dir'), ) assert.deepEqual(result, [ - {data: 'contents1', path: '1.ext' }, - {data: 'contents2', path: '2.ext' }, - {data: 'contents3', path: '3.ext' } + { data: 'contents1', path: '1.ext' }, + { data: 'contents2', path: '2.ext' }, + { data: 'contents3', path: '3.ext' }, ]) })