Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
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);
}

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