Skip to content

fix: merge namespaces in enable() instead of flushing them - #1050

Open
arronKler wants to merge 1 commit into
debug-js:masterfrom
arronKler:fix/425-enable-no-flush
Open

fix: merge namespaces in enable() instead of flushing them#1050
arronKler wants to merge 1 commit into
debug-js:masterfrom
arronKler:fix/425-enable-no-flush

Conversation

@arronKler

Copy link
Copy Markdown

debug.enable() currently clears names/skips before applying the new list. That means previously enabled namespaces (including those from DEBUG) disappear:

DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
// false

This also breaks independent enable() calls from different modules that share one debug install.

Solution: treat enable() as additive. Incoming namespaces are merged with the existing set (skip tokens still disable a matching name; enabling a name again removes its skip). disable() still clears everything and is the way to replace:

debug.disable();
debug.enable('bar');

Fixes #425

enable() currently wipes names/skips, so DEBUG=foo followed by
enable("bar") disables foo. Merge incoming namespaces with the
existing set. Call disable() first when replacement is intended.

Fixes debug-js#425

@official-burak official-burak left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable() is documented as a full replace, including the DEBUG=foo example this PR rewrites. Code that calls debug.enable('production') today relies on that to drop whatever DEBUG was. Making it additive would keep those namespaces on, which is a behavior change rather than a bugfix.

If additive enable is useful, it needs a new method or an opt-in, not a silent change to enable().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

debug.enable() flushes enabled namespaces

2 participants