angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

Issue with using visionmedia/debug package #2727

Closed roshan-cinq closed 6 years ago

roshan-cinq commented 6 years ago
Item Version
generator-angular-fullstack 4.2.2
Node 6.9.0
npm 6.1.0
Operating System Windows 7
Item Answer
Transpiler Babel

I have an issue with using the visionmedia/debug library. While running tests, the gulp task sets the environment variables from local.env.js. It does not work if I set say app:*, but works if I set it to *. It also works fine if I set it manually by set DEBUG=app:* before running the task.

Some digging through the debug module showed that it was only working for node modules which had their own nested debug. It doesn't work for the main app or any node module which uses the top level debug . Some more digging leads me to believe that babel loads the top level debug before the gulp task runs.

Is there a workaround for this apart from manually setting env?

Awk34 commented 6 years ago

I don't quite understand what your issue is, probably because I've never used that specific debug package. Are you just looking for an easier way to set the DEBUG environment variable?

roshan-cinq commented 6 years ago

The visionmedia/debug package enables console logging selectively based on the value of the environment variable DEBUG. Its very useful while dev/test to set the variable to see only the logs you want to.

The generator already provides a convenient option to set the DEBUG or any env variable here. And the gulp task env:all sets it from this file. So I am assuming the authors meant for this package to be used if need be.

But the task does not behave as expected. The debug package is initialized on first load, where it checks the env variable. But while running the gulp test task, the top level node modules are loaded (by babel I think) before the task itself executes. So effectively the env variable has not been set when the module loads and no logs basically.

roshan-cinq commented 6 years ago

I came up with a workaround. Added debug.enable(localConfig.DEBUG); at the end of env:all gulp task.

Awk34 commented 6 years ago

Can this be closed?