Skip to content

Commit

Permalink
use debug ^4.3.4 fixes #4612 (#5508)
Browse files Browse the repository at this point in the history
* use debug ^4.3.4

* Update debug.js

* Update debug.js

* Update debug.js

* Update debug.js
  • Loading branch information
arpu authored Apr 9, 2024
1 parent 8705f84 commit e65ea4e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"dependencies": {
"buffer": "^6.0.3",
"debug": "ngokevin/debug#noTimestamp",
"debug": "^4.3.4",
"deep-assign": "^2.0.0",
"load-bmfont": "^1.2.3",
"super-animejs": "^3.1.0",
Expand Down
46 changes: 37 additions & 9 deletions src/utils/debug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var debugLib = require('debug');
var debug = require('debug');

var settings = {
colors: {
Expand All @@ -10,18 +10,46 @@ var settings = {
};

/**
* Monkeypatches `debug` so we can colorize error/warning messages.
* Overwrite `debug` so we can colorize error/warning messages and remove Time Diff
*
* (See issue: https://github.com/visionmedia/debug/issues/137)
* (See issue: https://github.com/debug-js/debug/issues/582#issuecomment-1755718739)
*/
var debug = function (namespace) {
var d = debugLib(namespace);
debug.formatArgs = formatArgs;

d.color = getDebugNamespaceColor(namespace);
function formatArgs (args) {
args[0] =
(this.useColors ? '%c' : '') +
this.namespace +
(this.useColors ? ' %c' : ' ') +
args[0] +
(this.useColors ? '%c ' : ' ');

return d;
};
Object.assign(debug, debugLib);
if (!this.useColors) {
return;
}
this.color = getDebugNamespaceColor(this.namespace);
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 (match === '%c') {
// We only are interested in the *last* %c
// (the user may have provided their own)
lastC = index;
}
});

args.splice(lastC, 0, c);
}

/**
* Returns the type of the namespace (e.g., `error`, `warn`).
Expand Down

0 comments on commit e65ea4e

Please sign in to comment.