From 207a6a2d53507ec9dd57c94c46cc7d3dd272306d Mon Sep 17 00:00:00 2001 From: Miau Lightouch Date: Thu, 26 Jul 2018 16:07:10 +0800 Subject: [PATCH 01/83] Fix nwjs support (#569) --- src/browser.js | 2 +- src/index.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/browser.js b/src/browser.js index 4d61d080..b6d94e17 100644 --- a/src/browser.js +++ b/src/browser.js @@ -39,7 +39,7 @@ function useColors() { // NB: In an Electron preload script, document will be defined but not fully // initialized. Since we know we're in Chrome, we'll just detect this case // explicitly - if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') { + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { return true; } diff --git a/src/index.js b/src/index.js index 9b44b967..a8792cc1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,10 @@ /** - * Detect Electron renderer process, which is node, but we should + * Detect Electron renderer / nwjs process, which is node, but we should * treat as a browser. */ -if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true) { + +if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) { module.exports = require('./browser.js'); } else { module.exports = require('./node.js'); From e43e5fed177b8698674748063f4ed1aaba1d59c8 Mon Sep 17 00:00:00 2001 From: Ruslan Boliev Date: Tue, 11 Sep 2018 06:06:24 +0300 Subject: [PATCH 02/83] add instance extends feature (#524) * instance extends feature * add .extend documentation * allow empty delimiter in extend --- README.md | 14 ++++++++++++++ src/common.js | 5 +++++ test/debug_spec.js | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/README.md b/README.md index b9f4b49a..0ee7634d 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,20 @@ error('now goes to stdout via console.info'); log('still goes to stdout, but via console.info now'); ``` +## Extend +You can simply extend debugger +```js +const log = require('debug')('auth'); + +//creates new debug instance with extended namespace +const logSign = log.extend('sign'); +const logLogin = log.extend('login'); + +log('hello'); // auth hello +logSign('hello'); //auth:sign hello +logLogin('hello'); //auth:login hello +``` + ## Set dynamically You can also enable debug dynamically by calling the `enable()` method : diff --git a/src/common.js b/src/common.js index 61eaf893..65713e4d 100644 --- a/src/common.js +++ b/src/common.js @@ -123,6 +123,7 @@ module.exports = function setup(env) { debug.useColors = createDebug.useColors(); debug.color = selectColor(namespace); debug.destroy = destroy; + debug.extend = extend; //debug.formatArgs = formatArgs; //debug.rawLog = rawLog; @@ -146,6 +147,10 @@ module.exports = function setup(env) { } } + function extend (namespace, delimiter) { + return createDebug(this.namespace + (typeof delimiter !== 'undefined' ? delimiter : ':') + namespace); + } + /** * Enables a debug mode by namespaces. This can include modes * separated by a colon and wildcards. diff --git a/test/debug_spec.js b/test/debug_spec.js index 142fbe79..7ac6d7cd 100644 --- a/test/debug_spec.js +++ b/test/debug_spec.js @@ -64,4 +64,30 @@ describe('debug', function () { }); }); + + describe('extend namespace', function () { + var log; + + beforeEach(function () { + debug.enable('foo'); + log = debug('foo'); + }); + + it('should extend namespace', function () { + var logBar = log.extend('bar'); + expect(logBar.namespace).to.be.equal('foo:bar'); + }); + + it('should extend namespace with custom delimiter', function () { + var logBar = log.extend('bar', '--'); + expect(logBar.namespace).to.be.equal('foo--bar'); + }); + + it('should extend namespace with empty delimiter', function () { + var logBar = log.extend('bar', ''); + expect(logBar.namespace).to.be.equal('foobar'); + }); + + }); + }); From 7e1d5d94f31b37b460fb8d88000ab7ed0be3597e Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 21:33:02 -0600 Subject: [PATCH 03/83] add yarn-error.log to .gitignore --- .gitignore | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f0cf3a35..15be2208 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,11 @@ .DS_Store -node_modules +node_modules/ *.sock -build +/build/ npm-debug.log -dist -coverage +yarn-error.log +/dist/ +/coverage/ # lockfiles yarn.lock From 853853f9f588044d76df3daf1959ca56c5f341b7 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 21:33:29 -0600 Subject: [PATCH 04/83] bump vulnerable packages --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9af3874d..4e922381 100644 --- a/package.json +++ b/package.json @@ -24,19 +24,20 @@ "browserify": "14.4.0", "chai": "^3.5.0", "concurrently": "^3.1.0", - "coveralls": "^2.11.15", + "coveralls": "^3.0.2", "eslint": "^3.12.1", "istanbul": "^0.4.5", - "karma": "^1.3.0", + "karma": "^3.0.0", "karma-chai": "^0.1.0", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.2", "karma-sinon": "^1.0.5", - "mocha": "^3.2.0", + "mocha": "^5.2.0", "mocha-lcov-reporter": "^1.2.0", "rimraf": "^2.5.4", "sinon": "^1.17.6", - "sinon-chai": "^2.8.0" + "sinon-chai": "^2.8.0", + "xo": "^0.23.0" }, "main": "./src/index.js", "browser": "./src/browser.js" From 2d2509e26bf6df1e1954267e3b1a1cb83973fb09 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 21:46:11 -0600 Subject: [PATCH 05/83] add .editorconfig --- .editorconfig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..a2be8159 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,37 @@ +root = true + +[*] +indent_style = tab +indent_size = 4 +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{*.json,*.json.example,*.gyp,*.yml,*.yaml}] +indent_style = space +indent_size = 2 + +[{*.py,*.asm}] +indent_style = space + +[*.py] +indent_size = 4 + +[*.asm] +indent_size = 8 + +[*.md] +trim_trailing_whitespace = false + +# Ideal settings - some plugins might support these. +[*.js] +quote_type = single + +[{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}] +curly_bracket_next_line = false +spaces_around_operators = true +spaces_around_brackets = outside +# close enough to 1TB +indent_brace_style = K&R From ba8a424d41e9dc6129e081ac3aa9715be6a45fbd Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 22:04:31 -0600 Subject: [PATCH 06/83] move to XO (closes #397) --- examples/node/app.js | 23 +- examples/node/colors.js | 10 +- examples/node/stdout.js | 15 +- examples/node/wildcards.js | 14 +- examples/node/worker.js | 17 +- karma.conf.js | 124 +++++----- package.json | 3 + src/browser.js | 276 ++++++++++++++-------- src/common.js | 471 +++++++++++++++++++------------------ src/index.js | 5 +- src/node.js | 236 ++++++++++++------- test/debug-spec.js | 92 ++++++++ test/debug_spec.js | 93 -------- 13 files changed, 766 insertions(+), 613 deletions(-) create mode 100644 test/debug-spec.js delete mode 100644 test/debug_spec.js diff --git a/examples/node/app.js b/examples/node/app.js index d4a19914..08d3f257 100644 --- a/examples/node/app.js +++ b/examples/node/app.js @@ -1,19 +1,20 @@ +const http = require('http'); -var debug = require('../../')('http') - , http = require('http') - , name = 'My App'; +const debug = require('../..')('http'); -// fake app +const name = 'My App'; + +// Fake app debug('booting %o', name); -http.createServer(function(req, res){ - debug(req.method + ' ' + req.url); - res.end('hello\n'); -}).listen(3000, function(){ - debug('listening'); +http.createServer((req, res) => { + debug(req.method + ' ' + req.url); + res.end('hello\n'); +}).listen(3000, () => { + debug('listening'); }); -// fake worker of some kind - +// Fake worker of some kind +// eslint-disable-next-line import/no-unassigned-import require('./worker'); diff --git a/examples/node/colors.js b/examples/node/colors.js index c144ee4e..9cbfa1f9 100644 --- a/examples/node/colors.js +++ b/examples/node/colors.js @@ -1,8 +1,8 @@ -var debug = require('../../') +const debug = require('../..'); -debug.enable('*') +debug.enable('*'); -for (var i=0; i < debug.colors.length; i++) { - const d = debug('example:' + i); - d('The color is %o', d.color); +for (let i = 0; i < debug.colors.length; i++) { + const d = debug('example:' + i); + d('The color is %o', d.color); } diff --git a/examples/node/stdout.js b/examples/node/stdout.js index c999c4c0..17558da0 100644 --- a/examples/node/stdout.js +++ b/examples/node/stdout.js @@ -1,16 +1,17 @@ -var debug = require('../../'); -var error = debug('app:error'); +const debug = require('../..'); -// by default stderr is used +const error = debug('app:error'); + +// By default stderr is used error('goes to stderr!'); -var log = debug('app:log'); -// set this namespace to log via console.log -log.log = console.log.bind(console); // don't forget to bind to console! +const log = debug('app:log'); +// Set this namespace to log via console.log +log.log = console.log.bind(console); // Don't forget to bind to console! log('goes to stdout'); error('still goes to stderr!'); -// set all output to go via console.info +// Set all output to go via console.info // overrides all per-namespace log settings debug.log = console.info.bind(console); error('now goes to stdout via console.info'); diff --git a/examples/node/wildcards.js b/examples/node/wildcards.js index ca99aeff..2cedc2d8 100644 --- a/examples/node/wildcards.js +++ b/examples/node/wildcards.js @@ -1,10 +1,10 @@ -var debug = { - foo: require('../../')('test:foo'), - bar: require('../../')('test:bar'), - baz: require('../../')('test:baz') +const debug = { + foo: require('../..')('test:foo'), + bar: require('../..')('test:bar'), + baz: require('../..')('test:baz') }; -debug.foo('foo') -debug.bar('bar') -debug.baz('baz') +debug.foo('foo'); +debug.bar('bar'); +debug.baz('baz'); diff --git a/examples/node/worker.js b/examples/node/worker.js index 07e3bc59..6f483a66 100644 --- a/examples/node/worker.js +++ b/examples/node/worker.js @@ -4,23 +4,24 @@ // DEBUG=worker:a node example/worker // DEBUG=worker:b node example/worker -var a = require('../../')('worker:a') - , b = require('../../')('worker:b'); +const a = require('../..')('worker:a'); + +const b = require('../..')('worker:b'); function work() { - a('doing lots of uninteresting work'); - setTimeout(work, Math.random() * 1000); + a('doing lots of uninteresting work'); + setTimeout(work, Math.random() * 1000); } work(); function workb() { - b('doing some work'); - setTimeout(workb, Math.random() * 2000); + b('doing some work'); + setTimeout(workb, Math.random() * 2000); } workb(); -setTimeout(function(){ - b(new Error('fail')); +setTimeout(() => { + b(new Error('fail')); }, 5000); diff --git a/karma.conf.js b/karma.conf.js index 103a82d1..82f90691 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,70 +1,60 @@ // Karma configuration // Generated on Fri Dec 16 2016 13:09:51 GMT+0000 (UTC) -module.exports = function(config) { - config.set({ - - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', - - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha', 'chai', 'sinon'], - - - // list of files / patterns to load in the browser - files: [ - 'dist/debug.js', - 'test/*spec.js' - ], - - - // list of files to exclude - exclude: [ - 'src/node.js' - ], - - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - }, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], - - - // web server port - port: 9876, - - - // enable / disable colors in the output (reporters and logs) - colors: true, - - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, - - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], - - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - }) -} +module.exports = function (config) { + config.set({ + + // Base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // Frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha', 'chai', 'sinon'], + + // List of files / patterns to load in the browser + files: [ + 'dist/debug.js', + 'test/*spec.js' + ], + + // List of files to exclude + exclude: [ + 'src/node.js' + ], + + // Preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + // Test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // Web server port + port: 9876, + + // Enable / disable colors in the output (reporters and logs) + colors: true, + + // Level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // Enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // Start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }); +}; diff --git a/package.json b/package.json index 4e922381..1f9b3640 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "url": "git://github.com/visionmedia/debug.git" }, "description": "small debugging utility", + "scripts": { + "test": "xo && mocha" + }, "keywords": [ "debug", "log", diff --git a/src/browser.js b/src/browser.js index b6d94e17..5f34c0d0 100644 --- a/src/browser.js +++ b/src/browser.js @@ -1,3 +1,5 @@ +/* eslint-env browser */ + /** * This is the web browser implementation of `debug()`. */ @@ -14,17 +16,82 @@ exports.storage = localstorage(); */ exports.colors = [ - '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', - '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', - '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', - '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', - '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', - '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', - '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', - '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', - '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', - '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', - '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33' + '#0000CC', + '#0000FF', + '#0033CC', + '#0033FF', + '#0066CC', + '#0066FF', + '#0099CC', + '#0099FF', + '#00CC00', + '#00CC33', + '#00CC66', + '#00CC99', + '#00CCCC', + '#00CCFF', + '#3300CC', + '#3300FF', + '#3333CC', + '#3333FF', + '#3366CC', + '#3366FF', + '#3399CC', + '#3399FF', + '#33CC00', + '#33CC33', + '#33CC66', + '#33CC99', + '#33CCCC', + '#33CCFF', + '#6600CC', + '#6600FF', + '#6633CC', + '#6633FF', + '#66CC00', + '#66CC33', + '#9900CC', + '#9900FF', + '#9933CC', + '#9933FF', + '#99CC00', + '#99CC33', + '#CC0000', + '#CC0033', + '#CC0066', + '#CC0099', + '#CC00CC', + '#CC00FF', + '#CC3300', + '#CC3333', + '#CC3366', + '#CC3399', + '#CC33CC', + '#CC33FF', + '#CC6600', + '#CC6633', + '#CC9900', + '#CC9933', + '#CCCC00', + '#CCCC33', + '#FF0000', + '#FF0033', + '#FF0066', + '#FF0099', + '#FF00CC', + '#FF00FF', + '#FF3300', + '#FF3333', + '#FF3366', + '#FF3399', + '#FF33CC', + '#FF33FF', + '#FF6600', + '#FF6633', + '#FF9900', + '#FF9933', + '#FFCC00', + '#FFCC33' ]; /** @@ -35,29 +102,30 @@ exports.colors = [ * TODO: add a `localStorage` variable to explicitly enable/disable colors */ +// eslint-disable-next-line complexity function useColors() { - // NB: In an Electron preload script, document will be defined but not fully - // initialized. Since we know we're in Chrome, we'll just detect this case - // explicitly - if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { - return true; - } - - // Internet Explorer and Edge do not support colors. - if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { - return false; - } - - // 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) || - // is firebug? http://stackoverflow.com/a/398120/376773 - (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) || - // double check webkit in userAgent just in case we are in a worker - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { + return true; + } + + // Internet Explorer and Edge do not support colors. + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } + + // 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) || + // Is firebug? http://stackoverflow.com/a/398120/376773 + (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) || + // Double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); } /** @@ -67,36 +135,38 @@ function useColors() { */ function formatArgs(args) { - var useColors = this.useColors; - - args[0] = (useColors ? '%c' : '') - + this.namespace - + (useColors ? ' %c' : ' ') - + args[0] - + (useColors ? '%c ' : ' ') - + '+' + module.exports.humanize(this.diff); - - if (!useColors) return; - - var c = 'color: ' + this.color; - args.splice(1, 0, c, 'color: inherit') - - // the final "%c" is somewhat tricky, because there could be other - // arguments passed either before or after the %c, so we need to - // figure out the correct index to insert the CSS into - var index = 0; - var lastC = 0; - args[0].replace(/%[a-zA-Z%]/g, function(match) { - if ('%%' === match) return; - index++; - if ('%c' === match) { - // we only are interested in the *last* %c - // (the user may have provided their own) - lastC = index; - } - }); - - args.splice(lastC, 0, c); + args[0] = (this.useColors ? '%c' : '') + + this.namespace + + (this.useColors ? ' %c' : ' ') + + args[0] + + (this.useColors ? '%c ' : ' ') + + '+' + module.exports.humanize(this.diff); + + if (!this.useColors) { + return; + } + + const c = 'color: ' + this.color; + args.splice(1, 0, c, 'color: inherit'); + + // The final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + let index = 0; + let lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, match => { + if (match === '%%') { + return; + } + index++; + if (match === '%c') { + // We only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + + args.splice(lastC, 0, c); } /** @@ -105,13 +175,12 @@ function formatArgs(args) { * * @api public */ - -function log() { - // this hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return 'object' === typeof console - && console.log - && Function.prototype.apply.call(console.log, console, arguments); +function log(...args) { + // This hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return typeof console === 'object' && + console.log && + console.log(...args); } /** @@ -120,15 +189,17 @@ function log() { * @param {String} namespaces * @api private */ - function save(namespaces) { - try { - if (null == namespaces) { - exports.storage.removeItem('debug'); - } else { - exports.storage.setItem('debug', namespaces); - } - } catch(e) {} + try { + if (namespaces) { + exports.storage.setItem('debug', namespaces); + } else { + exports.storage.removeItem('debug'); + } + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } } /** @@ -137,19 +208,21 @@ function save(namespaces) { * @return {String} returns the previously persisted debug modes * @api private */ - function load() { - var r; - try { - r = exports.storage.getItem('debug'); - } catch(e) {} + let r; + try { + r = exports.storage.getItem('debug'); + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } - // If debug isn't set in LS, and we're in Electron, try to load $DEBUG - if (!r && typeof process !== 'undefined' && 'env' in process) { - r = process.env.DEBUG; - } + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (!r && typeof process !== 'undefined' && 'env' in process) { + r = process.env.DEBUG; + } - return r; + return r; } /** @@ -164,25 +237,28 @@ function load() { */ function localstorage() { - try { - // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context - // The Browser also has localStorage in the global context. - return localStorage; - } catch (e) {} + try { + // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context + // The Browser also has localStorage in the global context. + return localStorage; + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } } module.exports = require('./common')(exports); -var formatters = module.exports.formatters; +const {formatters} = module.exports; /** * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. */ -formatters.j = function(v) { - try { - return JSON.stringify(v); - } catch (err) { - return '[UnexpectedJSONParseError]: ' + err.message; - } +formatters.j = function (v) { + try { + return JSON.stringify(v); + } catch (error) { + return '[UnexpectedJSONParseError]: ' + error.message; + } }; diff --git a/src/common.js b/src/common.js index 65713e4d..dab9e480 100644 --- a/src/common.js +++ b/src/common.js @@ -4,237 +4,242 @@ * implementations of `debug()`. */ -module.exports = function setup(env) { - createDebug.debug = createDebug['default'] = createDebug; - createDebug.coerce = coerce; - createDebug.disable = disable; - createDebug.enable = enable; - createDebug.enabled = enabled; - createDebug.humanize = require('ms'); - - Object.keys(env).forEach(function(key) { - createDebug[key] = env[key]; - }); - - /** - * Active `debug` instances. - */ - createDebug.instances = []; - - /** - * The currently active debug mode names, and names to skip. - */ - - createDebug.names = []; - createDebug.skips = []; - - /** - * Map of special "%n" handling functions, for the debug "format" argument. - * - * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". - */ - - createDebug.formatters = {}; - - /** - * Select a color. - * @param {String} namespace - * @return {Number} - * @api private - */ - - function selectColor(namespace) { - var hash = 0, i; - - for (i in namespace) { - hash = ((hash << 5) - hash) + namespace.charCodeAt(i); - hash |= 0; // Convert to 32bit integer - } - - return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; - } - createDebug.selectColor = selectColor; - - /** - * Create a debugger with the given `namespace`. - * - * @param {String} namespace - * @return {Function} - * @api public - */ - - function createDebug(namespace) { - var prevTime; - - function debug() { - // disabled? - if (!debug.enabled) return; - - var self = debug; - - // set `diff` timestamp - var curr = +new Date(); - var ms = curr - (prevTime || curr); - self.diff = ms; - self.prev = prevTime; - self.curr = curr; - prevTime = curr; - - // turn the `arguments` into a proper Array - var args = new Array(arguments.length); - for (var i = 0; i < args.length; i++) { - args[i] = arguments[i]; - } - - args[0] = createDebug.coerce(args[0]); - - if ('string' !== typeof args[0]) { - // anything else let's inspect with %O - args.unshift('%O'); - } - - // apply any `formatters` transformations - var index = 0; - args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { - // if we encounter an escaped % then don't increase the array index - if (match === '%%') return match; - index++; - var formatter = createDebug.formatters[format]; - if ('function' === typeof formatter) { - var val = args[index]; - match = formatter.call(self, val); - - // now we need to remove `args[index]` since it's inlined in the `format` - args.splice(index, 1); - index--; - } - return match; - }); - - // apply env-specific formatting (colors, etc.) - createDebug.formatArgs.call(self, args); - - var logFn = self.log || createDebug.log; - logFn.apply(self, args); - } - - debug.namespace = namespace; - debug.enabled = createDebug.enabled(namespace); - debug.useColors = createDebug.useColors(); - debug.color = selectColor(namespace); - debug.destroy = destroy; - debug.extend = extend; - //debug.formatArgs = formatArgs; - //debug.rawLog = rawLog; - - // env-specific initialization logic for debug instances - if ('function' === typeof createDebug.init) { - createDebug.init(debug); - } - - createDebug.instances.push(debug); - - return debug; - } - - function destroy () { - var index = createDebug.instances.indexOf(this); - if (index !== -1) { - createDebug.instances.splice(index, 1); - return true; - } else { - return false; - } - } - - function extend (namespace, delimiter) { - return createDebug(this.namespace + (typeof delimiter !== 'undefined' ? delimiter : ':') + namespace); - } - - /** - * Enables a debug mode by namespaces. This can include modes - * separated by a colon and wildcards. - * - * @param {String} namespaces - * @api public - */ - - function enable(namespaces) { - createDebug.save(namespaces); - - createDebug.names = []; - createDebug.skips = []; - - var i; - var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); - var len = split.length; - - for (i = 0; i < len; i++) { - if (!split[i]) continue; // ignore empty strings - namespaces = split[i].replace(/\*/g, '.*?'); - if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); - } else { - createDebug.names.push(new RegExp('^' + namespaces + '$')); - } - } - - for (i = 0; i < createDebug.instances.length; i++) { - var instance = createDebug.instances[i]; - instance.enabled = createDebug.enabled(instance.namespace); - } - } - - /** - * Disable debug output. - * - * @api public - */ - - function disable() { - createDebug.enable(''); - } - - /** - * Returns true if the given mode name is enabled, false otherwise. - * - * @param {String} name - * @return {Boolean} - * @api public - */ - - function enabled(name) { - if (name[name.length - 1] === '*') { - return true; - } - var i, len; - for (i = 0, len = createDebug.skips.length; i < len; i++) { - if (createDebug.skips[i].test(name)) { - return false; - } - } - for (i = 0, len = createDebug.names.length; i < len; i++) { - if (createDebug.names[i].test(name)) { - return true; - } - } - return false; - } - - /** - * Coerce `val`. - * - * @param {Mixed} val - * @return {Mixed} - * @api private - */ - - function coerce(val) { - if (val instanceof Error) return val.stack || val.message; - return val; - } - - createDebug.enable(createDebug.load()); - - return createDebug; +function setup(env) { + createDebug.debug = createDebug; + createDebug.default = createDebug; + createDebug.coerce = coerce; + createDebug.disable = disable; + createDebug.enable = enable; + createDebug.enabled = enabled; + createDebug.humanize = require('ms'); + + Object.keys(env).forEach(key => { + createDebug[key] = env[key]; + }); + + /** + * Active `debug` instances. + */ + createDebug.instances = []; + + /** + * The currently active debug mode names, and names to skip. + */ + + createDebug.names = []; + createDebug.skips = []; + + /** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". + */ + createDebug.formatters = {}; + + /** + * Selects a color for a debug namespace + * @param {String} namespace The namespace string for the for the debug instance to be colored + * @return {Number|String} An ANSI color code for the given namespace + * @api private + */ + function selectColor(namespace) { + let hash = 0; + + for (let i = 0; i < namespace.length; i++) { + hash = ((hash << 5) - hash) + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; + } + createDebug.selectColor = selectColor; + + /** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ + function createDebug(namespace) { + let prevTime; + + function debug(...args) { + // Disabled? + if (!debug.enabled) { + return; + } + + const self = debug; + + // Set `diff` timestamp + const curr = Number(new Date()); + const ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + + args[0] = createDebug.coerce(args[0]); + + if (typeof args[0] !== 'string') { + // Anything else let's inspect with %O + args.unshift('%O'); + } + + // Apply any `formatters` transformations + let index = 0; + 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; + } + index++; + const formatter = createDebug.formatters[format]; + if (typeof formatter === 'function') { + const val = args[index]; + match = formatter.call(self, val); + + // Now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + + // Apply env-specific formatting (colors, etc.) + createDebug.formatArgs.call(self, args); + + const logFn = self.log || createDebug.log; + logFn.apply(self, args); + } + + debug.namespace = namespace; + debug.enabled = createDebug.enabled(namespace); + debug.useColors = createDebug.useColors(); + debug.color = selectColor(namespace); + debug.destroy = destroy; + debug.extend = extend; + // Debug.formatArgs = formatArgs; + // debug.rawLog = rawLog; + + // 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) { + return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + } + + /** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + function enable(namespaces) { + createDebug.save(namespaces); + + 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; + } + + namespaces = split[i].replace(/\*/g, '.*?'); + + if (namespaces[0] === '-') { + createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + 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); + } + } + + /** + * Disable debug output. + * + * @api public + */ + function disable() { + createDebug.enable(''); + } + + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @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)) { + return false; + } + } + + for (i = 0, len = createDebug.names.length; i < len; i++) { + if (createDebug.names[i].test(name)) { + return true; + } + } + + return false; + } + + /** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ + function coerce(val) { + if (val instanceof Error) { + return val.stack || val.message; + } + return val; + } + + createDebug.enable(createDebug.load()); + + return createDebug; } + +module.exports = setup; diff --git a/src/index.js b/src/index.js index a8792cc1..bf4c57f2 100644 --- a/src/index.js +++ b/src/index.js @@ -3,9 +3,8 @@ * treat as a browser. */ - if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) { - module.exports = require('./browser.js'); + module.exports = require('./browser.js'); } else { - module.exports = require('./node.js'); + module.exports = require('./node.js'); } diff --git a/src/node.js b/src/node.js index c13b932c..5e1f1541 100644 --- a/src/node.js +++ b/src/node.js @@ -2,8 +2,8 @@ * Module dependencies. */ -var tty = require('tty'); -var util = require('util'); +const tty = require('tty'); +const util = require('util'); /** * This is the Node.js implementation of `debug()`. @@ -20,21 +20,95 @@ exports.useColors = useColors; * Colors. */ -exports.colors = [ 6, 2, 3, 4, 5, 1 ]; +exports.colors = [6, 2, 3, 4, 5, 1]; try { - var supportsColor = require('supports-color'); - if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) { - exports.colors = [ - 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, - 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, - 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, - 205, 206, 207, 208, 209, 214, 215, 220, 221 - ]; - } -} catch (err) { - // swallow - we only care if `supports-color` is available; it doesn't have to be. + // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json) + // eslint-disable-next-line import/no-extraneous-dependencies + const supportsColor = require('supports-color'); + + if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) { + exports.colors = [ + 20, + 21, + 26, + 27, + 32, + 33, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 56, + 57, + 62, + 63, + 68, + 69, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 92, + 93, + 98, + 99, + 112, + 113, + 128, + 129, + 134, + 135, + 148, + 149, + 160, + 161, + 162, + 163, + 164, + 165, + 166, + 167, + 168, + 169, + 170, + 171, + 172, + 173, + 178, + 179, + 184, + 185, + 196, + 197, + 198, + 199, + 200, + 201, + 202, + 203, + 204, + 205, + 206, + 207, + 208, + 209, + 214, + 215, + 220, + 221 + ]; + } +} catch (error) { + // Swallow - we only care if `supports-color` is available; it doesn't have to be. } /** @@ -43,24 +117,31 @@ try { * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js */ -exports.inspectOpts = Object.keys(process.env).filter(function (key) { - return /^debug_/i.test(key); -}).reduce(function (obj, key) { - // camel-case - var prop = key - .substring(6) - .toLowerCase() - .replace(/_([a-z])/g, function (_, k) { return k.toUpperCase() }); - - // coerce string value into JS value - var val = process.env[key]; - if (/^(yes|on|true|enabled)$/i.test(val)) val = true; - else if (/^(no|off|false|disabled)$/i.test(val)) val = false; - else if (val === 'null') val = null; - else val = Number(val); - - obj[prop] = val; - return obj; +exports.inspectOpts = Object.keys(process.env).filter(key => { + return /^debug_/i.test(key); +}).reduce((obj, key) => { + // Camel-case + const prop = key + .substring(6) + .toLowerCase() + .replace(/_([a-z])/g, (_, k) => { + return k.toUpperCase(); + }); + + // Coerce string value into JS value + let val = process.env[key]; + if (/^(yes|on|true|enabled)$/i.test(val)) { + val = true; + } else if (/^(no|off|false|disabled)$/i.test(val)) { + val = false; + } else if (val === 'null') { + val = null; + } else { + val = Number(val); + } + + obj[prop] = val; + return obj; }, {}); /** @@ -68,9 +149,9 @@ exports.inspectOpts = Object.keys(process.env).filter(function (key) { */ function useColors() { - return 'colors' in exports.inspectOpts - ? Boolean(exports.inspectOpts.colors) - : tty.isatty(process.stderr.fd); + return 'colors' in exports.inspectOpts ? + Boolean(exports.inspectOpts.colors) : + tty.isatty(process.stderr.fd); } /** @@ -80,35 +161,33 @@ function useColors() { */ function formatArgs(args) { - var name = this.namespace; - var useColors = this.useColors; - - if (useColors) { - var c = this.color; - var colorCode = '\u001b[3' + (c < 8 ? c : '8;5;' + c); - var prefix = ' ' + colorCode + ';1m' + name + ' ' + '\u001b[0m'; - - args[0] = prefix + args[0].split('\n').join('\n' + prefix); - args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001b[0m'); - } else { - args[0] = getDate() + name + ' ' + args[0]; - } + const {namespace: name, useColors} = this; + + if (useColors) { + const c = this.color; + const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); + const prefix = ` ${colorCode};1m${name} \u001B[0m`; + + args[0] = prefix + args[0].split('\n').join('\n' + prefix); + args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m'); + } else { + args[0] = getDate() + name + ' ' + args[0]; + } } function getDate() { - if (exports.inspectOpts.hideDate) { - return ''; - } else { - return new Date().toISOString() + ' '; - } + if (exports.inspectOpts.hideDate) { + return ''; + } + return new Date().toISOString() + ' '; } /** * Invokes `util.format()` with the specified arguments and writes to stderr. */ -function log() { - return process.stderr.write(util.format.apply(util, arguments) + '\n'); +function log(...args) { + return process.stderr.write(util.format(...args) + '\n'); } /** @@ -117,15 +196,14 @@ function log() { * @param {String} namespaces * @api private */ - function save(namespaces) { - if (null == namespaces) { - // If you set a process.env field to null or undefined, it gets cast to the - // string 'null' or 'undefined'. Just delete instead. - delete process.env.DEBUG; - } else { - process.env.DEBUG = namespaces; - } + if (namespaces) { + process.env.DEBUG = namespaces; + } else { + // If you set a process.env field to null or undefined, it gets cast to the + // string 'null' or 'undefined'. Just delete instead. + delete process.env.DEBUG; + } } /** @@ -136,7 +214,7 @@ function save(namespaces) { */ function load() { - return process.env.DEBUG; + return process.env.DEBUG; } /** @@ -146,34 +224,34 @@ function load() { * differently for a particular `debug` instance. */ -function init (debug) { - debug.inspectOpts = {}; +function init(debug) { + debug.inspectOpts = {}; - var keys = Object.keys(exports.inspectOpts); - for (var i = 0; i < keys.length; i++) { - debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]]; - } + const keys = Object.keys(exports.inspectOpts); + for (let i = 0; i < keys.length; i++) { + debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]]; + } } module.exports = require('./common')(exports); -var formatters = module.exports.formatters; +const {formatters} = module.exports; /** * Map %o to `util.inspect()`, all on a single line. */ -formatters.o = function(v) { - this.inspectOpts.colors = this.useColors; - return util.inspect(v, this.inspectOpts) - .replace(/\s*\n\s*/g, ' '); +formatters.o = function (v) { + this.inspectOpts.colors = this.useColors; + return util.inspect(v, this.inspectOpts) + .replace(/\s*\n\s*/g, ' '); }; /** * Map %O to `util.inspect()`, allowing multiple lines if needed. */ -formatters.O = function(v) { - this.inspectOpts.colors = this.useColors; - return util.inspect(v, this.inspectOpts); +formatters.O = function (v) { + this.inspectOpts.colors = this.useColors; + return util.inspect(v, this.inspectOpts); }; diff --git a/test/debug-spec.js b/test/debug-spec.js new file mode 100644 index 00000000..08edb3b3 --- /dev/null +++ b/test/debug-spec.js @@ -0,0 +1,92 @@ +/* global describe, it, context, beforeEach */ +'use strict'; + +let chai; + +let expect; + +let debug; + +let sinon; + +let sinonChai; + +if (typeof module !== 'undefined') { + chai = require('chai'); + expect = chai.expect; + + debug = require('../src'); + sinon = require('sinon'); + sinonChai = require('sinon-chai'); + chai.use(sinonChai); +} + +describe('debug', () => { + let log = debug('test'); + + log.log = sinon.stub(); + + it('passes a basic sanity check', () => { + expect(log('hello world')).to.not.throw(); + }); + + it('allows namespaces to be a non-string value', () => { + expect(debug.enable(true)).to.not.throw(); + }); + + context('with log function', () => { + beforeEach(() => { + debug.enable('test'); + log = debug('test'); + }); + + it('uses it', () => { + log.log = sinon.stub(); + log('using custom log function'); + + expect(log.log).to.have.been.calledOnce(); + }); + }); + + describe('custom functions', () => { + let log; + + beforeEach(() => { + debug.enable('test'); + log = debug('test'); + }); + + context('with log function', () => { + it('uses it', () => { + log.log = sinon.spy(); + log('using custom log function'); + + expect(log.log).to.have.been.calledOnce(); + }); + }); + }); + + describe('extend namespace', () => { + let log; + + beforeEach(() => { + debug.enable('foo'); + log = debug('foo'); + }); + + it('should extend namespace', () => { + const logBar = log.extend('bar'); + expect(logBar.namespace).to.be.equal('foo:bar'); + }); + + it('should extend namespace with custom delimiter', () => { + const logBar = log.extend('bar', '--'); + expect(logBar.namespace).to.be.equal('foo--bar'); + }); + + it('should extend namespace with empty delimiter', () => { + const logBar = log.extend('bar', ''); + expect(logBar.namespace).to.be.equal('foobar'); + }); + }); +}); diff --git a/test/debug_spec.js b/test/debug_spec.js deleted file mode 100644 index 7ac6d7cd..00000000 --- a/test/debug_spec.js +++ /dev/null @@ -1,93 +0,0 @@ -/* global describe, it, context, beforeEach */ -'use strict'; - -var chai - , expect - , debug - , sinon - , sinonChai; - -if (typeof module !== 'undefined') { - chai = require('chai'); - expect = chai.expect; - - debug = require('../src/index'); - sinon = require('sinon'); - sinonChai = require("sinon-chai"); - chai.use(sinonChai); -} - - -describe('debug', function () { - var log = debug('test'); - - log.log = sinon.stub(); - - it('passes a basic sanity check', function () { - expect(log('hello world')).to.not.throw; - }); - - it('allows namespaces to be a non-string value', function () { - expect(debug.enable(true)).to.not.throw; - }); - - context('with log function', function () { - - beforeEach(function () { - debug.enable('test'); - log = debug('test'); - }); - - it('uses it', function () { - log.log = sinon.stub(); - log('using custom log function'); - - expect(log.log).to.have.been.calledOnce; - }); - }); - - describe('custom functions', function () { - var log; - - beforeEach(function () { - debug.enable('test'); - log = debug('test'); - }); - - context('with log function', function () { - it('uses it', function () { - log.log = sinon.spy(); - log('using custom log function'); - - expect(log.log).to.have.been.calledOnce; - }); - }); - }); - - - describe('extend namespace', function () { - var log; - - beforeEach(function () { - debug.enable('foo'); - log = debug('foo'); - }); - - it('should extend namespace', function () { - var logBar = log.extend('bar'); - expect(logBar.namespace).to.be.equal('foo:bar'); - }); - - it('should extend namespace with custom delimiter', function () { - var logBar = log.extend('bar', '--'); - expect(logBar.namespace).to.be.equal('foo--bar'); - }); - - it('should extend namespace with empty delimiter', function () { - var logBar = log.extend('bar', ''); - expect(logBar.namespace).to.be.equal('foobar'); - }); - - }); - -}); From 833b6f84c8f8dc5b6f13da38ab0ef8a8ff86c0c9 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 22:34:47 -0600 Subject: [PATCH 07/83] fix tests --- package.json | 3 -- test/debug-spec.js | 84 +++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 1f9b3640..1907cda9 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,9 @@ "karma-chai": "^0.1.0", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.2", - "karma-sinon": "^1.0.5", "mocha": "^5.2.0", "mocha-lcov-reporter": "^1.2.0", "rimraf": "^2.5.4", - "sinon": "^1.17.6", - "sinon-chai": "^2.8.0", "xo": "^0.23.0" }, "main": "./src/index.js", diff --git a/test/debug-spec.js b/test/debug-spec.js index 08edb3b3..6862497e 100644 --- a/test/debug-spec.js +++ b/test/debug-spec.js @@ -1,4 +1,4 @@ -/* global describe, it, context, beforeEach */ +/* eslint-env mocha */ 'use strict'; let chai; @@ -7,84 +7,76 @@ let expect; let debug; -let sinon; - -let sinonChai; - if (typeof module !== 'undefined') { chai = require('chai'); expect = chai.expect; - debug = require('../src'); - sinon = require('sinon'); - sinonChai = require('sinon-chai'); - chai.use(sinonChai); } describe('debug', () => { - let log = debug('test'); - - log.log = sinon.stub(); - it('passes a basic sanity check', () => { - expect(log('hello world')).to.not.throw(); + const log = debug('test'); + log.enabled = true; + log.log = () => {}; + + expect(() => log('hello world')).to.not.throw(); }); it('allows namespaces to be a non-string value', () => { - expect(debug.enable(true)).to.not.throw(); - }); + const log = debug('test'); + log.enabled = true; + log.log = () => {}; - context('with log function', () => { - beforeEach(() => { - debug.enable('test'); - log = debug('test'); - }); + expect(() => debug.enable(true)).to.not.throw(); + }); - it('uses it', () => { - log.log = sinon.stub(); - log('using custom log function'); + it('honors global debug namespace enable calls', () => { + expect(debug('test:12345').enabled).to.equal(false); + expect(debug('test:67890').enabled).to.equal(false); - expect(log.log).to.have.been.calledOnce(); - }); + debug.enable('test:12345'); + expect(debug('test:12345').enabled).to.equal(true); + expect(debug('test:67890').enabled).to.equal(false); }); - describe('custom functions', () => { - let log; + it('uses custom log function', () => { + const log = debug('test'); + log.enabled = true; - beforeEach(() => { - debug.enable('test'); - log = debug('test'); - }); + const messages = []; + log.log = (...args) => messages.push(args); - context('with log function', () => { - it('uses it', () => { - log.log = sinon.spy(); - log('using custom log function'); + log('using custom log function'); + log('using custom log function again'); + log('%O', 12345); - expect(log.log).to.have.been.calledOnce(); - }); - }); + expect(messages.length).to.equal(3); }); describe('extend namespace', () => { - let log; - - beforeEach(() => { - debug.enable('foo'); - log = debug('foo'); - }); - it('should extend namespace', () => { + const log = debug('foo'); + log.enabled = true; + log.log = () => {}; + const logBar = log.extend('bar'); expect(logBar.namespace).to.be.equal('foo:bar'); }); it('should extend namespace with custom delimiter', () => { + const log = debug('foo'); + log.enabled = true; + log.log = () => {}; + const logBar = log.extend('bar', '--'); expect(logBar.namespace).to.be.equal('foo--bar'); }); it('should extend namespace with empty delimiter', () => { + const log = debug('foo'); + log.enabled = true; + log.log = () => {}; + const logBar = log.extend('bar', ''); expect(logBar.namespace).to.be.equal('foobar'); }); From 62822f12668e8a0b1d1a4fd5a1c2fce1d8715da3 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 22:43:04 -0600 Subject: [PATCH 08/83] clean up makefile --- Makefile | 30 +++++++----------------------- package.json | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 3ddd1360..48e66bc7 100644 --- a/Makefile +++ b/Makefile @@ -15,22 +15,16 @@ YARN ?= $(shell which yarn) PKG ?= $(if $(YARN),$(YARN),$(NODE) $(shell which npm)) BROWSERIFY ?= $(NODE) $(BIN)/browserify -install: node_modules +all: lint test browser: dist/debug.js -node_modules: package.json - @NODE_ENV= $(PKG) install - @touch node_modules - -dist/debug.js: src/*.js node_modules +dist/debug.js: src/*.js @mkdir -p dist - @$(BROWSERIFY) \ - --standalone debug \ - . > dist/debug.js + @$(BROWSERIFY) --standalone debug . > dist/debug.js lint: - @eslint *.js src/*.js + @xo test-node: @istanbul cover node_modules/mocha/bin/_mocha -- test/**.js @@ -40,19 +34,9 @@ test-browser: @$(MAKE) browser @karma start --single-run -test-all: - @concurrently \ - "make test-node" \ - "make test-browser" - -test: - @if [ "x$(BROWSER)" = "x" ]; then \ - $(MAKE) test-node; \ - else \ - $(MAKE) test-browser; \ - fi +test: test-node test-browser clean: - rimraf dist coverage + rm -rf dist coverage -.PHONY: browser install clean lint test test-all test-node test-browser +.PHONY: all browser install clean lint test test-node test-browser diff --git a/package.json b/package.json index 1907cda9..c6f613c2 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,6 @@ "url": "git://github.com/visionmedia/debug.git" }, "description": "small debugging utility", - "scripts": { - "test": "xo && mocha" - }, "keywords": [ "debug", "log", @@ -28,7 +25,6 @@ "chai": "^3.5.0", "concurrently": "^3.1.0", "coveralls": "^3.0.2", - "eslint": "^3.12.1", "istanbul": "^0.4.5", "karma": "^3.0.0", "karma-chai": "^0.1.0", From 57cde56e43003f6b404d4b3d9d76b74aafaeeec8 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 23:07:20 -0600 Subject: [PATCH 09/83] fix tests --- .babelrc | 13 +++++++++++++ .travis.yml | 5 ++--- Makefile | 14 +++++++++++--- karma.conf.js | 4 ++-- package.json | 3 +++ test/debug-spec.js => test.js | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 .babelrc rename test/debug-spec.js => test.js (98%) diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..b2799de4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,13 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "chrome": "58", + "ie": "8" + } + } + ] + ] +} diff --git a/.travis.yml b/.travis.yml index 05f3dbb2..fca0ce19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,10 @@ node_js: - "10" install: - - make install + - npm install script: - - make lint - - make test + - make all matrix: include: diff --git a/Makefile b/Makefile index 48e66bc7..3651a92d 100644 --- a/Makefile +++ b/Makefile @@ -17,17 +17,25 @@ BROWSERIFY ?= $(NODE) $(BIN)/browserify all: lint test -browser: dist/debug.js +browser: dist/debug.js dist/test.js dist/debug.js: src/*.js @mkdir -p dist - @$(BROWSERIFY) --standalone debug . > dist/debug.js + @$(BROWSERIFY) --standalone debug . > $@.es6.js + @babel $@.es6.js > $@ + @rm $@.es6.js + +dist/test.js: test.js + @mkdir -p dist + @cp $< $@.es6.js + @babel $@.es6.js > $@ + @rm $@.es6.js lint: @xo test-node: - @istanbul cover node_modules/mocha/bin/_mocha -- test/**.js + @istanbul cover node_modules/mocha/bin/_mocha -- test.js @cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js test-browser: diff --git a/karma.conf.js b/karma.conf.js index 82f90691..e503df20 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,12 +9,12 @@ module.exports = function (config) { // Frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha', 'chai', 'sinon'], + frameworks: ['mocha', 'chai'], // List of files / patterns to load in the browser files: [ 'dist/debug.js', - 'test/*spec.js' + 'dist/test.js' ], // List of files to exclude diff --git a/package.json b/package.json index c6f613c2..6a15aed3 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ "ms": "^2.1.1" }, "devDependencies": { + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "@babel/preset-env": "^7.0.0", "browserify": "14.4.0", "chai": "^3.5.0", "concurrently": "^3.1.0", diff --git a/test/debug-spec.js b/test.js similarity index 98% rename from test/debug-spec.js rename to test.js index 6862497e..675d0825 100644 --- a/test/debug-spec.js +++ b/test.js @@ -10,7 +10,7 @@ let debug; if (typeof module !== 'undefined') { chai = require('chai'); expect = chai.expect; - debug = require('../src'); + debug = require('./src'); } describe('debug', () => { From 623c08ef73f8211278d5596c88041c65a2a58ee7 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 23:11:24 -0600 Subject: [PATCH 10/83] no longer checking for BROWSER=1 --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index fca0ce19..c160e8d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,3 @@ install: script: - make all - -matrix: - include: - - node_js: '8' - env: BROWSER=1 From 9f4f8f59ba745166b0c014a61c76de5e73d4841a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 23:11:33 -0600 Subject: [PATCH 11/83] remove needless command aliases in makefile --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3651a92d..663744fb 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,7 @@ PATH := node_modules/.bin:$(PATH) SHELL := /bin/bash # applications -NODE ?= $(shell which node) -YARN ?= $(shell which yarn) -PKG ?= $(if $(YARN),$(YARN),$(NODE) $(shell which npm)) -BROWSERIFY ?= $(NODE) $(BIN)/browserify +BROWSERIFY ?= $(BIN)/browserify all: lint test From 3ca23316a470f6bc6e0d75d297179cfc19bbc763 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 10 Sep 2018 23:45:28 -0600 Subject: [PATCH 12/83] clean up builds --- .npmignore | 15 --------------- Makefile | 40 ++++++++++++++++------------------------ node.js | 1 - package.json | 6 ++++++ 4 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 .npmignore delete mode 100644 node.js diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 9c93383c..00000000 --- a/.npmignore +++ /dev/null @@ -1,15 +0,0 @@ -support -test -examples -example -*.sock -dist -yarn.lock -coverage -bower.json -.coveralls.yml -.eslintrc -.travis.yml -.npmignore -karma.conf.js -Makefile diff --git a/Makefile b/Makefile index 663744fb..e28468e6 100644 --- a/Makefile +++ b/Makefile @@ -1,47 +1,39 @@ -# get Makefile directory name: http://stackoverflow.com/a/5982798/376773 +# http://stackoverflow.com/a/5982798/376773 THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) - -# BIN directory -BIN := $(THIS_DIR)/node_modules/.bin - -# Path -PATH := node_modules/.bin:$(PATH) +export PATH := $(THIS_DIR)/node_modules/.bin:$(PATH) SHELL := /bin/bash -# applications -BROWSERIFY ?= $(BIN)/browserify - all: lint test -browser: dist/debug.js dist/test.js +dist: dist/debug.js dist/test.js + +.INTERMEDIATE: dist/debug.es6.js +dist/debug.es6.js: src/*.js + @mkdir -p dist + browserify --standalone debug $< > $@ -dist/debug.js: src/*.js +dist/debug.js: dist/debug.es6.js @mkdir -p dist - @$(BROWSERIFY) --standalone debug . > $@.es6.js - @babel $@.es6.js > $@ - @rm $@.es6.js + babel $< > $@ dist/test.js: test.js @mkdir -p dist - @cp $< $@.es6.js - @babel $@.es6.js > $@ - @rm $@.es6.js + babel $< > $@ lint: - @xo + xo test-node: - @istanbul cover node_modules/mocha/bin/_mocha -- test.js + istanbul cover node_modules/mocha/bin/_mocha -- test.js @cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -test-browser: - @$(MAKE) browser - @karma start --single-run +test-browser: dist + karma start --single-run test: test-node test-browser clean: rm -rf dist coverage -.PHONY: all browser install clean lint test test-node test-browser +.PHONY: all dist clean lint test test-node test-browser diff --git a/node.js b/node.js deleted file mode 100644 index 7fc36fe6..00000000 --- a/node.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./src/node'); diff --git a/package.json b/package.json index 6a15aed3..c07c03b3 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,12 @@ "log", "debugger" ], + "files": [ + "src", + "dist/debug.js", + "LICENSE", + "README.md" + ], "author": "TJ Holowaychuk ", "contributors": [ "Nathan Rajlich (http://n8.io)", From dec4b159ddf63915c94cd9d8421ad11cd06f0e76 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 00:12:55 -0600 Subject: [PATCH 13/83] 3.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c07c03b3..1bbaa207 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "3.1.0", + "version": "3.2.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From b3f8f8e683915ef4fae3a77cbcebc6c410e65a8c Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 00:25:34 -0600 Subject: [PATCH 14/83] use babel-ified distributed source for browsers --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1bbaa207..c727ec02 100644 --- a/package.json +++ b/package.json @@ -45,5 +45,5 @@ "xo": "^0.23.0" }, "main": "./src/index.js", - "browser": "./src/browser.js" + "browser": "./dist/debug.js" } From 84e41d52acfdaa00ac724277f8c73a550be6916d Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 00:25:52 -0600 Subject: [PATCH 15/83] 3.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c727ec02..4852a37f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "3.2.0", + "version": "3.2.1", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 7fb104b8cfcbc3a91d8e4a6727638c3fe24be8d2 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 02:56:30 -0600 Subject: [PATCH 16/83] 4.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4852a37f..7b1923b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "3.2.1", + "version": "4.0.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 99c95e3d54b07a918ad65bc148a2930ea8bfdd02 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 15:35:13 -0600 Subject: [PATCH 17/83] fix browserify and supply alternative unpkg entry point (closes #606) --- Makefile | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e28468e6..5d91c19c 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ dist: dist/debug.js dist/test.js .INTERMEDIATE: dist/debug.es6.js dist/debug.es6.js: src/*.js @mkdir -p dist - browserify --standalone debug $< > $@ + browserify --standalone debug . > $@ dist/debug.js: dist/debug.es6.js @mkdir -p dist diff --git a/package.json b/package.json index 7b1923b9..8d8df5e6 100644 --- a/package.json +++ b/package.json @@ -45,5 +45,6 @@ "xo": "^0.23.0" }, "main": "./src/index.js", - "browser": "./dist/debug.js" + "browser": "./src/browser.js", + "unpkg": "./dist/debug.js" } From 4490cd95bfb952e1ed756914ac225ddc987b2ba3 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 11 Sep 2018 17:16:06 -0600 Subject: [PATCH 18/83] 4.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d8df5e6..cecd5ac5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.0.0", + "version": "4.0.1", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 4236585a40787fe60ed625452163299600df2ce6 Mon Sep 17 00:00:00 2001 From: Outsider Date: Tue, 2 Oct 2018 22:44:35 +0900 Subject: [PATCH 19/83] migrate Makefile to npm scripts Signed-off-by: Outsider --- .travis.yml | 3 ++- Makefile | 39 --------------------------------------- package.json | 13 +++++++++++++ 3 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 Makefile diff --git a/.travis.yml b/.travis.yml index c160e8d3..24682db3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,5 @@ install: - npm install script: - - make all + - npm run lint + - npm test diff --git a/Makefile b/Makefile deleted file mode 100644 index 5d91c19c..00000000 --- a/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# http://stackoverflow.com/a/5982798/376773 -THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) -THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) -export PATH := $(THIS_DIR)/node_modules/.bin:$(PATH) -SHELL := /bin/bash - -all: lint test - -dist: dist/debug.js dist/test.js - -.INTERMEDIATE: dist/debug.es6.js -dist/debug.es6.js: src/*.js - @mkdir -p dist - browserify --standalone debug . > $@ - -dist/debug.js: dist/debug.es6.js - @mkdir -p dist - babel $< > $@ - -dist/test.js: test.js - @mkdir -p dist - babel $< > $@ - -lint: - xo - -test-node: - istanbul cover node_modules/mocha/bin/_mocha -- test.js - @cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js - -test-browser: dist - karma start --single-run - -test: test-node test-browser - -clean: - rm -rf dist coverage - -.PHONY: all dist clean lint test test-node test-browser diff --git a/package.json b/package.json index cecd5ac5..0c8aa48e 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,19 @@ "Andrew Rhyne " ], "license": "MIT", + "scripts": { + "lint": "xo", + "test": "npm run test:node && npm run test:browser", + "test:node": "istanbul cover _mocha -- test.js", + "posttest:node": "cat ./coverage/lcov.info | coveralls", + "pretest:browser": "npm run build", + "test:browser": "karma start --single-run", + "prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .", + "build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js", + "build:test": "babel -d dist test.js", + "build": "npm run build:debug && npm run build:test", + "clean": "rimraf dist coverage" + }, "dependencies": { "ms": "^2.1.1" }, From 7ef8b417a86941372074f749019b9f439a1f6ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B8cker-Larsen?= Date: Thu, 4 Oct 2018 09:45:22 +0800 Subject: [PATCH 20/83] feat: Return namespaces string when invoking disable() feat: Add unit tests for disable return value fix: Correct spelling in test case description feat: Test that disable-string works with enable again Closes #523 docs: Add section about disable return value --- README.md | 18 ++++++++++++++++++ src/common.js | 19 +++++++++++++++++++ test.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/README.md b/README.md index 0ee7634d..88dae35d 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,24 @@ $ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log( => false ``` +`disable()` + +Will disable all namespaces. The functions returns the namespaces currently +enabled (and skipped). This can be useful if you want to disable debugging +temporarily without knowing what was enabled to begin with. + +For example: + +```js +let debug = require('debug'); +debug.enable('foo:*,-foo:bar'); +let namespaces = debug.disable(); +debug.enable(namespaces); +``` + +Note: There is no guarantee that the string will be identical to the initial +enable string, but semantically they will be identical. + ## Checking whether a debug target is enabled After you've created a debug instance, you can determine whether or not it is diff --git a/src/common.js b/src/common.js index dab9e480..0b6d0b64 100644 --- a/src/common.js +++ b/src/common.js @@ -187,10 +187,16 @@ function setup(env) { /** * Disable debug output. * + * @return {String} namespaces * @api public */ function disable() { + const namespaces = [ + ...createDebug.names.map(toNamespace), + ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) + ].join(','); createDebug.enable(''); + return namespaces; } /** @@ -223,6 +229,19 @@ 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`. * diff --git a/test.js b/test.js index 675d0825..888f9bd8 100644 --- a/test.js +++ b/test.js @@ -81,4 +81,43 @@ describe('debug', () => { expect(logBar.namespace).to.be.equal('foobar'); }); }); + + describe('rebuild namespaces string (disable)', () => { + it('handle names, skips, and wildcards', () => { + debug.enable('test,abc*,-abc'); + const namespaces = debug.disable(); + expect(namespaces).to.equal('test,abc*,-abc'); + }); + + it('handles empty', () => { + debug.enable(''); + const namespaces = debug.disable(); + expect(namespaces).to.equal(''); + expect(debug.names).to.deep.equal([]); + expect(debug.skips).to.deep.equal([]); + }); + + it('handles all', () => { + debug.enable('*'); + const namespaces = debug.disable(); + expect(namespaces).to.equal('*'); + }); + + it('handles skip all', () => { + debug.enable('-*'); + const namespaces = debug.disable(); + expect(namespaces).to.equal('-*'); + }); + + it('names+skips same with new string', () => { + debug.enable('test,abc*,-abc'); + const oldNames = [...debug.names]; + const oldSkips = [...debug.skips]; + const namespaces = debug.disable(); + expect(namespaces).to.equal('test,abc*,-abc'); + debug.enable(namespaces); + expect(oldNames.map(String)).to.deep.equal(debug.names.map(String)); + expect(oldSkips.map(String)).to.deep.equal(debug.skips.map(String)); + }); + }); }); From e30e8fdbc92c4cf6b3007cd1c3ad2c3cbb82be85 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 8 Oct 2018 04:09:42 -0600 Subject: [PATCH 21/83] 4.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c8aa48e..0477a691 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "4.0.1", + "version": "4.1.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 615cbb925f3a57f00d6bfeab881ad47f77a7e4c7 Mon Sep 17 00:00:00 2001 From: ossdev07 Date: Mon, 24 Sep 2018 15:53:42 +0530 Subject: [PATCH 22/83] debug: Replaced phantomJS by chrome Added script in package.json for running Test-suite Signed-off-by: ossdev07 --- karma.conf.js | 8 +++++++- package.json | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index e503df20..8a4d88c6 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -47,7 +47,13 @@ module.exports = function (config) { // Start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], + browsers: ['HeadlessChrome'], + customLaunchers: { + HeadlessChrome: { + base: 'ChromeHeadless', + flags: ['--no-sandbox',], + }, + }, // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits diff --git a/package.json b/package.json index 0477a691..a2dc7f31 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,9 @@ "dependencies": { "ms": "^2.1.1" }, + "scripts": { + "test": "mocha" + }, "devDependencies": { "@babel/cli": "^7.0.0", "@babel/core": "^7.0.0", @@ -48,10 +51,10 @@ "concurrently": "^3.1.0", "coveralls": "^3.0.2", "istanbul": "^0.4.5", - "karma": "^3.0.0", + "karma": "^2.0.0", "karma-chai": "^0.1.0", "karma-mocha": "^1.3.0", - "karma-phantomjs-launcher": "^1.0.2", + "karma-chrome-launcher": "^2.2.0", "mocha": "^5.2.0", "mocha-lcov-reporter": "^1.2.0", "rimraf": "^2.5.4", From 4fe746a44692a9fe55d24a3c0ff5e4f340519d90 Mon Sep 17 00:00:00 2001 From: ossdev07 <39188636+ossdev07@users.noreply.github.com> Date: Mon, 24 Sep 2018 16:15:28 +0530 Subject: [PATCH 23/83] Update karma.conf.js --- karma.conf.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 8a4d88c6..c8033d79 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -48,12 +48,12 @@ module.exports = function (config) { // Start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['HeadlessChrome'], - customLaunchers: { - HeadlessChrome: { - base: 'ChromeHeadless', - flags: ['--no-sandbox',], - }, - }, + customLaunchers: { + HeadlessChrome: { + base: 'ChromeHeadless', + flags: ['--no-sandbox',], + }, + }, // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits From 61c94841a0cc48f33a8b5ac5f973ee75d74b7996 Mon Sep 17 00:00:00 2001 From: ossdev07 <39188636+ossdev07@users.noreply.github.com> Date: Mon, 24 Sep 2018 16:26:46 +0530 Subject: [PATCH 24/83] Update karma.conf.js --- karma.conf.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index c8033d79..fef8bf4c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -48,12 +48,12 @@ module.exports = function (config) { // Start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['HeadlessChrome'], - customLaunchers: { - HeadlessChrome: { - base: 'ChromeHeadless', - flags: ['--no-sandbox',], - }, - }, + customLaunchers: { + HeadlessChrome: { + base: 'ChromeHeadless', + flags: ['--no-sandbox' ], + } + }, // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits From 7ea4076fd684df6ace0cb4eba64d17a3b711ba3a Mon Sep 17 00:00:00 2001 From: ossdev07 <39188636+ossdev07@users.noreply.github.com> Date: Mon, 24 Sep 2018 16:31:03 +0530 Subject: [PATCH 25/83] Update karma.conf.js --- karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index fef8bf4c..38f34571 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -51,7 +51,7 @@ module.exports = function (config) { customLaunchers: { HeadlessChrome: { base: 'ChromeHeadless', - flags: ['--no-sandbox' ], + flags: ['--no-sandbox'] } }, From dab648abd54abf3f0cc8862d7ba9628f616cf3fe Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 10 Oct 2018 01:03:02 -0600 Subject: [PATCH 26/83] remove second (shadow) scripts block --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index a2dc7f31..2e14fcbe 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,6 @@ "dependencies": { "ms": "^2.1.1" }, - "scripts": { - "test": "mocha" - }, "devDependencies": { "@babel/cli": "^7.0.0", "@babel/core": "^7.0.0", From 5fadf4544d32531a91519299f6850620c6a0221e Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 11 Oct 2018 05:56:04 -0600 Subject: [PATCH 27/83] deprecate CHANGELOG.md --- CHANGELOG.md | 397 +-------------------------------------------------- 1 file changed, 3 insertions(+), 394 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 820d21e3..97162b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,395 +1,4 @@ +CHANGELOG.md has been deprecated moved to the Github releases pages. It will be removed in the future. -3.1.0 / 2017-09-26 -================== - - * Add `DEBUG_HIDE_DATE` env var (#486) - * Remove ReDoS regexp in %o formatter (#504) - * Remove "component" from package.json - * Remove `component.json` - * Ignore package-lock.json - * Examples: fix colors printout - * Fix: browser detection - * Fix: spelling mistake (#496, @EdwardBetts) - -3.0.1 / 2017-08-24 -================== - - * Fix: Disable colors in Edge and Internet Explorer (#489) - -3.0.0 / 2017-08-08 -================== - - * Breaking: Remove DEBUG_FD (#406) - * Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418) - * Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408) - * Addition: document `enabled` flag (#465) - * Addition: add 256 colors mode (#481) - * Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440) - * Update: component: update "ms" to v2.0.0 - * Update: separate the Node and Browser tests in Travis-CI - * Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots - * Update: separate Node.js and web browser examples for organization - * Update: update "browserify" to v14.4.0 - * Fix: fix Readme typo (#473) - -2.6.9 / 2017-09-22 -================== - - * remove ReDoS regexp in %o formatter (#504) - -2.6.8 / 2017-05-18 -================== - - * Fix: Check for undefined on browser globals (#462, @marbemac) - -2.6.7 / 2017-05-16 -================== - - * Fix: Update ms to 2.0.0 to fix regular expression denial of service vulnerability (#458, @hubdotcom) - * Fix: Inline extend function in node implementation (#452, @dougwilson) - * Docs: Fix typo (#455, @msasad) - -2.6.5 / 2017-04-27 -================== - - * Fix: null reference check on window.documentElement.style.WebkitAppearance (#447, @thebigredgeek) - * Misc: clean up browser reference checks (#447, @thebigredgeek) - * Misc: add npm-debug.log to .gitignore (@thebigredgeek) - - -2.6.4 / 2017-04-20 -================== - - * Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo) - * Chore: ignore bower.json in npm installations. (#437, @joaovieira) - * Misc: update "ms" to v0.7.3 (@tootallnate) - -2.6.3 / 2017-03-13 -================== - - * Fix: Electron reference to `process.env.DEBUG` (#431, @paulcbetts) - * Docs: Changelog fix (@thebigredgeek) - -2.6.2 / 2017-03-10 -================== - - * Fix: DEBUG_MAX_ARRAY_LENGTH (#420, @slavaGanzin) - * Docs: Add backers and sponsors from Open Collective (#422, @piamancini) - * Docs: Add Slackin invite badge (@tootallnate) - -2.6.1 / 2017-02-10 -================== - - * Fix: Module's `export default` syntax fix for IE8 `Expected identifier` error - * Fix: Whitelist DEBUG_FD for values 1 and 2 only (#415, @pi0) - * Fix: IE8 "Expected identifier" error (#414, @vgoma) - * Fix: Namespaces would not disable once enabled (#409, @musikov) - -2.6.0 / 2016-12-28 -================== - - * Fix: added better null pointer checks for browser useColors (@thebigredgeek) - * Improvement: removed explicit `window.debug` export (#404, @tootallnate) - * Improvement: deprecated `DEBUG_FD` environment variable (#405, @tootallnate) - -2.5.2 / 2016-12-25 -================== - - * Fix: reference error on window within webworkers (#393, @KlausTrainer) - * Docs: fixed README typo (#391, @lurch) - * Docs: added notice about v3 api discussion (@thebigredgeek) - -2.5.1 / 2016-12-20 -================== - - * Fix: babel-core compatibility - -2.5.0 / 2016-12-20 -================== - - * Fix: wrong reference in bower file (@thebigredgeek) - * Fix: webworker compatibility (@thebigredgeek) - * Fix: output formatting issue (#388, @kribblo) - * Fix: babel-loader compatibility (#383, @escwald) - * Misc: removed built asset from repo and publications (@thebigredgeek) - * Misc: moved source files to /src (#378, @yamikuronue) - * Test: added karma integration and replaced babel with browserify for browser tests (#378, @yamikuronue) - * Test: coveralls integration (#378, @yamikuronue) - * Docs: simplified language in the opening paragraph (#373, @yamikuronue) - -2.4.5 / 2016-12-17 -================== - - * Fix: `navigator` undefined in Rhino (#376, @jochenberger) - * Fix: custom log function (#379, @hsiliev) - * Improvement: bit of cleanup + linting fixes (@thebigredgeek) - * Improvement: rm non-maintainted `dist/` dir (#375, @freewil) - * Docs: simplified language in the opening paragraph. (#373, @yamikuronue) - -2.4.4 / 2016-12-14 -================== - - * Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts) - -2.4.3 / 2016-12-14 -================== - - * Fix: navigation.userAgent error for react native (#364, @escwald) - -2.4.2 / 2016-12-14 -================== - - * Fix: browser colors (#367, @tootallnate) - * Misc: travis ci integration (@thebigredgeek) - * Misc: added linting and testing boilerplate with sanity check (@thebigredgeek) - -2.4.1 / 2016-12-13 -================== - - * Fix: typo that broke the package (#356) - -2.4.0 / 2016-12-13 -================== - - * Fix: bower.json references unbuilt src entry point (#342, @justmatt) - * Fix: revert "handle regex special characters" (@tootallnate) - * Feature: configurable util.inspect()`options for NodeJS (#327, @tootallnate) - * Feature: %O`(big O) pretty-prints objects (#322, @tootallnate) - * Improvement: allow colors in workers (#335, @botverse) - * Improvement: use same color for same namespace. (#338, @lchenay) - -2.3.3 / 2016-11-09 -================== - - * Fix: Catch `JSON.stringify()` errors (#195, Jovan Alleyne) - * Fix: Returning `localStorage` saved values (#331, Levi Thomason) - * Improvement: Don't create an empty object when no `process` (Nathan Rajlich) - -2.3.2 / 2016-11-09 -================== - - * Fix: be super-safe in index.js as well (@TooTallNate) - * Fix: should check whether process exists (Tom Newby) - -2.3.1 / 2016-11-09 -================== - - * Fix: Added electron compatibility (#324, @paulcbetts) - * Improvement: Added performance optimizations (@tootallnate) - * Readme: Corrected PowerShell environment variable example (#252, @gimre) - * Misc: Removed yarn lock file from source control (#321, @fengmk2) - -2.3.0 / 2016-11-07 -================== - - * Fix: Consistent placement of ms diff at end of output (#215, @gorangajic) - * Fix: Escaping of regex special characters in namespace strings (#250, @zacronos) - * Fix: Fixed bug causing crash on react-native (#282, @vkarpov15) - * Feature: Enabled ES6+ compatible import via default export (#212 @bucaran) - * Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom) - * Package: Update "ms" to 0.7.2 (#315, @DevSide) - * Package: removed superfluous version property from bower.json (#207 @kkirsche) - * Readme: fix USE_COLORS to DEBUG_COLORS - * Readme: Doc fixes for format string sugar (#269, @mlucool) - * Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0) - * Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable) - * Readme: better docs for browser support (#224, @matthewmueller) - * Tooling: Added yarn integration for development (#317, @thebigredgeek) - * Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek) - * Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman) - * Misc: Updated contributors (@thebigredgeek) - -2.2.0 / 2015-05-09 -================== - - * package: update "ms" to v0.7.1 (#202, @dougwilson) - * README: add logging to file example (#193, @DanielOchoa) - * README: fixed a typo (#191, @amir-s) - * browser: expose `storage` (#190, @stephenmathieson) - * Makefile: add a `distclean` target (#189, @stephenmathieson) - -2.1.3 / 2015-03-13 -================== - - * Updated stdout/stderr example (#186) - * Updated example/stdout.js to match debug current behaviour - * Renamed example/stderr.js to stdout.js - * Update Readme.md (#184) - * replace high intensity foreground color for bold (#182, #183) - -2.1.2 / 2015-03-01 -================== - - * dist: recompile - * update "ms" to v0.7.0 - * package: update "browserify" to v9.0.3 - * component: fix "ms.js" repo location - * changed bower package name - * updated documentation about using debug in a browser - * fix: security error on safari (#167, #168, @yields) - -2.1.1 / 2014-12-29 -================== - - * browser: use `typeof` to check for `console` existence - * browser: check for `console.log` truthiness (fix IE 8/9) - * browser: add support for Chrome apps - * Readme: added Windows usage remarks - * Add `bower.json` to properly support bower install - -2.1.0 / 2014-10-15 -================== - - * node: implement `DEBUG_FD` env variable support - * package: update "browserify" to v6.1.0 - * package: add "license" field to package.json (#135, @panuhorsmalahti) - -2.0.0 / 2014-09-01 -================== - - * package: update "browserify" to v5.11.0 - * node: use stderr rather than stdout for logging (#29, @stephenmathieson) - -1.0.4 / 2014-07-15 -================== - - * dist: recompile - * example: remove `console.info()` log usage - * example: add "Content-Type" UTF-8 header to browser example - * browser: place %c marker after the space character - * browser: reset the "content" color via `color: inherit` - * browser: add colors support for Firefox >= v31 - * debug: prefer an instance `log()` function over the global one (#119) - * Readme: update documentation about styled console logs for FF v31 (#116, @wryk) - -1.0.3 / 2014-07-09 -================== - - * Add support for multiple wildcards in namespaces (#122, @seegno) - * browser: fix lint - -1.0.2 / 2014-06-10 -================== - - * browser: update color palette (#113, @gscottolson) - * common: make console logging function configurable (#108, @timoxley) - * node: fix %o colors on old node <= 0.8.x - * Makefile: find node path using shell/which (#109, @timoxley) - -1.0.1 / 2014-06-06 -================== - - * browser: use `removeItem()` to clear localStorage - * browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777) - * package: add "contributors" section - * node: fix comment typo - * README: list authors - -1.0.0 / 2014-06-04 -================== - - * make ms diff be global, not be scope - * debug: ignore empty strings in enable() - * node: make DEBUG_COLORS able to disable coloring - * *: export the `colors` array - * npmignore: don't publish the `dist` dir - * Makefile: refactor to use browserify - * package: add "browserify" as a dev dependency - * Readme: add Web Inspector Colors section - * node: reset terminal color for the debug content - * node: map "%o" to `util.inspect()` - * browser: map "%j" to `JSON.stringify()` - * debug: add custom "formatters" - * debug: use "ms" module for humanizing the diff - * Readme: add "bash" syntax highlighting - * browser: add Firebug color support - * browser: add colors for WebKit browsers - * node: apply log to `console` - * rewrite: abstract common logic for Node & browsers - * add .jshintrc file - -0.8.1 / 2014-04-14 -================== - - * package: re-add the "component" section - -0.8.0 / 2014-03-30 -================== - - * add `enable()` method for nodejs. Closes #27 - * change from stderr to stdout - * remove unnecessary index.js file - -0.7.4 / 2013-11-13 -================== - - * remove "browserify" key from package.json (fixes something in browserify) - -0.7.3 / 2013-10-30 -================== - - * fix: catch localStorage security error when cookies are blocked (Chrome) - * add debug(err) support. Closes #46 - * add .browser prop to package.json. Closes #42 - -0.7.2 / 2013-02-06 -================== - - * fix package.json - * fix: Mobile Safari (private mode) is broken with debug - * fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript - -0.7.1 / 2013-02-05 -================== - - * add repository URL to package.json - * add DEBUG_COLORED to force colored output - * add browserify support - * fix component. Closes #24 - -0.7.0 / 2012-05-04 -================== - - * Added .component to package.json - * Added debug.component.js build - -0.6.0 / 2012-03-16 -================== - - * Added support for "-" prefix in DEBUG [Vinay Pulim] - * Added `.enabled` flag to the node version [TooTallNate] - -0.5.0 / 2012-02-02 -================== - - * Added: humanize diffs. Closes #8 - * Added `debug.disable()` to the CS variant - * Removed padding. Closes #10 - * Fixed: persist client-side variant again. Closes #9 - -0.4.0 / 2012-02-01 -================== - - * Added browser variant support for older browsers [TooTallNate] - * Added `debug.enable('project:*')` to browser variant [TooTallNate] - * Added padding to diff (moved it to the right) - -0.3.0 / 2012-01-26 -================== - - * Added millisecond diff when isatty, otherwise UTC string - -0.2.0 / 2012-01-22 -================== - - * Added wildcard support - -0.1.0 / 2011-12-02 -================== - - * Added: remove colors unless stderr isatty [TooTallNate] - -0.0.1 / 2010-01-03 -================== - - * Initial release +Please see https://github.com/visionmedia/debug/releases for all changelogs and information pertaining +to new releases. From 010fd0d92faeed1bd7e822f3780175e4f57fa2db Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 01:43:40 +0100 Subject: [PATCH 28/83] remove changelog --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 97162b9e..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,4 +0,0 @@ -CHANGELOG.md has been deprecated moved to the Github releases pages. It will be removed in the future. - -Please see https://github.com/visionmedia/debug/releases for all changelogs and information pertaining -to new releases. From dfd5ffa8b6cd52056651964360749a1873149eff Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 01:46:00 +0100 Subject: [PATCH 29/83] remove bower.json (closes #602) --- bower.json | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 bower.json diff --git a/bower.json b/bower.json deleted file mode 100644 index 027804ce..00000000 --- a/bower.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "visionmedia-debug", - "main": "./src/browser.js", - "homepage": "https://github.com/visionmedia/debug", - "authors": [ - "TJ Holowaychuk ", - "Nathan Rajlich (http://n8.io)", - "Andrew Rhyne " - ], - "description": "visionmedia-debug", - "moduleType": [ - "amd", - "es6", - "globals", - "node" - ], - "keywords": [ - "visionmedia", - "debug" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ] -} From dc5c34f9d8fc9c08ee5b275b4f0c51b9f984a98f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 02:05:38 +0100 Subject: [PATCH 30/83] remove .eslintrc --- .eslintrc | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 146371ed..00000000 --- a/.eslintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "env": { - "browser": true, - "node": true - }, - "globals": { - "chrome": true - }, - "rules": { - "no-console": 0, - "no-empty": [1, { "allowEmptyCatch": true }] - }, - "extends": "eslint:recommended" -} From fe49015965c0f29f943df20f29445b4310b3ce0a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 02:29:30 +0100 Subject: [PATCH 31/83] remove .coveralls.yml --- .coveralls.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 20a70685..00000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: SIAeZjKYlHK74rbcFvNHMUzjRiMpflxve From ad551e2b61022107cee85a66819cd4d2b962038a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 02:45:52 +0100 Subject: [PATCH 32/83] add Josh Junon to contributors --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e14fcbe..3464bd8a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "author": "TJ Holowaychuk ", "contributors": [ "Nathan Rajlich (http://n8.io)", - "Andrew Rhyne " + "Andrew Rhyne ", + "Josh Junon " ], "license": "MIT", "scripts": { From 0e94034efb1e88b88a06ca3862d8d2cc2f2ed5d0 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 02:41:45 +0100 Subject: [PATCH 33/83] update development dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3464bd8a..9e35a1b2 100644 --- a/package.json +++ b/package.json @@ -44,12 +44,12 @@ "@babel/cli": "^7.0.0", "@babel/core": "^7.0.0", "@babel/preset-env": "^7.0.0", - "browserify": "14.4.0", - "chai": "^3.5.0", - "concurrently": "^3.1.0", + "browserify": "16.2.3", + "chai": "^4.2.0", + "concurrently": "^4.1.0", "coveralls": "^3.0.2", "istanbul": "^0.4.5", - "karma": "^2.0.0", + "karma": "^3.1.4", "karma-chai": "^0.1.0", "karma-mocha": "^1.3.0", "karma-chrome-launcher": "^2.2.0", From 94583b652a58e58102074ce5ab99e17972db1c4f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 04:03:39 +0100 Subject: [PATCH 34/83] remove build system (closes #652) --- .babelrc | 13 ------------- .travis.yml | 1 + karma.conf.js | 43 +++++++++++++++++------------------------- package.json | 25 ++++++------------------- test.js | 52 +++++++++++++++++++++------------------------------ 5 files changed, 45 insertions(+), 89 deletions(-) delete mode 100644 .babelrc diff --git a/.babelrc b/.babelrc deleted file mode 100644 index b2799de4..00000000 --- a/.babelrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "chrome": "58", - "ie": "8" - } - } - ] - ] -} diff --git a/.travis.yml b/.travis.yml index 24682db3..c020bf98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ node_js: - "6" - "8" - "10" + - "11" install: - npm install diff --git a/karma.conf.js b/karma.conf.js index 38f34571..6e835858 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,32 +1,16 @@ -// Karma configuration -// Generated on Fri Dec 16 2016 13:09:51 GMT+0000 (UTC) - module.exports = function (config) { config.set({ - - // Base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', - // Frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha', 'chai'], + frameworks: ['browserify', 'mocha'], // List of files / patterns to load in the browser files: [ - 'dist/debug.js', - 'dist/test.js' + 'src/browser.js', + 'src/common.js', + 'test.js' ], - // List of files to exclude - exclude: [ - 'src/node.js' - ], - - // Preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - }, - // Test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter @@ -40,10 +24,7 @@ module.exports = function (config) { // Level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // Enable / disable watching file and executing tests whenever any file changes - autoWatch: true, + logLevel: config.LOG_DEBUG, // Start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher @@ -55,12 +36,22 @@ module.exports = function (config) { } }, + preprocessors: { + // *Sigh* what a glob, folks! + '{{!(node_modules),*.js},!(node_modules)/**/*.js}': ['browserify'] + }, + + browserify: { + debug: true, + transform: ['brfs'] + }, + // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits - singleRun: false, + singleRun: true, // Concurrency level // how many browser should be started simultaneous - concurrency: Infinity + concurrency: 1 }); }; diff --git a/package.json b/package.json index 9e35a1b2..c26c4a16 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ ], "files": [ "src", - "dist/debug.js", "LICENSE", "README.md" ], @@ -28,37 +27,25 @@ "lint": "xo", "test": "npm run test:node && npm run test:browser", "test:node": "istanbul cover _mocha -- test.js", - "posttest:node": "cat ./coverage/lcov.info | coveralls", - "pretest:browser": "npm run build", "test:browser": "karma start --single-run", - "prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .", - "build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js", - "build:test": "babel -d dist test.js", - "build": "npm run build:debug && npm run build:test", - "clean": "rimraf dist coverage" + "posttest:node": "cat ./coverage/lcov.info | coveralls" }, "dependencies": { "ms": "^2.1.1" }, "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", - "browserify": "16.2.3", - "chai": "^4.2.0", - "concurrently": "^4.1.0", + "brfs": "^2.0.1", + "browserify": "^16.2.3", "coveralls": "^3.0.2", "istanbul": "^0.4.5", "karma": "^3.1.4", - "karma-chai": "^0.1.0", - "karma-mocha": "^1.3.0", + "karma-browserify": "^6.0.0", "karma-chrome-launcher": "^2.2.0", + "karma-mocha": "^1.3.0", "mocha": "^5.2.0", "mocha-lcov-reporter": "^1.2.0", - "rimraf": "^2.5.4", "xo": "^0.23.0" }, "main": "./src/index.js", - "browser": "./src/browser.js", - "unpkg": "./dist/debug.js" + "browser": "./src/browser.js" } diff --git a/test.js b/test.js index 888f9bd8..460f9759 100644 --- a/test.js +++ b/test.js @@ -1,17 +1,7 @@ /* eslint-env mocha */ -'use strict'; -let chai; - -let expect; - -let debug; - -if (typeof module !== 'undefined') { - chai = require('chai'); - expect = chai.expect; - debug = require('./src'); -} +const assert = require('assert'); +const debug = require('./src'); describe('debug', () => { it('passes a basic sanity check', () => { @@ -19,7 +9,7 @@ describe('debug', () => { log.enabled = true; log.log = () => {}; - expect(() => log('hello world')).to.not.throw(); + assert.doesNotThrow(() => log('hello world')); }); it('allows namespaces to be a non-string value', () => { @@ -27,16 +17,16 @@ describe('debug', () => { log.enabled = true; log.log = () => {}; - expect(() => debug.enable(true)).to.not.throw(); + assert.doesNotThrow(() => debug.enable(true)); }); it('honors global debug namespace enable calls', () => { - expect(debug('test:12345').enabled).to.equal(false); - expect(debug('test:67890').enabled).to.equal(false); + assert.deepStrictEqual(debug('test:12345').enabled, false); + assert.deepStrictEqual(debug('test:67890').enabled, false); debug.enable('test:12345'); - expect(debug('test:12345').enabled).to.equal(true); - expect(debug('test:67890').enabled).to.equal(false); + assert.deepStrictEqual(debug('test:12345').enabled, true); + assert.deepStrictEqual(debug('test:67890').enabled, false); }); it('uses custom log function', () => { @@ -50,7 +40,7 @@ describe('debug', () => { log('using custom log function again'); log('%O', 12345); - expect(messages.length).to.equal(3); + assert.deepStrictEqual(messages.length, 3); }); describe('extend namespace', () => { @@ -60,7 +50,7 @@ describe('debug', () => { log.log = () => {}; const logBar = log.extend('bar'); - expect(logBar.namespace).to.be.equal('foo:bar'); + assert.deepStrictEqual(logBar.namespace, 'foo:bar'); }); it('should extend namespace with custom delimiter', () => { @@ -69,7 +59,7 @@ describe('debug', () => { log.log = () => {}; const logBar = log.extend('bar', '--'); - expect(logBar.namespace).to.be.equal('foo--bar'); + assert.deepStrictEqual(logBar.namespace, 'foo--bar'); }); it('should extend namespace with empty delimiter', () => { @@ -78,7 +68,7 @@ describe('debug', () => { log.log = () => {}; const logBar = log.extend('bar', ''); - expect(logBar.namespace).to.be.equal('foobar'); + assert.deepStrictEqual(logBar.namespace, 'foobar'); }); }); @@ -86,27 +76,27 @@ describe('debug', () => { it('handle names, skips, and wildcards', () => { debug.enable('test,abc*,-abc'); const namespaces = debug.disable(); - expect(namespaces).to.equal('test,abc*,-abc'); + assert.deepStrictEqual(namespaces, 'test,abc*,-abc'); }); it('handles empty', () => { debug.enable(''); const namespaces = debug.disable(); - expect(namespaces).to.equal(''); - expect(debug.names).to.deep.equal([]); - expect(debug.skips).to.deep.equal([]); + assert.deepStrictEqual(namespaces, ''); + assert.deepStrictEqual(debug.names, []); + assert.deepStrictEqual(debug.skips, []); }); it('handles all', () => { debug.enable('*'); const namespaces = debug.disable(); - expect(namespaces).to.equal('*'); + assert.deepStrictEqual(namespaces, '*'); }); it('handles skip all', () => { debug.enable('-*'); const namespaces = debug.disable(); - expect(namespaces).to.equal('-*'); + assert.deepStrictEqual(namespaces, '-*'); }); it('names+skips same with new string', () => { @@ -114,10 +104,10 @@ describe('debug', () => { const oldNames = [...debug.names]; const oldSkips = [...debug.skips]; const namespaces = debug.disable(); - expect(namespaces).to.equal('test,abc*,-abc'); + assert.deepStrictEqual(namespaces, 'test,abc*,-abc'); debug.enable(namespaces); - expect(oldNames.map(String)).to.deep.equal(debug.names.map(String)); - expect(oldSkips.map(String)).to.deep.equal(debug.skips.map(String)); + assert.deepStrictEqual(oldNames.map(String), debug.names.map(String)); + assert.deepStrictEqual(oldSkips.map(String), debug.skips.map(String)); }); }); }); From c0127b18a0b7670bf931072a25ddc82e84116659 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 04:26:28 +0100 Subject: [PATCH 35/83] remove examples folder (closes #650) --- examples/browser/colors.html | 28 ---------------------------- examples/node/app.js | 20 -------------------- examples/node/colors.js | 8 -------- examples/node/stdout.js | 18 ------------------ examples/node/wildcards.js | 10 ---------- examples/node/worker.js | 27 --------------------------- 6 files changed, 111 deletions(-) delete mode 100644 examples/browser/colors.html delete mode 100644 examples/node/app.js delete mode 100644 examples/node/colors.js delete mode 100644 examples/node/stdout.js delete mode 100644 examples/node/wildcards.js delete mode 100644 examples/node/worker.js diff --git a/examples/browser/colors.html b/examples/browser/colors.html deleted file mode 100644 index ce969072..00000000 --- a/examples/browser/colors.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - debug() - - - - - - - Open your - Web Inspector - to see the debug output - - diff --git a/examples/node/app.js b/examples/node/app.js deleted file mode 100644 index 08d3f257..00000000 --- a/examples/node/app.js +++ /dev/null @@ -1,20 +0,0 @@ -const http = require('http'); - -const debug = require('../..')('http'); - -const name = 'My App'; - -// Fake app - -debug('booting %o', name); - -http.createServer((req, res) => { - debug(req.method + ' ' + req.url); - res.end('hello\n'); -}).listen(3000, () => { - debug('listening'); -}); - -// Fake worker of some kind -// eslint-disable-next-line import/no-unassigned-import -require('./worker'); diff --git a/examples/node/colors.js b/examples/node/colors.js deleted file mode 100644 index 9cbfa1f9..00000000 --- a/examples/node/colors.js +++ /dev/null @@ -1,8 +0,0 @@ -const debug = require('../..'); - -debug.enable('*'); - -for (let i = 0; i < debug.colors.length; i++) { - const d = debug('example:' + i); - d('The color is %o', d.color); -} diff --git a/examples/node/stdout.js b/examples/node/stdout.js deleted file mode 100644 index 17558da0..00000000 --- a/examples/node/stdout.js +++ /dev/null @@ -1,18 +0,0 @@ -const debug = require('../..'); - -const error = debug('app:error'); - -// By default stderr is used -error('goes to stderr!'); - -const log = debug('app:log'); -// Set this namespace to log via console.log -log.log = console.log.bind(console); // Don't forget to bind to console! -log('goes to stdout'); -error('still goes to stderr!'); - -// Set all output to go via console.info -// overrides all per-namespace log settings -debug.log = console.info.bind(console); -error('now goes to stdout via console.info'); -log('still goes to stdout, but via console.info now'); diff --git a/examples/node/wildcards.js b/examples/node/wildcards.js deleted file mode 100644 index 2cedc2d8..00000000 --- a/examples/node/wildcards.js +++ /dev/null @@ -1,10 +0,0 @@ - -const debug = { - foo: require('../..')('test:foo'), - bar: require('../..')('test:bar'), - baz: require('../..')('test:baz') -}; - -debug.foo('foo'); -debug.bar('bar'); -debug.baz('baz'); diff --git a/examples/node/worker.js b/examples/node/worker.js deleted file mode 100644 index 6f483a66..00000000 --- a/examples/node/worker.js +++ /dev/null @@ -1,27 +0,0 @@ - -// DEBUG=* node example/worker -// DEBUG=worker:* node example/worker -// DEBUG=worker:a node example/worker -// DEBUG=worker:b node example/worker - -const a = require('../..')('worker:a'); - -const b = require('../..')('worker:b'); - -function work() { - a('doing lots of uninteresting work'); - setTimeout(work, Math.random() * 1000); -} - -work(); - -function workb() { - b('doing some work'); - setTimeout(workb, Math.random() * 2000); -} - -workb(); - -setTimeout(() => { - b(new Error('fail')); -}, 5000); From 5528572f9a96b9202e77e565eb641ba8c74aec40 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 04:41:05 +0100 Subject: [PATCH 36/83] use console.debug() in browser when available (closes #600) also removes a branch for each logging call, slightly improving performance in the browser. --- src/browser.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/browser.js b/src/browser.js index 5f34c0d0..ac3f7e13 100644 --- a/src/browser.js +++ b/src/browser.js @@ -4,7 +4,6 @@ * This is the web browser implementation of `debug()`. */ -exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; @@ -170,18 +169,14 @@ function formatArgs(args) { } /** - * Invokes `console.log()` when available. - * No-op when `console.log` is not a "function". + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. * * @api public */ -function log(...args) { - // This hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return typeof console === 'object' && - console.log && - console.log(...args); -} +exports.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. From 825d35a2da0a9fa115baffea2f07d22b876332fc Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 04:56:06 +0100 Subject: [PATCH 37/83] copy custom logger to namespace extension (fixes #646) --- src/common.js | 4 +++- test.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 0b6d0b64..2f82b8dc 100644 --- a/src/common.js +++ b/src/common.js @@ -143,7 +143,9 @@ function setup(env) { } function extend(namespace, delimiter) { - return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + newDebug.log = this.log; + return newDebug; } /** diff --git a/test.js b/test.js index 460f9759..f61e079b 100644 --- a/test.js +++ b/test.js @@ -70,6 +70,14 @@ describe('debug', () => { const logBar = log.extend('bar', ''); assert.deepStrictEqual(logBar.namespace, 'foobar'); }); + + it('should keep the log function between extensions', () => { + const log = debug('foo'); + log.log = () => {}; + + const logBar = log.extend('bar'); + assert.deepStrictEqual(log.log, logBar.log); + }); }); describe('rebuild namespaces string (disable)', () => { From 982c12c926699221c6769b50a8ead9d50f8807c4 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Sat, 22 Dec 2018 03:14:57 -0500 Subject: [PATCH 38/83] test: only run coveralls on travis s/posttest:node/coverage Explicitly call coverage only from CI. This will stop the test suite from failing on a system not configured to authenticate with circle-ci --- .travis.yml | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c020bf98..40103cfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,4 @@ install: script: - npm run lint - npm test + - npm run test:coverage diff --git a/package.json b/package.json index c26c4a16..643af019 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test": "npm run test:node && npm run test:browser", "test:node": "istanbul cover _mocha -- test.js", "test:browser": "karma start --single-run", - "posttest:node": "cat ./coverage/lcov.info | coveralls" + "test:coverage": "cat ./coverage/lcov.info | coveralls" }, "dependencies": { "ms": "^2.1.1" From 976f8d2afc5e2a815225ff6eca2e02f4ef0462ee Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 10 Jan 2019 16:51:53 +0100 Subject: [PATCH 39/83] add issue and pull request templates --- .github/ISSUE_TEMPLATE.md | 17 +++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..baaeb283 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,17 @@ + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..c43a8c82 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ + From 5c7c61dc0df0db4eb5de25707d8cd1b9be1add4f Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 10 Jan 2019 16:53:31 +0100 Subject: [PATCH 40/83] fix links in issue templates --- .github/ISSUE_TEMPLATE.md | 2 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index baaeb283..3c5c9a92 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -12,6 +12,6 @@ target the browsers that make sense for your project. For more information, please see: -https://github.com/visionmedia/debug/pull/672 +https://github.com/sindresorhus/ama/issues/446#issuecomment-281014491 --> diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c43a8c82..af3da470 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,6 +12,6 @@ target the browsers that make sense for your project. For more information, please see: -https://github.com/visionmedia/debug/pull/672 +https://github.com/sindresorhus/ama/issues/446#issuecomment-281014491 --> From 608fca962b34e2bda841db9a4416bab6b4a62803 Mon Sep 17 00:00:00 2001 From: Qix Date: Wed, 13 Nov 2019 11:27:24 +0100 Subject: [PATCH 41/83] 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 42/83] 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 43/83] 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 44/83] 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 45/83] 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 46/83] 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 47/83] 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 48/83] 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 49/83] 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 50/83] 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 51/83] 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 52/83] 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 53/83] 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 54/83] 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 55/83] 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 56/83] 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 57/83] 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 58/83] 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 59/83] 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 60/83] 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 61/83] 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 62/83] 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 63/83] 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 64/83] 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 65/83] 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 66/83] 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 67/83] 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 69/83] 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 70/83] 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 71/83] 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 72/83] 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 73/83] 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 74/83] 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 75/83] 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 76/83] 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 77/83] 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 78/83] 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 79/83] 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 80/83] 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 81/83] 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 82/83] 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 83/83] 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"