Possibility to read in config at debug instance creation instead of at first (version) require/ import?

Open
#893 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript
Domain
tooling

Research direction

Start by reading the NodeJS implementation and tracing when configuration is read during require/import versus debugger creation. Compare the two examples in the issue, then define the intended behavior for independently loaded debug versions and programmatic environment changes before determining what tests are needed.

Written by the indexing model from the issue text.

Description

I love debug's simplicity, but it bugs me that it is so tightly coupled to environment variables (NodeJS impl)
I would like to integrate it in Metalsmith along with an abstraction of env.

Basically, as soon as a package where debug is used, is require'd, or perhaps with some NPM-derivatives, if multiple packages use the same version, debug reads its defaults from the environment.

const pkgContainingDebug = require('pkg-with-debug') // debug config set according to DEBUG_COLORS= (not defined)
process.env.DEBUG_COLORS = false
const localDebug = require('debug') // debug config takes into account dynamically set process.env.DEBUG_COLORS
const localDebugger= localDebug('app') // nothing happens here config-wise
localDebugger('Hello world') 
pkgContainingDebug() // different config from localDebugger

This makes it impossible (in my case for metalsmith) to provide a user with a programmatic way of setting debug values, unless the current package + all its dependencies use the same debug dependency (other typical use case: expressjs)
If the env reading was done at debugger creation instead of require, this would provide a window to decouple the tight coupling of debug configuration and env vars across debug dependencies

const pkgContainingDebug = require('pkg-with-debug') // debug config not initialized unless dependency instantiates it at inclusion
const localDebug = require('debug') // does nothing yet
process.env.DEBUG_COLORS = false
const localDebugger= localDebug('app') // reads in env
localDebugger('Hello world') 
pkgContainingDebug() // same config as localDebugger if the dependency's debugger only happens when the dep is first run

Hope this makes sense.
I haven't had the time to dive into the codebase for this yet

Dominant language
JavaScript
Stars
11.5k
Forks
992
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from debug-js/debug

All issues in debug-js/debug

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.