From a0b8843482062c9a4fd4cc0472ed6e43aefd2670 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 3 Apr 2024 15:20:11 -0700 Subject: [PATCH] Release v1.2.1 (#5) - feat: use optional chaining (?.) & default params - remove eslint & mocha from devDeps (install as needed with npx) related to haraka/Haraka#3290 --- .release | 2 +- Changes.md | 7 +++++++ index.js | 24 ++++++++++++------------ package.json | 14 ++++++-------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.release b/.release index 1db5e30..954197d 160000 --- a/.release +++ b/.release @@ -1 +1 @@ -Subproject commit 1db5e30154db50a9d355ef711bf87a07dfe79bf1 +Subproject commit 954197dae07b32c4476ff87ec9ae7371311ec97d diff --git a/Changes.md b/Changes.md index 4dc254d..ec72488 100644 --- a/Changes.md +++ b/Changes.md @@ -2,6 +2,12 @@ ### Unreleased +### [1.2.1] - 2024-04-03 + +- es6: use optional chaining (?.), for safety +- es6: use default function params + + ### [1.2.0] - 2022-06-24 - merged in ChunkEmitter, only used here @@ -21,3 +27,4 @@ [1.1.0]: https://github.com/haraka/message-stream/releases/tag/1.1.0 [1.2.0]: https://github.com/haraka/message-stream/releases/tag/1.2.0 +[1.2.1]: https://github.com/haraka/message-stream/releases/tag/1.2.1 diff --git a/index.js b/index.js index aae235c..173b3af 100644 --- a/index.js +++ b/index.js @@ -25,11 +25,11 @@ class MessageStream extends Stream { this.total_buffered = 0; this._queue = []; this.max_data_inflight = 0; - this.buffer_max = (!isNaN(cfg.main.spool_after) ? Number(cfg.main.spool_after) : -1); + this.buffer_max = (!isNaN(cfg?.main?.spool_after) ? Number(cfg.main.spool_after) : -1); this.spooling = false; this.fd = null; this.open_pending = false; - this.spool_dir = cfg.main.spool_dir || '/tmp'; + this.spool_dir = cfg?.main?.spool_dir || '/tmp'; this.filename = `${this.spool_dir}/${id}.eml`; this.write_pending = false; @@ -70,7 +70,7 @@ class MessageStream extends Stream { if (this.state === STATE.HEADERS) { // Look for end of headers line if (line.length === 2 && line[0] === 0x0d && line[1] === 0x0a) { - this.idx.headers = { start: 0, end: this.bytes_read-line.length }; + this.idx.headers = { start: 0, end: this.bytes_read - line.length }; this.state = STATE.BODY; this.idx.body = { start: this.bytes_read }; } @@ -90,7 +90,7 @@ class MessageStream extends Stream { else { // Start of boundary? if (!this.idx[boundary]) { - this.idx[boundary] = { start: this.bytes_read-line.length }; + this.idx[boundary] = { start: this.bytes_read - line.length }; } } } @@ -313,19 +313,19 @@ class MessageStream extends Stream { }); } - pipe (destination, options) { + pipe (destination, options = {}) { const self = this; if (this.in_pipe) { throw new Error('Cannot pipe while currently piping'); } Stream.prototype.pipe.call(this, destination, options); // Options - this.line_endings = ((options && options.line_endings) ? options.line_endings : "\r\n"); - this.dot_stuffing = ((options && options.dot_stuffing) ? options.dot_stuffing : false); - this.ending_dot = ((options && options.ending_dot) ? options.ending_dot : false); - this.clamd_style = (!!((options && options.clamd_style))); - this.buffer_size = ((options && options.buffer_size) ? options.buffer_size : 1024 * 64); - this.start = ((options && parseInt(options.start)) ? parseInt(options.start) : 0); + this.line_endings = options?.line_endings ?? '\r\n'; + this.dot_stuffing = options?.dot_stuffing ?? false; + this.ending_dot = options?.ending_dot ?? false; + this.clamd_style = !!options?.clamd_style; + this.buffer_size = options?.buffer_size ?? 1024 * 64; + this.start = (parseInt(options?.start) ? parseInt(options.start) : 0); // Reset this.in_pipe = true; this.readable = true; @@ -512,4 +512,4 @@ class ChunkEmitter extends EventEmitter { } } -module.exports.ChunkEmitter = ChunkEmitter \ No newline at end of file +module.exports.ChunkEmitter = ChunkEmitter diff --git a/package.json b/package.json index 4550312..319821d 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "haraka-message-stream", - "version": "1.2.0", + "version": "1.2.1", "description": "Haraka email message stream", "main": "index.js", "scripts": { - "lint": "npx eslint *.js test", - "lintfix": "npx eslint --fix *.js test", + "lint": "npx eslint@^8 *.js test", + "lintfix": "npx eslint@^8 --fix *.js test", "versions": "npx dependency-version-checker check", - "test": "npx mocha" + "test": "npx mocha@^10" }, "repository": { "type": "git", @@ -25,10 +25,8 @@ }, "homepage": "https://github.com/haraka/message-stream#readme", "devDependencies": { - "eslint": ">=8", - "eslint-plugin-haraka": "*", - "haraka-test-fixtures": "*", - "mocha": ">=9" + "eslint-plugin-haraka": "^1.0.15", + "haraka-test-fixtures": "^1.3.3" }, "dependencies": {} }