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 🙏

© 2026 – Pkg Stats / Ryan Hefner

babel-plugin-report-runtime-free-files

v1.0.0

Published

A Babel plugin that detects and reports files with or without runtime-executing code.

Readme

🌿 babel-plugin-report-runtime-free-files

Babel plugin that detects and reports files with or without runtime-executing code.

Table of Contents

Overview

This Babel plugin inspects a file and determines whether it includes any code that runs at runtime. It reports the result to a callback function, allowing developers to act on this information as needed.

The tree below shows the dist folder after building this plugin using the plugin itself. Files without runtime code are excluded from the cjs and esm folders, while their type declarations remain available under types.

  dist
  ├── cjs
  │   ├── index.cjs
  │   ├── plugin.cjs
  │   ├── program.cjs
  │   └── visitor.cjs
  ├── esm
  │   ├── index.mjs
  │   ├── plugin.mjs
  │   ├── program.mjs
  │   └── visitor.mjs
  └── types
      ├── callback-function.d.ts
      ├── index.d.ts
      ├── plugin-options.d.ts
      ├── plugin.d.ts
      ├── post-handler-function.d.ts
      ├── pre-handler-function.d.ts
      ├── program.d.ts
      ├── visitor-options.d.ts
      └── visitor.d.ts

Scope

The plugin classifies each file as either runtime or runtime-free. This makes it possible to exclude unnecessary files from the final build, minimizing distribution size and reducing payloads.

Runtime-free files may include:

  • TypeScript files (not just .d.ts) that only declare types
  • JavaScript files that contain only comments or @typedef annotations
  • Completely empty files

This plugin does not modify or exclude any files by itself. It only reports them. Decisions about what to do with the reported files are left to the developer.

Installation

The package is available on npm. It can be installed using any compatible package manager.

npm install --save-dev babel-plugin-report-runtime-free-files

Usage

Add the plugin to the Babel configuration, as shown in the example below.

/**
 * @import {
 *   type Options as RuntimeFreeFileReporterOptions,
 * } from "babel-plugin-report-runtime-free-files";
 */

/**
 * @type {RuntimeFreeFileReporterOptions}
 */
const runtimeFreeFileReporterOptions = {
  callback: (
    programNode,
    programState,
    isRuntimeFree,
  ) =>
  {
    // Handle the result for the file here.
  },
  post: (file) =>
  {
    // Run logic after the plugin has processed this file.
  },
  pre: (file) =>
  {
    // Run logic before the plugin processes this file.
  },
};

module.exports = {
  plugins: [
    [
      require.resolve("babel-plugin-report-runtime-free-files"),
      runtimeFreeFileReporterOptions,
    ],
  ],
};

Note: Babel CLI transpiles files one by one. The pre and post hooks run per file. To apply global logic across all files, consider using the Babel API via @babel/core in a custom script. This allows one-time pre/post behavior across the entire build process.

Options

The plugin supports the following options:

  • callback: Runs for each file processed. Parameters:
    • programNode (NodePath<Program>)
    • programState (PluginPass)
    • isRuntimeFree (boolean)
  • post: Runs before processing a file. Parameters:
    • file (BabelFile)
  • pre: Runs after processing a file. Parameters:
    • file (BabelFile)

Technical Details

The logic for determining whether a file is runtime free is implemented in the src/program.ts file, within the isProgramRuntimeFree function.

Non-runtime Constructs

The following node types are considered non-runtime:

  • ImportDeclaration with importKind set to type
  • ImportDeclaration where all specifiers are ImportSpecifier with importKind set to type or typeof
  • TSImportEqualsDeclaration with importKind set to type
  • ExportNamedDeclaration with exportKind set to type
  • TSInterfaceDeclaration
  • TSModuleDeclaration
  • TSTypeAliasDeclaration

If a file includes any node type outside this list, it is classified as containing runtime code.

Practical Example

This plugin is used in its own build process. Several source files contain only type declarations:

These files are omitted from cjs and esm outputs but remain available in types as .d.ts files.

Build steps are defined in package.json file, and the post-bootstrap script located in the hack directory.

License

This project is licensed under the MIT License. See the LICENSE file for details.