Skip to content

Commit

Permalink
Issue #1735 - Programmatic Integration as a transport fails (#1739)
Browse files Browse the repository at this point in the history
* fix: Support REPL

* test: Add a unit test
  • Loading branch information
altearius committed Jun 29, 2023
1 parent 9540007 commit 3abf814
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { createRequire } = require('module')
const getCallers = require('./caller')
const { join, isAbsolute } = require('path')
const { join, isAbsolute, sep } = require('path')
const sleep = require('atomic-sleep')
const onExit = require('on-exit-leak-free')
const ThreadStream = require('thread-stream')
Expand Down Expand Up @@ -128,7 +128,11 @@ function transport (fullOptions) {

for (const filePath of callers) {
try {
fixTarget = createRequire(filePath).resolve(origin)
const context = filePath === 'node:repl'
? process.cwd() + sep
: filePath

fixTarget = createRequire(context).resolve(origin)
break
} catch (err) {
// Silent catch
Expand Down
14 changes: 14 additions & 0 deletions test/transport/repl.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const { doesNotThrow, test } = require('tap')
const proxyquire = require('proxyquire')

test('pino.transport resolves targets in REPL', async ({ same }) => {
// Arrange
const transport = proxyquire('../../lib/transport', {
'./caller': () => ['node:repl']
})

// Act / Assert
doesNotThrow(() => transport({ target: 'pino-pretty' }))
})

0 comments on commit 3abf814

Please sign in to comment.