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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@skymakerolof/dts-builder

v1.1.8

Published

Generates a definition library file from generated .d.ts sources

Downloads

3

Readme

DTS-Builder

Modern NodeJS TypeScript Modern JavaScript MIT License

Project status

Note: This project is in mainteinance mode.

This tool was created to help with a TS library that I was writing. However, I am no longer part of this project and also it seems that there are actively maintained tools out there that do the job in a smarter way than concanetation + regexp replacements.

If you are using dts-builder and find bugs, I'd be happy to fix them. If you want to improve, please create pull requests or fork and hack away :)

Rollup

If you are using Rollup to bundle your code, consider using https://github.com/Swatinem/rollup-plugin-dts plugin, it looks quite promising.

Synopsis

Assembles a singe library definition file by concatenating and cleaning up generated .d.ts files.

Returns a promise with the names of bundles that have been exported.

Code Example

const path = require('path');
const dtsBuilder = require('dts-builder');

const projectRoot = path.resolve(__dirname, '../..');

dtsBuilder.generateBundles([
  {
    name: 'myLib',
    sourceDir: `${projectRoot}/ts-built/`,
    destDir: `${projectRoot}/dist`,
    externals: [
      `${projectRoot}/src/ext/external-lib.d.ts`,
      `${projectRoot}/src/lib/types.d.ts`
    ]
  }
]);

Running this script will read all TS declaration files from sourceDir (${sourceDir}/**/*.d.ts), concatenate them and clean up the result. It will then be wrapped with a name module declaration (declare module ${name} { ... }). The result will be saved as ${name}.d.ts in destDir.

Additionally, if externals array is provided, all the files that are referenced by it will be prepended to the top of the resulting library file as /// <reference path="${basename(externals[i])}" /> and these files will be copied to destDir alongside the library file.

Motivation

A project that I am involved in has a large library that is being build using concatenation of ES5 files into a single .js package. The team moved to ES6 with modules, and I wanted to take it one notch further, and convert the 12k lines of code to TypeScript, for all the benefits.

However, I didn't find a good way to generate a single definition file that will act as a library. I started by playing with the generated d.ts files for each transpiled file to see how this can be achieved, and I created this simple script to remove and modify the result so it will be parsed well by tsc and will allow importing of the namespace.

Installation

npm install --save-dev dts-builder

API Reference

module dtsBuilder {
    function generateBundles(bundles: Array<Bundle>): Promise<Array<string>>;

    interface Bundle {
        /**
          * Bundle name. Used for d.ts filename and the wrapping namespace.
          * @type {string}
          */
        name: string;

        /**
          * Location in which to search for *.d.ts files
          * @type {string}
          */
        sourceDir: string;

        /**
          * Location in which to save the output, under the name: `${name}.d.ts`
          * @type {string}
          */
        destDir: string;

        /**
          * List of external d.ts files that will be copied to the destination
          * directory, and will be referenced from withing the main d.ts file
          * @type {Array<string>}
          */
        externals?: Array<string>;

        /**
          * Wrap resulting definitions in a namespace. Set to false if files are already wrapped
          * by namespaces.
          * Default: true
          * @type {boolean}
          */
        wrap?: boolean;

        /**
          * If specified, library will exported as the given value, as an alias together
          * with the original name.
          * @type {string}
          */
        alias?: string;
    }
}

Tests

Currently test is basic, checking for required module and builds the generate-self package under two names.

Contributors

Feel free to fork, improve and send PRs if it's generic in nature.

License

MIT © Boris Aranovič