npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

babel-plugin-raceway

v0.1.0

Published

Babel plugin for automatic Raceway instrumentation

Downloads

6

Readme

Babel Plugin Raceway

Automatic instrumentation for Raceway - causal debugging and race condition detection.

Transform your code at build-time to automatically track:

  • ✅ Variable reads and writes
  • ✅ Function calls with arguments
  • ✅ Async/await operations
  • ✅ Property access on objects

Zero code changes required - just configure Babel and your code is automatically instrumented!

Installation

npm install --save-dev babel-plugin-raceway
npm install @mode-7/raceway

Quick Start

With Babel Config

Add to your .babelrc or babel.config.js:

{
  "plugins": [
    ["babel-plugin-raceway", {
      "instrumentFunctions": true,
      "instrumentAssignments": true,
      "instrumentAsync": true,
      "exclude": ["node_modules/**", "test/**"]
    }]
  ]
}

With CLI

npx raceway instrument ./src --output ./instrumented

What It Does

This plugin automatically transforms your code to capture Raceway events:

Function Calls

Before:

function transferMoney(from, to, amount) {
  // ... logic
}

After:

import __raceway from '@mode-7/raceway/runtime';

function transferMoney(from, to, amount) {
  __raceway.captureFunctionCall('transferMoney', { from, to, amount }, {
    file: __filename,
    line: 1
  });
  // ... logic
}

Variable Assignments

Before:

account.balance = newBalance;

After:

__raceway.captureStateChange('account.balance', newBalance, undefined, '5'),
account.balance = newBalance;

Async Operations

Before:

const result = await fetchData();

After:

__raceway.captureCustom('await', { location: '10' });
const result = await fetchData();

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | racewayInstance | string | '__raceway' | Name of raceway runtime variable | | instrumentFunctions | boolean | true | Instrument function declarations | | instrumentAssignments | boolean | true | Instrument variable assignments | | instrumentAsync | boolean | true | Instrument async/await | | exclude | string[] | [] | File patterns to exclude |

Examples

Minimal Configuration

// babel.config.js
module.exports = {
  plugins: ['babel-plugin-raceway']
};

Custom Configuration

// babel.config.js
module.exports = {
  plugins: [
    ['babel-plugin-raceway', {
      racewayInstance: 'raceway',
      instrumentFunctions: true,
      instrumentAssignments: false, // Skip variable tracking
      instrumentAsync: true,
      exclude: ['**/*.test.js', '**/mocks/**']
    }]
  ]
};

With TypeScript

// babel.config.js
module.exports = {
  presets: [
    '@babel/preset-typescript'
  ],
  plugins: [
    'babel-plugin-raceway'
  ]
};

Runtime Setup

Initialize the Raceway runtime in your application entry point:

// app.js or server.js
import { initializeRuntime } from '@mode-7/raceway/runtime';
import express from 'express';

// Initialize Raceway runtime before any instrumented code runs
const raceway = initializeRuntime({
  serverUrl: process.env.RACEWAY_URL || 'http://localhost:8080',
  serviceName: process.env.SERVICE_NAME || 'my-service',
  environment: process.env.NODE_ENV || 'development'
});

const app = express();

// Install middleware for request context
app.use(raceway.getInstance().middleware());

// Your routes - automatically instrumented by Babel!
app.post('/api/transfer', (req, res) => {
  const { from, to, amount } = req.body;

  // All variable access automatically tracked!
  const balance = accounts[from].balance;
  if (balance < amount) {
    return res.status(400).json({ error: 'Insufficient funds' });
  }

  accounts[from].balance -= amount;
  accounts[to].balance += amount;

  res.json({ success: true });
});

app.listen(3000);

Performance

  • Instrumentation adds ~10-50μs per event
  • Events are batched and sent asynchronously
  • Minimal impact on application performance
  • Can be disabled via configuration

Limitations

  • Does not instrument eval() or dynamically generated code
  • Arrow functions without blocks are converted to block statements
  • Destructuring assignments are captured as single events

Troubleshooting

Plugin not working

  1. Check Babel is configured correctly: npx babel --version
  2. Verify plugin is in package.json dependencies
  3. Clear Babel cache: rm -rf node_modules/.cache

Too many events

Reduce instrumentation scope:

{
  "plugins": [
    ["babel-plugin-raceway", {
      "instrumentFunctions": true,
      "instrumentAssignments": false, // Disable variable tracking
      "instrumentAsync": false,
      "exclude": ["**/lib/**", "**/vendor/**"]
    }]
  ]
}

Build errors

Make sure you have required presets:

npm install --save-dev @babel/preset-env @babel/preset-typescript

License

MIT