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

rollup-ns

v1.1.1

Published

The node tool to rollup es6 typescript modules to single source file.

Readme

rollup-ns

The ES6 to global namespace code transformation utility.

Rollup-ns is a node command producing a single (rolled-up) Namespace'd source code from the source ES6 modules.

Why?

To support single-file namespace organized module output from the ES6 modularized solution. While transpiling and module bundling can solve much but this is not addressable by any of these tools. This scenario is not supported by the typescript compiler, and bundle tools like babel or rollup.

rollup-ns solves this scenario with custom source file transformation and module imports aware target namespace source code building.

How it works?

  • rollup-ns reads all the ES6 modules in the given directory and subdirectories.
  • changes original ES6 imports to namespace type imports.
  • generates one single file containing the namespace organized modules.

Note: rollup-ns never changes the original sources but always rewrite the single output file. If you are customizing the generated namespaces use declaration merging and never make changes to the generated file.

Configuration

Rollup-ns supports configuring the source folder, the target file and namespace. It also has configuration option for ignoring files (such as test files, or other support files) from the generated output.

rollup-ns.config.js

/*
 * rollup-ns configuration.
 */
module.exports = {
	//set the target file 
	target: './generated/out.ts',

	//sets the target namespace 
	targetNs: 'Target.Namespace',

	//sets the source directory where the source es6 modules are located
	src: '../source/directory/',

	//enable/disable the target prettier.
	pretty: true,

	//excluded files...
	exclude: [
		//ignore the ES6 module index file (exports)
		'**/**/index.ts',

		//ignore the polyfill module.
		'**/**/polyfills.ts',

		//exclude all spec
		'**/*.[s|S]pec.ts',

		//exclude all test
		'**/*.[t|T]est.ts',

		//exclude all js files.
		'**/*.js',
    ],
    
    //the external types...
    externalTypes: [
        'Error',
    ]
};

Source Limitations

  1. import * as 'es6-namespace-name' module import is not supported.

rollup-ns needs named imports like this:

import { TypeName } from 'module';

where the imported module defines the type like this:

export type TypeName = 'a' | 'b' | 'c';
  1. imports from re-exporting modules are not supported.

Example

Basic source files

./ClassA.ts

import { EnumA } from './EnumA';

export class ClassA {
    enumField: EnumA;
}

./EnumA.ts

export enum EnumA {
    A,
    B,
    C
}

./SubFolder/ClassB.ts

import { ClassA } from '../ClassA';
import { EnumB } from './EnumB';

export class ClassB extends ClassA {
    subEnum: EnumB;
}

./SubFolder/EnumB.ts

export enum EnumB {
    A,
    B,
    C
}

Generated

The generated single output file using Samples.Basic target namespace.

//this file has been generated by rollup-ns
namespace Samples.Basic
{
export enum EnumA {
    A,
    B,
    C
}
}
namespace Samples.Basic
{
export class ClassA {
    enumField: EnumA;
}
}
namespace Samples.Basic.SubFolder
{
export enum EnumB {
    A,
    B,
    C
}
}
namespace Samples.Basic.SubFolder
{
export class ClassB extends ClassA {
    subEnum: EnumB;
}
}

Versions

  • 1.0 : Initial release
  • 1.1 : Add support for Global augmentations (such as extending Window or Array)
    Add support for External Packages.