From 0e1bf11678f0bb58e7fbedff6bd8bc6d56fc5d41 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 26 Apr 2024 20:45:12 -0700 Subject: [PATCH] Release v1.2.4 (#75) - fix(watch): callback was losing context. Use explicit obj --- CHANGELOG.md | 9 +++++---- CONTRIBUTORS.md | 2 +- lib/watch.js | 24 ++++++++++++++---------- package.json | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3f73a..96c55ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Unreleased -### [1.2.3] - 2024-04-26 +### [1.2.4] - 2024-04-26 -- reader: use path.sep instead of [\\/] to be more obvious +- fix(watch): callback was losing context. Use explicit obj +- fix(reader): use path.sep instead of [\\/] to be more obvious ### [1.2.2] - 2024-04-24 @@ -129,7 +130,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). - reduce node required 4.3 -> 0.10.43 [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 +[1.2.2]: https://github.com/haraka/haraka-config/releases/tag/v1.2.2 +[1.2.4]: https://github.com/haraka/haraka-config/releases/tag/v1.2.4 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4d50773..7d53657 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 (56) |
PSSGCSim (7) |
baudehlo (1) |
Wesitos (1) |
oreoluwa (1) | | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | this file is maintained by [.release](https://github.com/msimerson/.release) diff --git a/lib/watch.js b/lib/watch.js index 3029dd6..6b764eb 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -5,7 +5,9 @@ const enoent = { timer: false, files: [] } const watchers = {} const sedation_timers = {} -module.exports.ensure_enoent_timer = (reader) => { +const Watch = {} + +Watch.ensure_enoent_timer = (reader) => { if (enoent.timer) return // Create timer enoent.timer = setInterval(() => { @@ -19,7 +21,7 @@ module.exports.ensure_enoent_timer = (reader) => { watchers[file] = fs.watch( file, { persistent: false }, - this.onEvent(reader, file, args), + Watch.onEvent(reader, file, args), ) }) } @@ -27,7 +29,7 @@ module.exports.ensure_enoent_timer = (reader) => { enoent.timer.unref() // don't block process exit } -module.exports.file = (reader, name, type, cb, options) => { +Watch.file = (reader, name, type, cb, options) => { // This works on all OS's, but watch_dir() above is preferred for Linux and // Windows as it is far more efficient. // NOTE: we need a fs.watch per file. It's impossible to watch non-existent @@ -39,13 +41,13 @@ module.exports.file = (reader, name, type, cb, options) => { watchers[name] = fs.watch( name, { persistent: false }, - this.onEvent(reader, name, { type, options, cb }), + Watch.onEvent(reader, name, { type, options, cb }), ) } catch (e) { if (e.code === 'ENOENT') { // ignore error when ENOENT enoent.files[name] = true - this.ensure_enoent_timer(reader) + Watch.ensure_enoent_timer(reader) } else { console.error(`Error watching config file: ${name} : ${e}`) } @@ -53,7 +55,7 @@ module.exports.file = (reader, name, type, cb, options) => { } // used to watch main haraka config dir -module.exports.dir = (reader) => { +Watch.dir = (reader) => { // NOTE: Has OS platform limitations: // https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener const cp = reader.config_path @@ -82,7 +84,7 @@ module.exports.dir = (reader) => { } // used by getDir -module.exports.dir2 = (reader, dirPath) => { +Watch.dir2 = (reader, dirPath) => { if (watchers[dirPath]) return const watchOpts = { persistent: false, recursive: true } @@ -105,7 +107,7 @@ module.exports.dir2 = (reader, dirPath) => { }) } -module.exports.onEvent = (reader, name, args) => { +Watch.onEvent = (reader, name, args) => { return (fse) => { if (sedation_timers[name]) { clearTimeout(sedation_timers[name]) @@ -126,15 +128,17 @@ module.exports.onEvent = (reader, name, args) => { watchers[name] = fs.watch( name, { persistent: false }, - this.onEvent(...arguments), + Watch.onEvent(reader, name, args), ) } catch (e) { if (e.code === 'ENOENT') { enoent.files[name] = true - this.ensure_enoent_timer(reader) + Watch.ensure_enoent_timer(reader) } else { console.error(`Error watching file: ${name} : ${e}`) } } } } + +module.exports = Watch diff --git a/package.json b/package.json index 4d67aa9..410565c 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.3", + "version": "1.2.4", "homepage": "http://haraka.github.io", "repository": { "type": "git",