From cccc8170c77724b1394e6876d8fa8a73c82fcb16 Mon Sep 17 00:00:00 2001 From: Markus Schanz Date: Mon, 22 Jul 2024 13:28:34 +0200 Subject: [PATCH] fix: remove source-map-support package in favor of native NodeJS support --- index.js | 1 - package.json | 9 +++------ tests/test.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 04dd4f4..bc37d03 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ 'use strict' -require('source-map-support/register') const NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10) const STACKTRACE_OFFSET = NODEJS_VERSION && NODEJS_VERSION > 6 ? 0 : 1 const LINE_OFFSET = 7 diff --git a/package.json b/package.json index eb801f3..f506f41 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,15 @@ "standard": "^8.6.0", "tap": "^12.0.1", "through2": "^4.0.2", - "tsd": "^0.28.0", "ts-node": "^10.2.1", + "tsd": "^0.28.0", "typescript": "^5.0.2" }, "peerDependencies": { "pino": "*" }, "engines": { - "node": ">6.0.0" + "node": ">=12.12.0" }, "scripts": { "lint-fix": "standard --fix index.js examples/*js tests/*.js", @@ -44,14 +44,11 @@ "test": "tap tests/*.js && npm run test-ts && npm run test-types", "test-ts": "ts-node tests/test-ts.ts", "test-watch": "tap tests/*.js tests/*.ts", - "test:ci": "npm run pretest && tap --node-arg=\"-r\" --node-arg=\"source-map-support/register\" tests/*.js tests/*.ts --coverage-report=lcovonly && npm run test-types", + "test:ci": "npm run pretest && tap --node-arg=\"--enable-source-maps\" tests/*.js tests/*.ts --coverage-report=lcovonly && npm run test-types", "test-types": "tsc && tsd", "example": "env NODE_ENV=development node examples/index.js", "watch": "npm-watch" }, - "dependencies": { - "source-map-support": "^0.5.13" - }, "standard": { "ignore": [ "examples/module-ts.js" diff --git a/tests/test.js b/tests/test.js index 5c6dd5b..ea8678a 100644 --- a/tests/test.js +++ b/tests/test.js @@ -127,3 +127,19 @@ test('pino caller can make stack adjustments', function(t) { } log.info('test') }) + +test('pino caller stack trace line number maps correctly', function (t) { + t.plan(4) + + const pinoInstance = pinoCaller(pino(through2(function (chunk, enc, callback) { + const res = JSON.parse(chunk.toString('utf8')) + const regex = /Test. \(\/(?:.)*tests\/test.js:(\d+)/ + const matches = regex.exec(res.caller || '') + t.ok(res.caller, 'caller property is set') + t.equal(typeof res.caller, 'string', 'caller property is a string') + t.ok(matches, 'caller property matches the test regex') + t.ok(parseInt(matches[1], 10) > 1, 'line number in stack trace is greater than 1') + }))) + + pinoInstance.fatal('test') +})