Skip to content

Commit

Permalink
fix: remove source-map-support package in favor of native NodeJS support
Browse files Browse the repository at this point in the history
  • Loading branch information
schnz committed Jul 22, 2024
1 parent 329bb04 commit cccc817
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,27 @@
"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",
"pretest": "npm run lint-fix",
"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"
Expand Down
16 changes: 16 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> \(\/(?:.)*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')
})

0 comments on commit cccc817

Please sign in to comment.