Skip to content

robin-drexler/babel-plugin-debug-source

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-debug-source

Adds file path and loc information for debug calls. Makes it easier to find the origin of the debug messages.

In:

const debug = require('debug')('my-app');
debug('hello');

Out:

const debug = require('debug')('my-app');
debug('hello', '/Users/your/project/path/source.js:2:0');

Installation

npm install -D babel-plugin-debug-source

Usage

.babelrc

{
  plugins: ['debug-source'];
}

Options

showSource: whether the plugin should run and add the source to debug calls. Defaults to true.

.babelrc

{
  plugins: [['debug-source', { showSource: true }]];
}

It probably makes sense to stay in the spirit of debug and only set showSource to true, when an environment variable is set.

e.g.

.babelrc

{
  plugins: [
    ['debug-source', { showSource: process.env.DEBUG_SHOW_SOURCE === 'true' }]
  ];
}

This is not the default behavior, because babel (or bundlers utilizing babel) use heavy caching. Changes in environment variables usually do not cause a cache invalidation and the result will unexpectedly stay the same.

About

Adds file path and loc information to debug calls. Heavily inspired by babel-plugin-console-source

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published