From 608fca962b34e2bda841db9a4416bab6b4a62803 Mon Sep 17 00:00:00 2001 From: Qix Date: Wed, 13 Nov 2019 11:27:24 +0100 Subject: [PATCH 01/43] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 3c5c9a92..58858535 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -14,4 +14,15 @@ your project. For more information, please see: https://github.com/sindresorhus/ama/issues/446#issuecomment-281014491 +Please keep in mind that `debug` is downloaded, +installed, transpiled and used millions of times +*per day*. If you have an error with `debug`, it's +most likely your own configuration (e.g. with Babel, +Webpack, etc). + +Unless you post ample evidence you have tried +to fix this yourself, it will most likely +be determined that your issue is localized +to your project - not `debug`. + --> From 3f4d7247c0f57085c3d8450593b22ecd7ef73886 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 7 Jan 2020 20:38:20 -0500 Subject: [PATCH 02/43] Add "engines" to `package.json` (#680) --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 643af019..5e9d45e2 100644 --- a/package.json +++ b/package.json @@ -47,5 +47,8 @@ "xo": "^0.23.0" }, "main": "./src/index.js", - "browser": "./src/browser.js" + "browser": "./src/browser.js", + "engines": { + "node": ">=6.0" + } } From 4acdeedd4b532f0b5a86b35019e0bc9f081d04b4 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 12 Jan 2020 20:29:28 +0100 Subject: [PATCH 03/43] run linter inside of test script --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5e9d45e2..85b6f1d6 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "license": "MIT", "scripts": { "lint": "xo", - "test": "npm run test:node && npm run test:browser", + "test": "npm run test:node && npm run test:browser && npm run lint", "test:node": "istanbul cover _mocha -- test.js", "test:browser": "karma start --single-run", "test:coverage": "cat ./coverage/lcov.info | coveralls" @@ -49,6 +49,6 @@ "main": "./src/index.js", "browser": "./src/browser.js", "engines": { - "node": ">=6.0" + "node": ">=6.0" } } From 0c1d5180ff9559b506c8b431b24842bed0e8a5e2 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 12 Jan 2020 20:31:27 +0100 Subject: [PATCH 04/43] remove dead code and fix lowercase comment (for linter) --- src/common.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/common.js b/src/common.js index 2f82b8dc..32b4fd62 100644 --- a/src/common.js +++ b/src/common.js @@ -120,10 +120,8 @@ function setup(env) { debug.color = selectColor(namespace); debug.destroy = destroy; debug.extend = extend; - // Debug.formatArgs = formatArgs; - // debug.rawLog = rawLog; - // env-specific initialization logic for debug instances + // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } From 6b07f9e50a528b6b47256d876f7e77374c337333 Mon Sep 17 00:00:00 2001 From: Milan Skuhra Date: Sun, 23 Feb 2020 20:07:49 +0100 Subject: [PATCH 05/43] Fixes: Unable to take control over selectColor #747 --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 32b4fd62..da7eada6 100644 --- a/src/common.js +++ b/src/common.js @@ -117,7 +117,7 @@ function setup(env) { debug.namespace = namespace; debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = selectColor(namespace); + debug.color = createDebug.selectColor(namespace); debug.destroy = destroy; debug.extend = extend; From db306db99e7822d355724698990d335927563210 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Fri, 27 Mar 2020 12:28:00 -0400 Subject: [PATCH 06/43] Update and pin ms to 2.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85b6f1d6..b20770f2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test:coverage": "cat ./coverage/lcov.info | coveralls" }, "dependencies": { - "ms": "^2.1.1" + "ms": "2.1.2" }, "devDependencies": { "brfs": "^2.0.1", From 09914af00e4c1479db9aa160bc51cb8c7e063ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Wed, 16 Oct 2019 16:55:00 +0200 Subject: [PATCH 07/43] Marks supports-color as an *optional* peer dependency --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index b20770f2..f9dd28e7 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,11 @@ "mocha-lcov-reporter": "^1.2.0", "xo": "^0.23.0" }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + }, "main": "./src/index.js", "browser": "./src/browser.js", "engines": { From 80ef62a3af4df95250d77d64edfc3d0e1667e7e8 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 19 May 2020 11:36:58 +0200 Subject: [PATCH 08/43] 4.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f9dd28e7..c270ca0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.1.0", + "version": "4.2.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 22e13fe07e21f32888201aa40833599fd10a4fbb Mon Sep 17 00:00:00 2001 From: "Bruce A. MacNaughton" Date: Mon, 6 Apr 2020 13:37:14 -0700 Subject: [PATCH 09/43] fix quoted percent sign --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index da7eada6..a7eeb0b1 100644 --- a/src/common.js +++ b/src/common.js @@ -92,7 +92,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return match; + return '%'; } index++; const formatter = createDebug.formatters[format]; From 27152cad248df54217a14c072e7be1cd16da5f6d Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 12 Jan 2020 20:10:16 +0100 Subject: [PATCH 10/43] add test for enable/disable of existing instances --- test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test.js b/test.js index f61e079b..a1d6f633 100644 --- a/test.js +++ b/test.js @@ -117,5 +117,24 @@ describe('debug', () => { assert.deepStrictEqual(oldNames.map(String), debug.names.map(String)); assert.deepStrictEqual(oldSkips.map(String), debug.skips.map(String)); }); + + it('handles re-enabling existing instances', () => { + debug.disable('*'); + const inst = debug('foo'); + const messages = []; + inst.log = msg => messages.push(msg.replace(/^[^@]*@([^@]+)@.*$/, '$1')); + + inst('@test@'); + assert.deepStrictEqual(messages, []); + debug.enable('foo'); + assert.deepStrictEqual(messages, []); + inst('@test2@'); + assert.deepStrictEqual(messages, ['test2']); + inst('@test3@'); + assert.deepStrictEqual(messages, ['test2', 'test3']); + debug.disable('*'); + inst('@test4@'); + assert.deepStrictEqual(messages, ['test2', 'test3']); + }); }); }); From 72e7f864bd75fc8353e4dd450de96d9104ba9f35 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 12 Jan 2020 20:14:48 +0100 Subject: [PATCH 11/43] fix memory leak within debug instance --- src/common.js | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/common.js b/src/common.js index a7eeb0b1..9d7e4dce 100644 --- a/src/common.js +++ b/src/common.js @@ -17,11 +17,6 @@ function setup(env) { createDebug[key] = env[key]; }); - /** - * Active `debug` instances. - */ - createDebug.instances = []; - /** * The currently active debug mode names, and names to skip. */ @@ -63,6 +58,7 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; + let enableOverride = null; function debug(...args) { // Disabled? @@ -115,31 +111,27 @@ function setup(env) { } debug.namespace = namespace; - debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); debug.color = createDebug.selectColor(namespace); - debug.destroy = destroy; debug.extend = extend; + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); + // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } - createDebug.instances.push(debug); - return debug; } - function destroy() { - const index = createDebug.instances.indexOf(this); - if (index !== -1) { - createDebug.instances.splice(index, 1); - return true; - } - return false; - } - function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -177,11 +169,6 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } - - for (i = 0; i < createDebug.instances.length; i++) { - const instance = createDebug.instances[i]; - instance.enabled = createDebug.enabled(instance.namespace); - } } /** From e2d3bc9e428bdd45adb8d6e7f8ab543bee54d9a6 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 12 Jan 2020 20:25:37 +0100 Subject: [PATCH 12/43] add deprecation notice for debug.destroy() --- src/browser.js | 10 ++++++++++ src/common.js | 10 ++++++++++ src/node.js | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/src/browser.js b/src/browser.js index ac3f7e13..cd0fc35d 100644 --- a/src/browser.js +++ b/src/browser.js @@ -9,6 +9,16 @@ exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); /** * Colors. diff --git a/src/common.js b/src/common.js index 9d7e4dce..392a8e00 100644 --- a/src/common.js +++ b/src/common.js @@ -12,6 +12,7 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); + createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; @@ -114,6 +115,7 @@ function setup(env) { debug.useColors = createDebug.useColors(); debug.color = createDebug.selectColor(namespace); debug.extend = extend; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. Object.defineProperty(debug, 'enabled', { enumerable: true, @@ -243,6 +245,14 @@ function setup(env) { return val; } + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + createDebug.enable(createDebug.load()); return createDebug; diff --git a/src/node.js b/src/node.js index 5e1f1541..12a11f40 100644 --- a/src/node.js +++ b/src/node.js @@ -15,6 +15,10 @@ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; +exports.destroy = util.deprecate( + () => {}, + 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.' +); /** * Colors. From 3f56313c1e4a0d59c1054fb9b10026b6903bfba7 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 19 Sep 2020 10:35:28 +0200 Subject: [PATCH 13/43] 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c270ca0e..c4e19aa1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.2.0", + "version": "4.3.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From b6d12fdbc63b483e5c969da33ea6adc09946b5ac Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 19 Nov 2020 12:31:16 +0100 Subject: [PATCH 14/43] fix regression --- src/node.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 12a11f40..79bc085c 100644 --- a/src/node.js +++ b/src/node.js @@ -248,7 +248,9 @@ const {formatters} = module.exports; formatters.o = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts) - .replace(/\s*\n\s*/g, ' '); + .split('\n') + .map(str => str.trim()) + .join(' '); }; /** From 0d3d66b0eb47c5d34e1a940e8a204446fdd832cd Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 19 Nov 2020 13:15:13 +0100 Subject: [PATCH 15/43] 4.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4e19aa1..da809d2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.0", + "version": "4.3.1", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 1e9d38c2e6e170abde6cfeaf7b2024d8b456f906 Mon Sep 17 00:00:00 2001 From: omg Date: Wed, 9 Dec 2020 17:34:56 +0200 Subject: [PATCH 16/43] cache enabled status per-logger (#799) Co-authored-by: Qix --- src/common.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 392a8e00..50ce2925 100644 --- a/src/common.js +++ b/src/common.js @@ -60,6 +60,8 @@ function setup(env) { function createDebug(namespace) { let prevTime; let enableOverride = null; + let namespacesCache; + let enabledCache; function debug(...args) { // Disabled? @@ -120,7 +122,17 @@ function setup(env) { Object.defineProperty(debug, 'enabled', { enumerable: true, configurable: false, - get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + get: () => { + if (enableOverride !== null) { + return enableOverride; + } + if (namespacesCache !== createDebug.namespaces) { + namespacesCache = createDebug.namespaces; + enabledCache = createDebug.enabled(namespace); + } + + return enabledCache; + }, set: v => { enableOverride = v; } @@ -149,6 +161,7 @@ function setup(env) { */ function enable(namespaces) { createDebug.save(namespaces); + createDebug.namespaces = namespaces; createDebug.names = []; createDebug.skips = []; From e47f96de3de5921584364b4ac91e2769d22a3b1f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 9 Dec 2020 16:35:38 +0100 Subject: [PATCH 17/43] 4.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da809d2b..b7d70acb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.1", + "version": "4.3.2", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From d177f2bc36d3b8b8e9b1b006727ef5e04f98eac7 Mon Sep 17 00:00:00 2001 From: Taylor Everding Date: Fri, 21 May 2021 13:51:30 -0600 Subject: [PATCH 18/43] Remove accidental epizeuxis --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 50ce2925..6d571d28 100644 --- a/src/common.js +++ b/src/common.js @@ -34,7 +34,7 @@ function setup(env) { /** * Selects a color for a debug namespace - * @param {String} namespace The namespace string for the for the debug instance to be colored + * @param {String} namespace The namespace string for the debug instance to be colored * @return {Number|String} An ANSI color code for the given namespace * @api private */ From f851b00eb006d400e757dca33568773910365519 Mon Sep 17 00:00:00 2001 From: Kristof Kalocsai Date: Wed, 13 Oct 2021 21:14:14 +0200 Subject: [PATCH 19/43] adds README section regarding usage in child procs (#850) * adds README section regarding usage in child procs code example and original request copied from @aaarichter should close #811 * Update README.md Co-authored-by: Qix Co-authored-by: Qix --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 88dae35d..3b168838 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,27 @@ if (debug.enabled) { You can also manually toggle this property to force the debug instance to be enabled or disabled. +## Usage in child processes + +Due to the way `debug` detects if the output is a TTY or not, colors are not shown in child processes when `stderr` is piped. A solution is to pass the `DEBUG_COLORS=1` environment variable to the child process. +For example: + +```javascript +worker = fork(WORKER_WRAP_PATH, [workerPath], { + stdio: [ + /* stdin: */ 0, + /* stdout: */ 'pipe', + /* stderr: */ 'pipe', + 'ipc', + ], + env: Object.assign({}, process.env, { + DEBUG_COLORS: 1 // without this settings, colors won't be shown + }), +}); + +worker.stderr.pipe(process.stderr, { end: false }); +``` + ## Authors From 19b36c052ab0084f8b1c86d34d3e82190680246a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 27 Nov 2021 14:00:16 +0100 Subject: [PATCH 20/43] update repository location + maintainership information --- README.md | 2 +- package.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b168838..3457f655 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # debug -[![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) +[![Build Status](https://travis-ci.org/debug-js/debug.svg?branch=master)](https://travis-ci.org/debug-js/debug) [![Coverage Status](https://coveralls.io/repos/github/debug-js/debug/badge.svg?branch=master)](https://coveralls.io/github/debug-js/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors) diff --git a/package.json b/package.json index b7d70acb..9cd2a2d7 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "4.3.2", "repository": { "type": "git", - "url": "git://github.com/visionmedia/debug.git" + "url": "git://github.com/debug-js/debug.git" }, - "description": "small debugging utility", + "description": "Lightweight debugging utility for Node.js and the browser", "keywords": [ "debug", "log", @@ -16,11 +16,11 @@ "LICENSE", "README.md" ], - "author": "TJ Holowaychuk ", + "author": "Josh Junon ", "contributors": [ + "TJ Holowaychuk ", "Nathan Rajlich (http://n8.io)", - "Andrew Rhyne ", - "Josh Junon " + "Andrew Rhyne " ], "license": "MIT", "scripts": { From 4079aae5b5bf1198ecd2e1032609dfd46bec843f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 27 Nov 2021 14:01:16 +0100 Subject: [PATCH 21/43] update license and more maintainership information --- LICENSE | 19 ++++++++++--------- README.md | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/LICENSE b/LICENSE index 658c933d..1a9820e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,19 +1,20 @@ (The MIT License) -Copyright (c) 2014 TJ Holowaychuk +Copyright (c) 2014-2017 TJ Holowaychuk +Copyright (c) 2018-2021 Josh Junon -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the 'Software'), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the 'Software'), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 3457f655..5ea4cd27 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,7 @@ worker.stderr.pipe(process.stderr, { end: false }); - TJ Holowaychuk - Nathan Rajlich - Andrew Rhyne + - Josh Junon ## Backers @@ -455,6 +456,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s (The MIT License) Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca> +Copyright (c) 2018-2021 Josh Junon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 043d3cd17d30af45f71d2beab4ec7abfc9936e9e Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 27 Nov 2021 14:01:35 +0100 Subject: [PATCH 22/43] 4.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9cd2a2d7..cb7efa8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.2", + "version": "4.3.3", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From c0805cc4d3b2c7c987567e99ecaec78840516d7b Mon Sep 17 00:00:00 2001 From: gitname Date: Wed, 2 Feb 2022 16:34:39 -0800 Subject: [PATCH 23/43] add section about configuring JS console to show debug messages (#866) * Add section about configuring JS console to show debug messages * Rewrite log level section to be more concise --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5ea4cd27..e9c3e047 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,9 @@ setInterval(function(){ }, 1200); ``` +In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScript console will—by default—only show messages logged by `debug` if the "Verbose" log level is _enabled_. + + ## Output streams From 9b334123f1331a252bc27c99c33b5c4f199d200f Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Thu, 17 Mar 2022 14:36:24 +0100 Subject: [PATCH 24/43] replace deprecated String.prototype.substr() (#876) String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated. Signed-off-by: Tobias Speicher --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 6d571d28..e3291b20 100644 --- a/src/common.js +++ b/src/common.js @@ -179,7 +179,7 @@ function setup(env) { namespaces = split[i].replace(/\*/g, '.*?'); if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$')); } else { createDebug.names.push(new RegExp('^' + namespaces + '$')); } From da66c86c5fd71ef570f36b5b1edfa4472149f1bc Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 17 Mar 2022 14:38:08 +0100 Subject: [PATCH 25/43] 4.3.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb7efa8e..3bcdc242 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.3", + "version": "4.3.4", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From 12c1ad04db972bbb40d49c952f8f8da6871c7216 Mon Sep 17 00:00:00 2001 From: Qix Date: Thu, 31 Mar 2022 17:24:37 +0200 Subject: [PATCH 26/43] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 58 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 58858535..f674f400 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,28 +1,38 @@ From d1616622e4d404863c5a98443f755b4006e971dc Mon Sep 17 00:00:00 2001 From: Qix Date: Thu, 31 Mar 2022 17:43:51 +0200 Subject: [PATCH 27/43] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index f674f400..62c47e32 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,11 +1,12 @@ diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index af3da470..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,17 +0,0 @@ - From cac39b1c5b018b0fe93a53a05f084eee543d17f5 Mon Sep 17 00:00:00 2001 From: calvintwr Date: Fri, 31 May 2024 19:34:49 +0800 Subject: [PATCH 29/43] Fix/debug depth (#926) * fix debug format options ignored * moved sinon to devDependencies --- package.json | 3 ++- src/node.js | 4 ++-- test.node.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 test.node.js diff --git a/package.json b/package.json index 3bcdc242..5da3cfeb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "scripts": { "lint": "xo", "test": "npm run test:node && npm run test:browser && npm run lint", - "test:node": "istanbul cover _mocha -- test.js", + "test:node": "istanbul cover _mocha -- test.js test.node.js", "test:browser": "karma start --single-run", "test:coverage": "cat ./coverage/lcov.info | coveralls" }, @@ -44,6 +44,7 @@ "karma-mocha": "^1.3.0", "mocha": "^5.2.0", "mocha-lcov-reporter": "^1.2.0", + "sinon": "^14.0.0", "xo": "^0.23.0" }, "peerDependenciesMeta": { diff --git a/src/node.js b/src/node.js index 79bc085c..715560a4 100644 --- a/src/node.js +++ b/src/node.js @@ -187,11 +187,11 @@ function getDate() { } /** - * Invokes `util.format()` with the specified arguments and writes to stderr. + * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr. */ function log(...args) { - return process.stderr.write(util.format(...args) + '\n'); + return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n'); } /** diff --git a/test.node.js b/test.node.js new file mode 100644 index 00000000..4cc3c051 --- /dev/null +++ b/test.node.js @@ -0,0 +1,40 @@ +/* eslint-env mocha */ + +const assert = require('assert'); +const util = require('util'); +const sinon = require('sinon'); +const debug = require('./src/node'); + +const formatWithOptionsSpy = sinon.spy(util, 'formatWithOptions'); +beforeEach(() => { + formatWithOptionsSpy.resetHistory(); +}); + +describe('debug node', () => { + describe('formatting options', () => { + it('calls util.formatWithOptions', () => { + debug.enable('*'); + const stdErrWriteStub = sinon.stub(process.stderr, 'write'); + const log = debug('formatting options'); + log('hello world'); + assert(util.formatWithOptions.callCount === 1); + stdErrWriteStub.restore(); + }); + + it('calls util.formatWithOptions with inspectOpts', () => { + debug.enable('*'); + const options = { + hideDate: true, + colors: true, + depth: 10, + showHidden: true + }; + Object.assign(debug.inspectOpts, options); + const stdErrWriteStub = sinon.stub(process.stderr, 'write'); + const log = debug('format with inspectOpts'); + log('hello world2'); + assert.deepStrictEqual(util.formatWithOptions.getCall(0).args[0], options); + stdErrWriteStub.restore(); + }); + }); +}); From f244ada2e98b30a09b42e6f85e8d4ac3f038d2d6 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 31 May 2024 13:37:01 +0200 Subject: [PATCH 30/43] update authorship contact info --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5da3cfeb..f498861c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "LICENSE", "README.md" ], - "author": "Josh Junon ", + "author": "Josh Junon (https://github.com/qix-)", "contributors": [ "TJ Holowaychuk ", "Nathan Rajlich (http://n8.io)", From 5464bdddbc6f91b2aef2ad20650d3a6cfd9fcc3a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 31 May 2024 13:37:42 +0200 Subject: [PATCH 31/43] 4.3.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f498861c..cb671038 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.4", + "version": "4.3.5", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From 7956a45f683924a1fce672dcfb15a1fb8a762c60 Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 26 Jul 2024 18:21:29 +0800 Subject: [PATCH 32/43] Avoid using deprecated RegExp.$1 --- src/browser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/browser.js b/src/browser.js index cd0fc35d..8d808e58 100644 --- a/src/browser.js +++ b/src/browser.js @@ -125,6 +125,8 @@ function useColors() { return false; } + let m; + // Is webkit? http://stackoverflow.com/a/16459606/376773 // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || @@ -132,7 +134,7 @@ function useColors() { (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || // Is firefox >= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) || // Double check webkit in userAgent just in case we are in a worker (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); } From c33b464a797d6cf8c72b8d84d87e02b2822494c9 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 27 Jul 2024 11:19:57 +0200 Subject: [PATCH 33/43] 4.3.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb671038..8eea0552 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.5", + "version": "4.3.6", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From 382864a45a782a84b29e457211c27704df77a75f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 7 Aug 2024 18:49:53 +0200 Subject: [PATCH 34/43] remove archaic badges from readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9c3e047..9ebdfbf1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # debug -[![Build Status](https://travis-ci.org/debug-js/debug.svg?branch=master)](https://travis-ci.org/debug-js/debug) [![Coverage Status](https://coveralls.io/repos/github/debug-js/debug/badge.svg?branch=master)](https://coveralls.io/github/debug-js/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors) From c63e96e6495cdb8e15d2affa8dad105c48a21c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Fri, 6 Sep 2024 02:48:50 +0200 Subject: [PATCH 35/43] Upgrade ms to version 2.1.3 (#819) * Upgrade ms to version 2.1.3 * Update package.json Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> --------- Co-authored-by: Josh Junon Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8eea0552..26146ca5 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test:coverage": "cat ./coverage/lcov.info | coveralls" }, "dependencies": { - "ms": "2.1.2" + "ms": "^2.1.3" }, "devDependencies": { "brfs": "^2.0.1", From bc60914816e5e45a5fff1cd638410438fc317521 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 6 Sep 2024 02:50:18 +0200 Subject: [PATCH 36/43] 4.3.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26146ca5..2f782eb9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.6", + "version": "4.3.7", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From d2d6bf0bab3a0eeeb3a9ce7113cb0a31d8da678f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 6 Dec 2024 13:27:40 +0100 Subject: [PATCH 37/43] fix inefficient .enable() regex and .enabled() test --- package.json | 5 +++ src/browser.js | 1 + src/common.js | 96 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 2f782eb9..f2050bc1 100644 --- a/package.json +++ b/package.json @@ -56,5 +56,10 @@ "browser": "./src/browser.js", "engines": { "node": ">=6.0" + }, + "xo": { + "rules": { + "import/extensions": "off" + } } } diff --git a/src/browser.js b/src/browser.js index 8d808e58..df8e179e 100644 --- a/src/browser.js +++ b/src/browser.js @@ -129,6 +129,7 @@ function useColors() { // Is webkit? http://stackoverflow.com/a/16459606/376773 // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + // eslint-disable-next-line no-return-assign return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || // Is firebug? http://stackoverflow.com/a/398120/376773 (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || diff --git a/src/common.js b/src/common.js index e3291b20..528c7ecf 100644 --- a/src/common.js +++ b/src/common.js @@ -166,24 +166,62 @@ function setup(env) { createDebug.names = []; createDebug.skips = []; - let i; - const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); - const len = split.length; - - for (i = 0; i < len; i++) { - if (!split[i]) { - // ignore empty strings - continue; + const split = (typeof namespaces === 'string' ? namespaces : '') + .trim() + .replace(' ', ',') + .split(',') + .filter(Boolean); + + for (const ns of split) { + if (ns[0] === '-') { + createDebug.skips.push(ns.slice(1)); + } else { + createDebug.names.push(ns); } + } + } - namespaces = split[i].replace(/\*/g, '.*?'); - - if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$')); + /** + * Checks if the given string matches a namespace template, honoring + * asterisks as wildcards. + * + * @param {String} search + * @param {String} template + * @return {Boolean} + */ + function matchesTemplate(search, template) { + let searchIndex = 0; + let templateIndex = 0; + let starIndex = -1; + let matchIndex = 0; + + while (searchIndex < search.length) { + if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) { + // Match character or proceed with wildcard + if (template[templateIndex] === '*') { + starIndex = templateIndex; + matchIndex = searchIndex; + templateIndex++; // Skip the '*' + } else { + searchIndex++; + templateIndex++; + } + } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition + // Backtrack to the last '*' and try to match more characters + templateIndex = starIndex + 1; + matchIndex++; + searchIndex = matchIndex; } else { - createDebug.names.push(new RegExp('^' + namespaces + '$')); + return false; // No match } } + + // Handle trailing '*' in template + while (templateIndex < template.length && template[templateIndex] === '*') { + templateIndex++; + } + + return templateIndex === template.length; } /** @@ -194,8 +232,8 @@ function setup(env) { */ function disable() { const namespaces = [ - ...createDebug.names.map(toNamespace), - ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) + ...createDebug.names, + ...createDebug.skips.map(namespace => '-' + namespace) ].join(','); createDebug.enable(''); return namespaces; @@ -209,21 +247,14 @@ function setup(env) { * @api public */ function enabled(name) { - if (name[name.length - 1] === '*') { - return true; - } - - let i; - let len; - - for (i = 0, len = createDebug.skips.length; i < len; i++) { - if (createDebug.skips[i].test(name)) { + for (const skip of createDebug.skips) { + if (matchesTemplate(name, skip)) { return false; } } - for (i = 0, len = createDebug.names.length; i < len; i++) { - if (createDebug.names[i].test(name)) { + for (const ns of createDebug.names) { + if (matchesTemplate(name, ns)) { return true; } } @@ -231,19 +262,6 @@ function setup(env) { return false; } - /** - * Convert regexp to namespace - * - * @param {RegExp} regxep - * @return {String} namespace - * @api private - */ - function toNamespace(regexp) { - return regexp.toString() - .substring(2, regexp.toString().length - 2) - .replace(/\.\*\?$/, '*'); - } - /** * Coerce `val`. * From 7e3814cc603bf64fdd69e714e0cf5611ec31f43b Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 6 Dec 2024 13:30:15 +0100 Subject: [PATCH 38/43] 4.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2050bc1..60dfcf57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.3.7", + "version": "4.4.0", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From a0497bd46dacb701437f62cfc065dc72bf0952c7 Mon Sep 17 00:00:00 2001 From: Prabhat Dahal Date: Fri, 21 Mar 2025 10:44:33 -0500 Subject: [PATCH 39/43] Replace whitespaces in namespaces string with commas globally instead of just the first space occurrence. (#997) Co-authored-by: Prabhat Dahal --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 528c7ecf..141cb578 100644 --- a/src/common.js +++ b/src/common.js @@ -168,7 +168,7 @@ function setup(env) { const split = (typeof namespaces === 'string' ? namespaces : '') .trim() - .replace(' ', ',') + .replace(/\s+/g, ',') .split(',') .filter(Boolean); From bf2f574c3e588ce4b660bf4e392e7a5e788640c0 Mon Sep 17 00:00:00 2001 From: Luke Zilioli Date: Sun, 23 Mar 2025 18:28:01 -0400 Subject: [PATCH 40/43] fixes #987 fallback to localStorage.DEBUG if debug is not defined (#988) --- src/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser.js b/src/browser.js index df8e179e..5993451b 100644 --- a/src/browser.js +++ b/src/browser.js @@ -219,7 +219,7 @@ function save(namespaces) { function load() { let r; try { - r = exports.storage.getItem('debug'); + r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ; } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? From 98df33ed9d5215c1d801b74e6ab00969759a6839 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 13 May 2025 22:53:29 +0200 Subject: [PATCH 41/43] remove istanbul --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 60dfcf57..20d2b670 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "scripts": { "lint": "xo", "test": "npm run test:node && npm run test:browser && npm run lint", - "test:node": "istanbul cover _mocha -- test.js test.node.js", + "test:node": "mocha test.js test.node.js", "test:browser": "karma start --single-run", "test:coverage": "cat ./coverage/lcov.info | coveralls" }, @@ -37,7 +37,6 @@ "brfs": "^2.0.1", "browserify": "^16.2.3", "coveralls": "^3.0.2", - "istanbul": "^0.4.5", "karma": "^3.1.4", "karma-browserify": "^6.0.0", "karma-chrome-launcher": "^2.2.0", From 33330fa8616b9b33f29f7674747be77266878ba6 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 13 May 2025 22:55:39 +0200 Subject: [PATCH 42/43] 4.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20d2b670..afc2f8b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.4.0", + "version": "4.4.1", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git" From 6b2c5fbdb7d414483d9e306ef234acb4cd7ea67c Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sat, 13 Sep 2025 19:24:41 +0200 Subject: [PATCH 43/43] 4.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index afc2f8b6..ee8abb52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.4.1", + "version": "4.4.3", "repository": { "type": "git", "url": "git://github.com/debug-js/debug.git"