Skip to content

Commit

Permalink
Merge pull request #15 from pinojs/feat/source-maps
Browse files Browse the repository at this point in the history
Add source maps support
  • Loading branch information
phra committed Feb 12, 2020
2 parents ac44483 + c4b8328 commit 8922af8
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ node_js:
- '8'
- '10'
- '12'
- '13'
script:
- npm run coverage
5 changes: 5 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
*.log
.nyc_output
module-ts.js
module-ts.js.map
12 changes: 12 additions & 0 deletions examples/module-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const pino = process.env.NODE_ENV === 'development' ? require('../')(require('pino')()) : require('pino')()

function add(n: number, m: number) {
return n + m
}

async function main() {
pino.info(add(2, 3))
}

main()

18 changes: 18 additions & 0 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "examples",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "tsc -sourcemap module-ts.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^12.7.5",
"typescript": "^3.6.3"
}
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'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 ? 2 : 3
const LINE_OFFSET = 7
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"patterns": [
"."
],
"extensions": "js"
"extensions": ["js", "ts"]
}
},
"devDependencies": {
Expand All @@ -20,7 +20,8 @@
"pino-debug": "^1.3.0",
"standard": "^8.6.0",
"tap": "^12.0.1",
"through2": "^2.0.3"
"through2": "^2.0.3",
"typescript": "^3.7.2"
},
"peerDependencies": {
"pino": "*"
Expand All @@ -32,9 +33,17 @@
"lint-fix": "standard --fix index.js examples/*js tests/*.js",
"pretest": "npm run lint-fix",
"test": "tap tests/*.js",
"test-watch": "tap tests/*.js",
"coverage": "tap --cov tests/*.js",
"test-watch": "tap tests/*.js tests/*.ts",
"coverage": "npm run pretest && tap --node-arg=\"-r\" --node-arg=\"source-map-support/register\" --cov tests/*.js tests/*.ts",
"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"
]
}
}
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-ts.js
test-ts.js.map
18 changes: 18 additions & 0 deletions tests/test-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tap = require('tap')
import pino = require('pino')
import through2 = require('through2')
import pinoCaller = require('../')

tap.test('pino caller works with sourcemaps (typescript)', function (t) {
t.plan(3)

const pinoInstance = pinoCaller(pino(through2(function (chunk, enc, callback) {
const res = JSON.parse(chunk.toString('utf8'))
const regex = /Test.<anonymous> \(\/(.)*tests\/test-ts.ts/
t.ok(res.caller, 'caller property is set')
t.equal(typeof res.caller, 'string', 'caller property is a string')
t.ok(regex.test(res.caller), 'caller property matches the test regex')
})))

pinoInstance.info('test')
})

0 comments on commit 8922af8

Please sign in to comment.