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

mf-types-bundler

v0.1.1

Published

Bundle public Module Federation declaration files for @mf-types.zip

Readme

mf-types-bundler

mf-types-bundler bundles the public declaration surface of a Module Federation remote into a compact @mf-types.zip archive.

It is designed for @module-federation/enhanced remotes that already generate DTS artifacts and need a smaller, host-compatible type archive containing only the exposed modules.

Use Cases

  • Replace large compiled-types/** archives with one declaration file per exposed module.
  • Validate that generated remote declarations do not leak private aliases or relative source imports.
  • Run a host-like TypeScript smoke check before publishing @mf-types.zip.
  • Keep the bundling logic reusable and independent from any application-specific route or component names.

Installation

npm install --save-dev mf-types-bundler

For local development with a file: dependency, build this package before loading the consuming MF config:

npm run build

Published packages are built by the prepack lifecycle before packing or publishing. Generated dist/ files are not committed.

Quick Start

const { createFederatedTypesBundler } = require('mf-types-bundler');

const name = 'remoteApp';
const exposes = {
  './Button': './src/Button.tsx',
};

module.exports = {
  name,
  exposes,
  dts: {
    generateTypes: {
      afterGenerate: createFederatedTypesBundler({
        exposes,
        name,
        shared: {
          react: { singleton: true },
          'react-dom': { singleton: true },
        },
        tsconfigPath: './tsconfig.json',
      }),
      tsConfigPath: './tsconfig.json',
    },
  },
};

See runnable-style snippets in examples/.

Agent Guide

If you are an agent integrating this package into another project, read agent-docs/using-mf-types-bundler.md before changing code.

Public API

createFederatedTypesBundler(options)

Creates an afterGenerate hook for @module-federation/enhanced DTS generation.

const { createFederatedTypesBundler } = require('mf-types-bundler');

Use this when a remote already has Module Federation exposes and dts.generateTypes configured.

bundleFederatedTypes(options)

Runs the bundling pipeline directly. This is useful for scripts and tests.

const { bundleFederatedTypes } = require('mf-types-bundler');

await bundleFederatedTypes({
  exposes: {
    './Button': './src/Button.tsx',
  },
  name: 'remoteApp',
  shared: {
    react: { singleton: true },
  },
  zipTypesPath: './dist/@mf-types.zip',
});

createFederatedTypesAssetSyncPlugin(options?)

Creates a small Webpack plugin that syncs the rewritten @mf-types.zip from disk back into the compilation assets.

Use this when Webpack emits the original zip asset before the afterGenerate hook has rewritten the file on disk.

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | name | string | required | Module Federation remote name. Used for host-like smoke imports. | | exposes | Record<string, string | { import?: string | string[] }> | required | Module Federation exposes map. | | shared | string[] | Record<string, unknown> | undefined | Shared packages that should stay external in declarations. | | externalPackages | Iterable<string> | { allow?: Iterable<string> } | undefined | Additional packages allowed in public declarations. | | allowedSideEffectImports | (string | RegExp)[] | [] | Side-effect imports that may remain in declarations. | | cwd | string | process.cwd() | Project root. | | tsconfigPath | string | ./tsconfig.json | TypeScript config used by tsdown and internal alias detection. | | packageJsonPath | string | ./package.json | Package file used to read peerDependencies. | | tempDir | string | .mf/types-bundler | Temporary build, verification, and diagnostics directory. | | verify | boolean | true | Run host-like TypeScript smoke check after rewriting the zip. | | diagnostics | boolean | true | Write diagnostics JSON to tempDir/latest.json. | | zipTypesPath | string | required for bundleFederatedTypes | Path to @mf-types.zip. Supplied by afterGenerate for hook usage. |

How It Works

  1. Reads Module Federation exposes and creates one declaration entry per expose.
  2. Reads package.json peerDependencies, MF shared, and explicit externalPackages to build the external package allowlist.
  3. Reads tsconfig.paths and treats those path aliases as internal imports that must not leak to hosts.
  4. Uses tsdown with DTS generation to bundle each exposed module into a public .d.ts file.
  5. Removes asset/style side-effect imports from the bundled declarations.
  6. Preserves non-asset side-effect imports so validation can reject them instead of hiding them.
  7. Validates declarations for relative imports, internal aliases, file imports, forbidden side effects, and non-allowlisted packages.
  8. Rewrites @mf-types.zip, removing compiled-types/** and replacing expose entries with bundled declarations.
  9. Extracts the rewritten zip into a host-like @mf-types/<remoteName>/ layout and runs TypeScript against imports such as remoteName/exposeName.
  10. Writes diagnostics to .mf/types-bundler/latest.json unless disabled.

Development

npm ci
npm run typecheck
npm test
npm run build
npm run pack:dry

dist/ is generated and ignored. CI builds it from source.

Requirements

  • Node.js >=20.19.0
  • TypeScript >=5
  • A Module Federation remote using @module-federation/enhanced DTS generation

Non-Goals

  • No CLI in v1.
  • No app-specific expose or route logic.
  • No compatibility alias for older local helper names.
  • No consumer-only host type fetching.