Skip to content

Commit

Permalink
fix: replace debug module with node builtin debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Feb 25, 2024
1 parent 991a8f3 commit f5eff86
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 76 deletions.
3 changes: 1 addition & 2 deletions lib/back.js
Expand Up @@ -9,10 +9,9 @@ const {
removeAll: cleanAll,
} = require('./intercept')
const { loadDefs, define } = require('./scope')

const { back: debug } = require('./debug')
const { format } = require('util')
const path = require('path')
const debug = require('debug')('nock.back')

let _mode = null

Expand Down
2 changes: 1 addition & 1 deletion lib/common.js
@@ -1,6 +1,6 @@
'use strict'

const debug = require('debug')('nock.common')
const { common: debug } = require('./debug')
const timers = require('timers')
const url = require('url')
const util = require('util')
Expand Down
12 changes: 12 additions & 0 deletions lib/debug.js
@@ -0,0 +1,12 @@
'use strict'

const { debuglog } = require('util')

module.exports.back = debuglog('nock:back')
module.exports.common = debuglog('nock:common')
module.exports.intercept = debuglog('nock:intercept')
module.exports.request_overrider = debuglog('nock:request_overrider')
module.exports.playback_interceptor = debuglog('nock:playback_interceptor')
module.exports.recorder = debuglog('nock:recorder')
module.exports.socket = debuglog('nock:socket')
module.exports.scopeDebuglog = namespace => debuglog(`nock:scope:${namespace}`)
2 changes: 1 addition & 1 deletion lib/intercept.js
Expand Up @@ -8,7 +8,7 @@ const { InterceptedRequestRouter } = require('./intercepted_request_router')
const common = require('./common')
const { inherits } = require('util')
const http = require('http')
const debug = require('debug')('nock.intercept')
const { intercept: debug } = require('./debug')
const globalEmitter = require('./global_emitter')
const { createResponse } = require('./create_response')

Expand Down
2 changes: 1 addition & 1 deletion lib/intercepted_request_router.js
@@ -1,6 +1,6 @@
'use strict'

const debug = require('debug')('nock.request_overrider')
const { request_overrider: debug } = require('./debug')
const {
IncomingMessage,
ClientRequest,
Expand Down
8 changes: 1 addition & 7 deletions lib/interceptor.js
Expand Up @@ -243,13 +243,7 @@ module.exports = class Interceptor {

match(req, options, body) {
// check if the logger is enabled because the stringifies can be expensive.
if (this.scope.logger.enabled) {
this.scope.logger(
'attempting match %s, body = %s',
stringify(options),
stringify(body),
)
}
this.scope.logger('attempting match %o, body = %o', options, body)

const method = (options.method || 'GET').toUpperCase()
let { path = '/' } = options
Expand Down
2 changes: 1 addition & 1 deletion lib/playback_interceptor.js
Expand Up @@ -3,7 +3,7 @@
const stream = require('stream')
const util = require('util')
const zlib = require('zlib')
const debug = require('debug')('nock.playback_interceptor')
const { playback_interceptor: debug } = require('./debug')
const common = require('./common')

function parseJSONRequestBody(req, requestBody) {
Expand Down
2 changes: 1 addition & 1 deletion lib/recorder.js
@@ -1,6 +1,6 @@
'use strict'

const debug = require('debug')('nock.recorder')
const { recorder: debug } = require('./debug')
const querystring = require('querystring')
const { inspect } = require('util')

Expand Down
4 changes: 2 additions & 2 deletions lib/scope.js
Expand Up @@ -3,11 +3,11 @@
/**
* @module nock/scope
*/
const { scopeDebuglog } = require('./debug')
const { addInterceptor, isOn } = require('./intercept')
const common = require('./common')
const assert = require('assert')
const url = require('url')
const debug = require('debug')('nock.scope')
const { EventEmitter } = require('events')
const Interceptor = require('./interceptor')

Expand Down Expand Up @@ -99,7 +99,7 @@ class Scope extends EventEmitter {
logNamespace = this.urlParts.host
}

this.logger = debug.extend(logNamespace)
this.logger = scopeDebuglog(logNamespace)
}

add(key, interceptor) {
Expand Down
2 changes: 1 addition & 1 deletion lib/socket.js
@@ -1,7 +1,7 @@
'use strict'

const { EventEmitter } = require('events')
const debug = require('debug')('nock.socket')
const { socket: debug } = require('./debug')

module.exports = class Socket extends EventEmitter {
constructor(options) {
Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -22,7 +22,6 @@
"main": "./index.js",
"types": "types",
"dependencies": {
"debug": "^4.1.0",
"json-stringify-safe": "^5.0.1",
"propagate": "^2.0.0"
},
Expand Down
55 changes: 0 additions & 55 deletions tests/got/test_logging.js

This file was deleted.

0 comments on commit f5eff86

Please sign in to comment.