From a2738a5a383cb7f1a525f2dc7d260133fc9d2c7f Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 15 Oct 2024 15:47:19 +0200 Subject: [PATCH 1/5] Drop pump & readable-stream Signed-off-by: Matteo Collina --- bin.js | 4 ++-- index.js | 5 ++--- package.json | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bin.js b/bin.js index d9d23aea..80c06465 100644 --- a/bin.js +++ b/bin.js @@ -6,7 +6,7 @@ const help = require('help-me')({ dir: path.join(__dirname, 'help'), ext: '.txt' }) -const pump = require('pump') +const { pipeline } = require('stream') const sjp = require('secure-json-parse') const JoyCon = require('joycon') const stripJsonComments = require('strip-json-comments') @@ -79,7 +79,7 @@ if (cmd.h || cmd.help) { opts.errorProps = opts.errorProps || '' const res = build(opts) - pump(process.stdin, res) + pipeline(process.stdin, res, () => {}) // https://github.com/pinojs/pino/pull/358 /* istanbul ignore next */ diff --git a/index.js b/index.js index 2d76def3..d34c1940 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ 'use strict' const { isColorSupported } = require('colorette') -const pump = require('pump') -const { Transform } = require('readable-stream') +const { Transform, pipeline: pump } = require('node:stream') const abstractTransport = require('pino-abstract-transport') const colors = require('./lib/colors') const { @@ -169,7 +168,7 @@ function build (opts = {}) { destination.write(line + '\n') }) - pump(source, stream, destination) + pump(source, stream, destination, () => {}) return stream }, { parse: 'lines' }) } diff --git a/package.json b/package.json index 2933b7c6..b89f7270 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,6 @@ "minimist": "^1.2.6", "on-exit-leak-free": "^2.1.0", "pino-abstract-transport": "^1.0.0", - "pump": "^3.0.0", - "readable-stream": "^4.0.0", "secure-json-parse": "^2.4.0", "sonic-boom": "^4.0.1", "strip-json-comments": "^3.1.1" From cda27589dd4ca196f5885aa4888961242cfff938 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 15 Oct 2024 16:14:30 +0200 Subject: [PATCH 2/5] wait for destination to close Signed-off-by: Matteo Collina --- index.js | 12 +++++++++--- test/basic.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d34c1940..e085c67d 100644 --- a/index.js +++ b/index.js @@ -131,6 +131,7 @@ function prettyFactory (options) { */ function build (opts = {}) { let pretty = prettyFactory(opts) + let destination return abstractTransport(function (source) { source.on('message', function pinoConfigListener (message) { if (!message || message.code !== 'PINO_CONFIG') return @@ -151,8 +152,6 @@ function build (opts = {}) { } }) - let destination - if (typeof opts.destination === 'object' && typeof opts.destination.write === 'function') { destination = opts.destination } else { @@ -170,7 +169,14 @@ function build (opts = {}) { pump(source, stream, destination, () => {}) return stream - }, { parse: 'lines' }) + }, { + parse: 'lines', + close (err, cb) { + destination.on('close', () => { + cb(err) + }) + } + }) } module.exports = build diff --git a/test/basic.test.js b/test/basic.test.js index 89514f54..a62abbf3 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1098,6 +1098,38 @@ test('basic prettifier tests', (t) => { t.equal(closeCalled, false) }) + t.test('wait for close event from destination', (t) => { + t.plan(2) + const destination = pino.destination({ minLength: 4096, sync: true }) + const prettyDestination = pinoPretty({ destination, colorize: false }) + const log = pino(prettyDestination) + log.info('this message has been buffered') + const chunks = [] + const { close, writeSync } = fs + fs.close = new Proxy(close, { + apply: (target, self, args) => { + } + }) + fs.writeSync = new Proxy(writeSync, { + apply: (target, self, args) => { + chunks.push(args[1]) + return args[1].length + } + }) + t.teardown(() => { + Object.assign(fs, { close, writeSync }) + }) + let destinationClosed = false + destination.on('close', () => { + destinationClosed = true + }) + prettyDestination.on('close', () => { + t.match(chunks.join(''), /INFO .+: this message has been buffered/) + t.equal(destinationClosed, true) + }) + prettyDestination.end() + }) + t.test('stream usage', async (t) => { t.plan(1) const tmpDir = path.join(__dirname, '.tmp_' + Date.now()) From 01d413d4f832dc57c0b1b2616ac37d3be8a553a5 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 15 Oct 2024 16:16:58 +0200 Subject: [PATCH 3/5] drop old nodes Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e2d5f91..186783f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,14 +40,10 @@ jobs: contents: read strategy: matrix: - node-version: [14, 16, 18.17, 20, 22] + node-version: [18.17, 20, 22] os: [ubuntu-latest] - pino-version: [8.20.0, ^8.21.0, ^9.0.0] - exclude: - - node-version: 14 - pino-version: ^9.0.0 - - node-version: 16 - pino-version: ^9.0.0 + pino-version: [^9.0.0] + steps: - name: Check out repo uses: actions/checkout@v4 From 0e2c7d6e1db58ec180b6f9ecebd5d346014fee40 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 15 Oct 2024 16:17:41 +0200 Subject: [PATCH 4/5] Revert "drop old nodes" This reverts commit 01d413d4f832dc57c0b1b2616ac37d3be8a553a5. --- .github/workflows/ci.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 186783f5..9e2d5f91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,10 +40,14 @@ jobs: contents: read strategy: matrix: - node-version: [18.17, 20, 22] + node-version: [14, 16, 18.17, 20, 22] os: [ubuntu-latest] - pino-version: [^9.0.0] - + pino-version: [8.20.0, ^8.21.0, ^9.0.0] + exclude: + - node-version: 14 + pino-version: ^9.0.0 + - node-version: 16 + pino-version: ^9.0.0 steps: - name: Check out repo uses: actions/checkout@v4 From 9530e5e1451d045a2584227542de5e1201bc5d14 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 15 Oct 2024 16:18:14 +0200 Subject: [PATCH 5/5] Revert "Drop pump & readable-stream" This reverts commit a2738a5a383cb7f1a525f2dc7d260133fc9d2c7f. Signed-off-by: Matteo Collina --- bin.js | 4 ++-- index.js | 5 +++-- package.json | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bin.js b/bin.js index 80c06465..d9d23aea 100644 --- a/bin.js +++ b/bin.js @@ -6,7 +6,7 @@ const help = require('help-me')({ dir: path.join(__dirname, 'help'), ext: '.txt' }) -const { pipeline } = require('stream') +const pump = require('pump') const sjp = require('secure-json-parse') const JoyCon = require('joycon') const stripJsonComments = require('strip-json-comments') @@ -79,7 +79,7 @@ if (cmd.h || cmd.help) { opts.errorProps = opts.errorProps || '' const res = build(opts) - pipeline(process.stdin, res, () => {}) + pump(process.stdin, res) // https://github.com/pinojs/pino/pull/358 /* istanbul ignore next */ diff --git a/index.js b/index.js index e085c67d..0368a660 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ 'use strict' const { isColorSupported } = require('colorette') -const { Transform, pipeline: pump } = require('node:stream') +const pump = require('pump') +const { Transform } = require('readable-stream') const abstractTransport = require('pino-abstract-transport') const colors = require('./lib/colors') const { @@ -167,7 +168,7 @@ function build (opts = {}) { destination.write(line + '\n') }) - pump(source, stream, destination, () => {}) + pump(source, stream, destination) return stream }, { parse: 'lines', diff --git a/package.json b/package.json index 18dac657..6a6eba4e 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,8 @@ "minimist": "^1.2.6", "on-exit-leak-free": "^2.1.0", "pino-abstract-transport": "^2.0.0", + "pump": "^3.0.0", + "readable-stream": "^4.0.0", "secure-json-parse": "^2.4.0", "sonic-boom": "^4.0.1", "strip-json-comments": "^3.1.1"