About
debug is nice utility for debug logging. This babel macro adds a few opinionated conveniences on top of debug library.
- Enforces the convention that debug scope is derived from filesystem hierarchy. So
my-package/lib/decorators/foo.js
will automatically userequire('debug')("my-package:lib:decorators:foo")
; - Line number & timestamp is prefixed in all debug logs.
- Utility to debug variable and members expressions without duplication:
debug.vars(a, b.c, d)
compiles todebug('a:', a, 'b.c:', b.c, 'd:', d)
. - Utility (
debug.allInScope()
) to debug all variables declared in block scope (whenever they are initialized or reassigned) - Utility (
debug.all()
) to debug all variables in current file.
Installation
This utility is implemented as a babel-macro.
Refer babel's setup instructions to learn how to setup your project to use babel for compilation. Usage with tsc (only) is not supported.
- Install
babel-plugin-macros
anddebug.macro
:
npm install --save-dev babel-plugin-macros @ts-delight/debug.macro
- Add babel-plugin-macros to .babelrc (if not already preset):
// .babelrc
module.exports = {
presets: [
'@babel/preset-typescript',
// ... other presets
],
plugins: [
'babel-plugin-macros',
// ... other plugins
],
};
License
MIT