Repository: pinojs/pino
Pull request #1972 (2024-05-13 12:16:20)

Drop yarn support and update pnpm


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 87c1410..274931b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -31,7 +31,7 @@ jobs:
           persist-credentials: false
 
       - name: Dependency review
-        uses: actions/dependency-review-action@v3
+        uses: actions/dependency-review-action@v4
 
   test:
     name: ${{ matrix.node-version }} ${{ matrix.os }}
diff --git a/.github/workflows/package-manager-ci.yml b/.github/workflows/package-manager-ci.yml
index 09304ca..cf2fe8d 100644
--- a/.github/workflows/package-manager-ci.yml
+++ b/.github/workflows/package-manager-ci.yml
@@ -24,76 +24,10 @@ jobs:
         with:
           node-version: ${{ matrix.node-version }}
       - name: Use pnpm
-        uses: pnpm/action-setup@v2.4.0
+        uses: pnpm/action-setup@v3.0.0
         with:
-          version: ^6.0.0
+          version: ^9.0.0
       - name: Install dependancies
         run: pnpm install
       - name: Tests
         run: pnpm run test-ci-pnpm
-
-  yarn:
-    name: yarn package manager on ${{ matrix.node-version }} ${{ matrix.os }}
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [windows-latest, ubuntu-latest]
-        node-version: [20]
-    steps:
-      - uses: actions/checkout@v4
-        with:
-          persist-credentials: false
-      - name: Use Node.js ${{ matrix.node-version }}
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ matrix.node-version }}
-      - name: Use yarn
-        run: |
-          yarn set version berry && yarn set version 2
-          echo "nodeLinker: node-modules" >> .yarnrc.yml
-          # see https://github.com/yarnpkg/berry/issues/2935#issuecomment-911299992
-          yarn add --dev typescript@~4.3.2
-          yarn install
-        env:
-          # needed due the yarn.lock file in pino's .gitignore
-          YARN_ENABLE_IMMUTABLE_INSTALLS: false
-      - name: Tests
-        run: yarn run test-ci
-
-  yarn-pnp:
-    name: yarn-pnp package manager on ${{ matrix.node-version }} ${{ matrix.os }}
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [windows-latest, ubuntu-latest]
-        node-version: [20]
-    steps:
-      - uses: actions/checkout@v4
-        with:
-          persist-credentials: false
-      - name: Use Node.js ${{ matrix.node-version }}
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ matrix.node-version }}
-      - name: Use yarn
-        run: |
-          yarn set version berry
-          echo 'nodeLinker: pnp
-          packageExtensions:
-            debug@*:
-              dependencies:
-                supports-color: "*"
-            treport@*:
-              dependencies:
-                tap-yaml: "*"
-          ' >> .yarnrc.yml
-          yarn add --dev typescript@~4.3.2
-          yarn install
-          yarn add --dev transport@link:./test/fixtures/transport
-        env:
-          # needed due the yarn.lock file in pino's .gitignore
-          YARN_ENABLE_IMMUTABLE_INSTALLS: false
-      - name: Tests
-        run: yarn run test-ci-yarn-pnp
diff --git a/browser.js b/browser.js
index 04b00ce..f786739 100644
--- a/browser.js
+++ b/browser.js
@@ -302,7 +302,7 @@ function createWrap (self, opts, rootLogger, level) {
       const proto = (Object.getPrototypeOf && Object.getPrototypeOf(this) === _console) ? _console : this
       for (var i = 0; i < args.length; i++) args[i] = arguments[i]
 
-      if (opts.serialize && !opts.asObject) {
+      if (opts.serialize && !opts.transmit) {
         applySerializers(args, this._serialize, this.serializers, this._stdErrSerialize)
       }
       if (opts.asObject || opts.formatters) {
@@ -330,17 +330,22 @@ function createWrap (self, opts, rootLogger, level) {
 
 function asObject (logger, level, args, ts, formatters = {}) {
   const {
-    level: levelFormatter = () => logger.levels.values[level],
+    level: levelFormatter,
     log: logObjectFormatter = (obj) => obj
   } = formatters
-  if (logger._serialize) applySerializers(args, logger._serialize, logger.serializers, logger._stdErrSerialize)
   const argsCloned = args.slice()
   let msg = argsCloned[0]
   const logObject = {}
   if (ts) {
     logObject.time = ts
   }
-  logObject.level = levelFormatter(level, logger.levels.values[level])
+
+  if (levelFormatter) {
+    const formattedLevel = levelFormatter(level, logger.levels.values[level])
+    Object.assign(logObject, formattedLevel)
+  } else {
+    logObject.level = logger.levels.values[level]
+  }
 
   let lvl = (logger._childLevel | 0) + 1
   if (lvl < 1) lvl = 1
@@ -361,9 +366,9 @@ function applySerializers (args, serialize, serializers, stdErrSerialize) {
   for (const i in args) {
     if (stdErrSerialize && args[i] instanceof Error) {
       args[i] = pino.stdSerializers.err(args[i])
-    } else if (typeof args[i] === 'object' && !Array.isArray(args[i])) {
+    } else if (typeof args[i] === 'object' && !Array.isArray(args[i]) && serialize) {
       for (const k in args[i]) {
-        if (serialize && serialize.indexOf(k) > -1 && k in serializers) {
+        if (serialize.indexOf(k) > -1 && k in serializers) {
           args[i][k] = serializers[k](args[i][k])
         }
       }
@@ -385,6 +390,7 @@ function transmit (logger, opts, args) {
     logger.serializers,
     logger._stdErrSerialize === undefined ? true : logger._stdErrSerialize
   )
+
   logger._logEvent.ts = ts
   logger._logEvent.messages = args.filter(function (arg) {
     // bindings can only be objects, so reference equality check via indexOf is fine
diff --git a/docs/browser.md b/docs/browser.md
index deb465c..a23ce83 100644
--- a/docs/browser.md
+++ b/docs/browser.md
@@ -144,7 +144,7 @@ Unlike server pino the serializers apply to every object passed to the logger me
 if the `asObject` option is `true`, this results in the serializers applying to the
 first object (as in server pino).
 
-For more info on serializers see https://github.com/pinojs/pino/blob/master/docs/api.md#parameters.
+For more info on serializers see https://github.com/pinojs/pino/blob/master/docs/api.md#mergingobject.
 
 ### `transmit` (Object)
 
diff --git a/package.json b/package.json
index 76bf66b..5a1a850 100644
--- a/package.json
+++ b/package.json
@@ -84,7 +84,7 @@
     "log": "^6.0.0",
     "loglevel": "^1.6.7",
     "midnight-smoker": "1.1.1",
-    "pino-pretty": "^10.2.1",
+    "pino-pretty": "^11.0.0",
     "pre-commit": "^1.2.2",
     "proxyquire": "^2.1.3",
     "pump": "^3.0.0",
@@ -97,7 +97,7 @@
     "tape": "^5.5.3",
     "through2": "^4.0.0",
     "ts-node": "^10.9.1",
-    "tsd": "^0.30.4",
+    "tsd": "^0.31.0",
     "typescript": "^5.1.3",
     "winston": "^3.7.2"
   },
@@ -106,12 +106,12 @@
     "fast-redact": "^3.1.1",
     "on-exit-leak-free": "^2.1.0",
     "pino-abstract-transport": "^1.2.0",
-    "pino-std-serializers": "^6.0.0",
+    "pino-std-serializers": "^7.0.0",
     "process-warning": "^3.0.0",
     "quick-format-unescaped": "^4.0.3",
     "real-require": "^0.2.0",
     "safe-stable-stringify": "^2.3.1",
-    "sonic-boom": "^3.7.0",
+    "sonic-boom": "^4.0.1",
     "thread-stream": "^2.6.0"
   },
   "tsd": {


Test patch:
diff --git a/test/browser-serializers.test.js b/test/browser-serializers.test.js
index 77d6dee..07cfa60 100644
--- a/test/browser-serializers.test.js
+++ b/test/browser-serializers.test.js
@@ -284,7 +284,6 @@ test('children inherit parent serializers', ({ end, is }) => {
 
 test('children serializers get called', ({ end, is }) => {
   const parent = pino({
-    test: 'this',
     browser: {
       serialize: true,
       write (o) {
@@ -301,7 +300,6 @@ test('children serializers get called', ({ end, is }) => {
 
 test('children serializers get called when inherited from parent', ({ end, is }) => {
   const parent = pino({
-    test: 'this',
     serializers: parentSerializers,
     browser: {
       serialize: true,
diff --git a/test/browser.test.js b/test/browser.test.js
index c296411..ab0b045 100644
--- a/test/browser.test.js
+++ b/test/browser.test.js
@@ -166,7 +166,7 @@ test('opts.browser.asObject logs pino-like object to console', ({ end, ok, is })
   end()
 })
 
-test('opts.browser.formatters logs pino-like object to console', ({ end, ok, is }) => {
+test('opts.browser.formatters (level) logs pino-like object to console', ({ end, ok, is }) => {
   const info = console.info
   console.info = function (o) {
     is(o.level, 30)
@@ -189,7 +189,7 @@ test('opts.browser.formatters logs pino-like object to console', ({ end, ok, is
   end()
 })
 
-test('opts.browser.formatters logs pino-like object to console', ({ end, ok, is }) => {
+test('opts.browser.formatters (log) logs pino-like object to console', ({ end, ok, is }) => {
   const info = console.info
   console.info = function (o) {
     is(o.level, 30)
@@ -213,40 +213,66 @@ test('opts.browser.formatters logs pino-like object to console', ({ end, ok, is
   end()
 })
 
-test('opts.browser.write func log single string', ({ end, ok, is }) => {
-  const instance = pino({
+test('opts.browser.serialize and opts.browser.transmit only serializes log data once', ({ end, ok, is }) => {
+  const instance = require('../browser')({
+    serializers: {
+      extras (data) {
+        return { serializedExtras: data }
+      }
+    },
     browser: {
+      serialize: ['extras'],
+      transmit: {
+        level: 'info',
+        send (level, o) {
+          is(o.messages[0].extras.serializedExtras, 'world')
+        }
+      }
+    }
+  })
+
+  instance.info({ extras: 'world' }, 'test')
+  end()
+})
+
+test('opts.browser.serialize and opts.asObject only serializes log data once', ({ end, ok, is }) => {
+  const instance = require('../browser')({
+    serializers: {
+      extras (data) {
+        return { serializedExtras: data }
+      }
+    },
+    browser: {
+      serialize: ['extras'],
+      asObject: true,
       write: function (o) {
-        is(o.level, 30)
-        is(o.msg, 'test')
-        ok(o.time)
+        is(o.extras.serializedExtras, 'world')
       }
     }
   })
-  instance.info('test')
 
+  instance.info({ extras: 'world' }, 'test')
   end()
 })
 
-test('opts.browser.write func string joining', ({ end, ok, is }) => {
+test('opts.browser.write func log single string', ({ end, ok, is }) => {
   const instance = pino({
     browser: {
       write: function (o) {
         is(o.level, 30)
-        is(o.msg, 'test test2 test3')
+        is(o.msg, 'test')
         ok(o.time)
       }
     }
   })
-  instance.info('test %s %s', 'test2', 'test3')
+  instance.info('test')
 
   end()
 })
 
-test('opts.browser.write func string joining when asObject is true', ({ end, ok, is }) => {
+test('opts.browser.write func string joining', ({ end, ok, is }) => {
   const instance = pino({
     browser: {
-      asObject: true,
       write: function (o) {
         is(o.level, 30)
         is(o.msg, 'test test2 test3')