Skip to content

Commit

Permalink
Merge pull request #176 from zackschuster/master
Browse files Browse the repository at this point in the history
fix node 18 breakage
  • Loading branch information
andris9 authored Apr 28, 2022
2 parents bc798a1 + 3a217ad commit a2e765f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on: push

jobs:
test:
name: test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node: [^12, ^14, ^16, ^18]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: checkout
uses: actions/checkout@v2

- name: node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- name: install
run: npm install

- name: test
run: npm test
5 changes: 4 additions & 1 deletion lib/smtp-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ class SMTPConnection extends EventEmitter {
*/
_onClose(/* hadError */) {
if (this._parser) {
this._parser.closed = true;
// node 18 makes this a getter-only property, handled internally
if (this._parser.canSetClosedProp) {
this._parser.closed = true;
}
this._socket.unpipe(this._parser);
this._parser = false;
}
Expand Down
16 changes: 15 additions & 1 deletion lib/smtp-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ class SMTPStream extends Writable {
// unprocessed bytes from the last parsing iteration (used in data mode)
this._lastBytes = false;

this.closed = false;
// node 18 makes this a getter-only property, handled internally
if (this.canSetClosedProp) {
this.closed = false;
}

// once the input stream ends, flush all output without expecting the newline
this.on('finish', () => this._flushData());
}

get canSetClosedProp() {
try {
const { closed } = this;
this.closed = closed;
return true;
} catch (err) {
return false;
}
}

/**
* Placeholder command handler. Override this with your own.
*/
Expand Down
3 changes: 2 additions & 1 deletion test/smtp-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ describe('SMTPServer', function () {
});

server.onData = function (stream, session, callback) {
stream.pipe(fs.createWriteStream('/dev/null'));
const nullDevice = process.platform === 'win32' ? '\\\\.\\NUL' : '/dev/null';
stream.pipe(fs.createWriteStream(nullDevice));
callback();
};

Expand Down

0 comments on commit a2e765f

Please sign in to comment.