3.3.0 • Published 9 months ago

@favware/rollup-type-bundler v3.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

rollup-type-bundler

A small CLI tool to bundle types with rollup

GitHub npm bundle size npm Depfu

Support Server

Description

When creating a library with TypeScript you will often be able to just publish it with your current toolset, however once your library grows and grows then you might want to make it possible for people of your library to use TypeScript Module Augmentation to merge additional types into the types that you provide.

This however introduces a big issue in TypeScript. Even when re-exporting all your interfaces/types/classes in a root index.d.ts that you are referencing in "types" in your package.json, TypeScript still won't properly apply folder-nested (i.e. a type that's in your-package/dist/lib/structures/SomeClass.d.ts) module augmentation when augmenting with:

declare module 'your-package' {}

Without this package your users would have to augment the type with:

declare module 'your-package/dist/lib/structures/SomeClass' {}

this is extremely bad developer experience because you cannot apply all module augmentations in 1 block. To solve this issue, there is this library.

How this works

The library uses rollup with rollup-plugin-dts under the hood. It will execute a few steps:

  1. It cleans the configured dist directory (--dist flag or dist in config).
  2. It calls the --build-script (or buildScript in config) to build your code with your compiler. This defaults to build.
  3. It executes rollup to bundle your types into 1 index.d.ts file, output to the configured dist directory.
  4. It removes all other .d.ts and .d.ts.map files from your configured dist directory as they are now superfluous.

Installation

You can use the following command to install this package, or replace npm install -D with your package manager of choice.

npm install -D @favware/rollup-type-bundler

Or install it globally:

npm install -g @favware/rollup-type-bundler

Then call the script with rollup-type-bundler or rtb:

rollup-type-bundler --dist ./dist # Add any other flags or use --help
rtb --dist ./dist # Add any other flags or use --help

Alternatively you can call the CLI directly with npx:

npx @favware/rollup-type-bundler --dist ./dist # Add any other flags or use --help

Usage

You can provide all options through CLI flags:

Usage: rollup-type-bundler [options]

Options:
  -V, --version                     output the version number
  -d, --dist <dist>                 The dist directory to target
  -b, --build-script [buildScript]  The build script to call after cleaning your dist directory (default: "build")
  -v, --verbose                     Print verbose information (default: false)
  -e, --external [external...]      Repeatable, each will be treated as a new entry. Library or libraries to treat as external in Rollup (see:
                                    https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) (default: [])
  -h, --help                        display help for command

Or you can provide most of these options through a configuration file. The following files are supported:

  • .rollup-type-bundlerrc
  • .rollup-type-bundlerrc.json
  • .rollup-type-bundlerrc.yaml
  • .rollup-type-bundlerrc.yml

The file should either be located at the current working directory from where this rollup-type-bundler is called, or provided as a custom path with --config.

Fields in config file

  • --dist maps to dist
  • --build-script maps to buildScript
  • --verbose maps to verbose
  • --external maps to external

When using .rollup-type-bundlerrc or .rollup-type-bundlerrc.json as your config file you can also use the JSON schema to get schema validation. Add to your config file:

{
  "$schema": "https://raw.githubusercontent.com/favware/rollup-type-bundler/main/assets/rollup-type-bundler.schema.json"
}

Example JSON file:

{
  "$schema": "https://raw.githubusercontent.com/favware/rollup-type-bundler/main/assets/rollup-type-bundler.schema.json",
  "dist": "./dist",
  "buildScript": "build",
  "verbose": true,
  "external": ["stream", "url"]
}

Example Yaml file:

dist: './dist'
buildScript: build
verbose: true
external:
  - stream
  - url

Buy us some doughnuts

Favware projects is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and various crypto currencies. You can use the buttons below to donate through your method of choice.

Donate WithAddress
Ko-fiClick Here
PatreonClick Here
PayPalClick Here
GitHub SponsorsClick Here
Bitcoin1E643TNif2MTh75rugepmXuq35Tck4TnE5
Ethereum0xF653F666903cd8739030D2721bF01095896F5D6E
LiteCoinLZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

3.3.1-next.55e5d1f

9 months ago

3.3.1-next.88fc29c

9 months ago

3.3.1-next.7878f4a

9 months ago

3.3.1-next.a125641

9 months ago

3.3.1-next.80440e6

9 months ago

3.3.1-next.b9334d0

10 months ago

3.3.1-next.da141f8

9 months ago

3.3.1-next.a4ec87e

9 months ago

3.3.1-next.a959f0b

10 months ago

3.3.1-next.e054029

10 months ago

3.3.1-next.2c53d1f

10 months ago

3.3.1-next.1f47f0e

11 months ago

3.3.1-next.cbce40b

12 months ago

3.3.1-next.55a86e2

11 months ago

3.3.1-next.4f6dbcc

11 months ago

3.3.1-next.3687c69

11 months ago

3.3.1-next.90db489

11 months ago

3.3.1-next.b31b7c2

12 months ago

3.3.1-next.eec96d6

11 months ago

3.3.1-next.74bd21e

12 months ago

3.3.1-next.f8a40f1

12 months ago

3.3.1-next.b8aa10d

12 months ago

3.3.0

1 year ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.0.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1-next.0

4 years ago