A powerful Babel plugin for selective expression monitoring and debugging in JavaScript/TypeScript projects. Only monitors lines marked with //? comments, making it perfect for development, testing, and debugging workflows.
- 🔍 Selective Expression Monitoring - Only monitors lines marked with
//?comments - 📊 Variable Tracking - Captures variable assignments and their values
- 📝 Console Log Wrapping - Monitors console.log, console.error, etc.
- ⚡ Async Support - Handles async/await expressions
- 🧪 Jest Integration - Works seamlessly with Jest tests
- 🎯 Precise Control - Only transform what you explicitly mark for monitoring
- 📁 Multi-File Support - Tracks file paths for monitoring across multiple files
- 🔗 Project-Wide Monitoring - Perfect for large projects with many files
npm install --save-dev inline-debugger// Mark lines you want to monitor with //?
let name = 'John'; //?
let age = 30;
let isAdult = age >= 18; //?
console.log('Name:', name); //?
console.log('Age:', age); // → not monitoredCreate a .babelrc or babel.config.js:
module.exports = {
plugins: [
['inline-debugger', {
enableDebugger: true,
outputFile: '.debug.data.json'
}]
],
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
};The runtime automatically initializes with default settings. No manual setup required!
// Runtime auto-initializes with default output file: '.debug.data.json'
// No manual initialization needed!The runtime is built using a modern class-based approach:
const { InlineDebuggerRuntime } = require('inline-debugger/src/runtime.js');
// Create a custom runtime instance
const customRuntime = new InlineDebuggerRuntime({
outputFile: 'custom-debug.json'
});
// Use the instance methods
customRuntime.setupGlobals();Benefits:
- ✅ Encapsulation: All functionality contained within the class
- ✅ Reusability: Create multiple runtime instances
- ✅ Maintainability: Clean, organized code structure
- ✅ Extensibility: Easy to extend and customize
The plugin only transforms and monitors lines marked with //? comments:
let x = 5; //? → monitored
let y = x + 3; // → not monitored2 + 3; //? → monitored
Math.sqrt(16); // → not monitoredconsole.log('hello'); //? → monitored
console.error('err'); // → not monitoredawait fetchData(); //? → monitoredThe plugin automatically tracks file paths, making it perfect for large projects:
// user.js
let name = 'John'; //? → monitored
// math.js
let result = 2 + 3; //? → monitored📁 user.js:
──────────
1. name = John (line 2)
📁 math.js:
──────────
1. result = 5 (line 2)
npm install --save-dev jest babel-jest @babel/preset-env @babel/preset-typescriptmodule.exports = {
transform: {
'^.+\\.(ts|tsx|js|jsx)$': [
'babel-jest',
{
plugins: [
[
'inline-debugger',
{
enableDebugger: true,
outputFile: '.debug.data.json',
},
],
],
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
},
],
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
};// Runtime auto-initializes and sets up globals when required
require('inline-debugger/src/runtime.js');
// Clean up after each test
afterEach(() => {
global.debugger.clearData();
});describe('My Tests', () => {
test('should monitor expressions', () => {
let result = 2 + 3; //? → monitored
let power = Math.pow(2, 3); // → not monitored
console.log('Result:', result); //? → monitored
expect(result).toBe(5);
expect(power).toBe(8);
// Print debug results
global.debugger.printData();
});
});| Option | Type | Default | Description |
|---|---|---|---|
enableDebugger |
boolean | true |
Enable/disable debugger monitoring |
outputFile |
string | '.debug.data.json' |
Output file for debug data |
The plugin generates a .debug.data.json file with monitoring data:
[
{
"type": "variable",
"variable": "name",
"called": "John",
"line": 3,
"filePath": "/src/user.js"
},
{
"type": "expression",
"called": "5",
"line": 5,
"filePath": "/src/math.js"
},
{
"type": "log",
"called": ["Name:", "John"],
"line": 7,
"filePath": "/src/user.js"
}
]The main runtime class that handles all monitoring functionality.
Constructor:
new InlineDebuggerRuntime(options)- Create a new runtime instance
Methods:
initialize(options)- Initialize the runtime with custom optionssetupGlobals()- Setup global utilities for testing environmentsinlineDebuggerWatch(data)- Main monitoring functiondebugLog(logFn, data)- Console log wrapper
Manually initialize the debugger runtime with custom options.
Parameters:
options.outputFile- Output file path (default: '.debug.data.json')
Setup global utilities for testing environments. This function is called automatically when requiring the runtime:
- Auto-initializes the runtime if not already initialized
- Makes
inlineDebuggerWatchanddebugLogavailable globally - Creates
global.debuggerwith utility functions for testing
Main monitoring function (automatically injected).
Parameters:
data.type- Type of monitoring ('variable', 'expression', 'log', 'error')data.variable- Variable name (for variables)data.called- Function to executedata.line- Line numberdata.filePath- Source file path
Console log wrapper (automatically injected).
Get current debug data.
Clear debug data.
Print debug data in readable format.
- Debug complex expressions - See intermediate values
- Understand code flow - Track variable changes
- Performance analysis - Monitor expensive operations
- Test debugging - See what's happening in tests
- Assertion debugging - Understand why tests fail
- Integration testing - Monitor cross-file interactions
- Learning JavaScript - See how expressions evaluate
- Code reviews - Understand complex logic
- Documentation - Live examples of code execution
// You can manually call the monitoring functions
inlineDebuggerWatch({
type: 'expression',
called: () => someComplexCalculation(),
line: 42,
hide: false
});try {
riskyOperation(); //?
} catch (error) {
// Error is automatically captured and logged
}-
Plugin not transforming code
- Ensure the plugin is properly configured in your Babel config
- Check that the file extensions match your test files
-
No output data
- Verify that
initializeRuntime()is called - Check that the output file path is correct
- Verify that
-
Missing file paths
- Ensure Babel is configured with proper filename options
- Check that the plugin is receiving file information
Enable debug logging:
// In your setup file
process.env.DEBUG = 'inline-debugger';MIT
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or need help, please open an issue on GitHub.
Inline Debugger - Making debugging easier, one expression at a time! 🐛✨