Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
webketje opened this issue Jun 3, 2022 · 3 comments

Comments

@webketje
Copy link

webketje commented Jun 3, 2022

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

@Qix-
Copy link
Member

Qix- commented Jun 3, 2022

Yeah makes sense, it's definitely a drawback. The next major version was planned to change a lot of this with full backwards compatibility but with the shifting loader system in Node a lot of the plans have been tabled until the ESM loaders reach parity.

I don't really have a great answer for you right now, unfortunately :/

@RabiaSaid
Copy link

4.3.4

@RabiaSaid
Copy link

2.6.8

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

No branches or pull requests

3 participants