Detalhes do pacote

@favware/rollup-type-bundler

favware16.5kMIT4.0.0

A small CLI tool to bundle types with rollup

favware, typescript, ts, yarn

readme (leia-me)

# rollup-type-bundler A small CLI tool to bundle types with rollup GitHub npm Support Server

Description

When you create a library in TypeScript, you will often be able to just publish it with your current toolset; however, once your library grows and grows, 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.

Unfortunately, this 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 module augmentation (i.e. a type that's in your-package/dist/lib/structures/SomeClass.d.ts) when augmenting like this:

declare module 'your-package' {}

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

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

As you might guess, this is extremely bad developer experience because you cannot apply all module augmentations in 1 block. That's where this rollup module comes in - now, you can bundle types in a developer-friendly way and make life easier for everyone involved.

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 distribution directory (--dist flag or dist in config).
    • This can be skipped by configuring --no-clean
  2. It calls the --build-script (or buildScript in config) to build your code with your compiler. This defaults to build.
    • This can be skipped by configuring --no-build
  3. It executes rollup to bundle your types into 1 index.d.ts (extension can be customized through --output-typings-file-extension) 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. (This can be skipped by providing --no-clean, or alternatively files can be excluded from the clean step by providing --exclude-from-clean).

Note: You can combine --no-clean and --no-build by using --only-bundle.

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
  -nb, --no-build [noBuild]                                          When enabled (default: false) the build step will not be called. Useful if you want to only bundle types and
                                                                     handle building yourself.
  -nc, --no-clean [noClean]                                          When enabled (default: false) the clean step will not be called. Useful if you want to only bundle types and
                                                                     handle cleaning yourself.
  -ob, --only-bundle [onlyBundle]                                    A shortcut to enabling both `--no-build` and `--no-clean`. This essentially makes it so rollup-type-bundler
                                                                     only deals with bundling types and nothing else.
  -t, --typings-file-extension [typingsFileExtension]                The input file extension for your typings files. Useful if you want to set `.cts` or `.mts`. If you forego
                                                                     adding a prefixing dot (`.`), it will be added for you.
  -ot, --output-typings-file-extension [outputTypingsFileExtension]  The output file extension for your typings files. Useful if you want to set `.cts` or `.mts`. If you forego
                                                                     adding a prefixing dot (`.`), it will be added for you. Defaults to the value of "typingsFileExtension"
  -v, --verbose                                                      Print verbose information
  -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)
  -ec, --exclude-from-clean [excludeFromClean...]                    Repeatable, each will be treated as a new entry.
                                                                     Files to be excluded from the clean step, useful if you want to process those files manually yourself later.
                                                                     This is in particular useful if you have multiple entrypoints.
                                                                     Note that a String#endsWith check is used to check if an entry in this array matches a path of a file to
                                                                     delete. So you can either use the full relative path, or just the file name.
  -h, --help                                                         display help for command

Or, you can set most of these options through a configuration file. This file should be located at your current working directory (where you're calling this package). It should be named .rollup-type-bundlerrc, optionally suffixed with .json, .yaml, or .yml.

Config file fields

  • --dist maps to dist
  • --build-script maps to buildScript
  • --no-build maps to noBuild
  • --no-clean maps to noClean
  • --only-bundle maps to onlyBundle
  • --typings-file-extension maps to typingsFileExtension
  • --output-typings-file-extension maps to outputTypingsFileExtension
  • --verbose maps to verbose
  • --external maps to external
  • --exclude-from-clean maps to excludeFromClean

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. To do so, add the following 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

Default values

This library has opinionated defaults for its options. These are as follows:

  • --dist will default to ./dist, using the current working directory as the reference point for the relative path.
  • --build-script will default to build.
  • --no-build will default to false.
  • --no-clean will default to false.
  • --only-bundle will default to false.
  • --typings-file-extension will default to .ts.
  • --output-typings-file-extension will default to the value of --typings-file-extension.
  • --verbose will default to false.
  • --external will default to [].
  • --exclude-from-clean will default to [].

Buy us some doughnuts

Favware projects are 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 cryptocurrencies. You can use the buttons below to donate through your method of choice.

Donate With Address
Ko-fi Click Here
Patreon Click Here
PayPal Click Here
GitHub Sponsors Click Here
Bitcoin 1E643TNif2MTh75rugepmXuq35Tck4TnE5
Ethereum 0xF653F666903cd8739030D2721bF01095896F5D6E
LiteCoin LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6

Contributors

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to Sapphire!

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

4.0.0 - (2025-01-05)

🏠 Refactor

  • Remove various single dash aliases for commander v13 compatibility (2d8e3ef)
    • 💥 BREAKING CHANGE: Removed -nb as alias for --no-build
    • 💥 BREAKING CHANGE: Removed -nc as alias for --no-clean
    • 💥 BREAKING CHANGE: Removed -ob as alias for --only-bundle
    • 💥 BREAKING CHANGE: Removed -ot as alias for --output-typings-file-extension
    • 💥 BREAKING CHANGE: Removed -ec as alias for --exclude-from-clean

🐛 Bug Fixes

  • deps: Update dependency commander to v13 (1f14146)
  • deps: Update all non-major dependencies (9db03a4) (#334 by @renovate[bot])
  • deps: Update dependency rollup to ^4.27.2 (8802523) (#329 by @renovate[bot])
  • deps: Update all non-major dependencies (d9f24a6) (#328 by @renovate[bot])
  • deps: Update all non-major dependencies (55e5d1f) (#325 by @renovate[bot])
  • deps: Update dependency rollup to ^4.24.0 (a4ec87e) (#320 by @renovate[bot])
  • deps: Update dependency rollup to ^4.21.0 (3687c69) (#312 by @renovate[bot])
  • deps: Update all non-major dependencies (b92460e) (#298 by @renovate[bot])
  • deps: Update dependency rollup to ^4.16.0 (04adfaa) (#292 by @renovate[bot])
  • deps: Update dependency rollup to ^4.14.1 (ce8f0de) (#289 by @renovate[bot])
  • deps: Update dependency commander to v12 (471c556) (#274 by @renovate[bot])
  • deps: Update dependency rollup to ^4.9.6 (2e7b07f) (#270 by @renovate[bot])
  • deps: Update all non-major dependencies (dab6fb8) (#269 by @renovate[bot])

3.3.0 - (2024-01-15)

🐛 Bug Fixes

  • deps: Update all non-major dependencies (7d3130e)
  • deps: Update dependency rollup to ^4.9.1 (fbb0a45)

🚀 Features

  • Add --output-typings-file-extension to make it possible to customize the output file extension separately from the input file extension (4ec5e88)

3.2.1 - (2023-12-05)

🐛 Bug Fixes

  • Normalize path separators for excludeFromClean to ensure PowerShell & Sh support (66e6b28)

3.2.0 - (2023-12-03)

📝 Documentation

  • readme: Update readme to mention previously added options (13a9c7a)

🚀 Features

  • Add --exclude-from-clean option (a5ec99b)

3.1.0 - (2023-12-01)

🚀 Features

  • Add noBuild, noClean, and onlyBundle options (57254d5)

3.0.0 - (2023-12-01)

🐛 Bug Fixes

  • Update rollup to v4.5.2 (f548af3)
  • deps: Update dependency rollup to ^4.4.0 (5aded14)
  • deps: Update dependency rollup to ^4.1.1 (09c47a7)
  • deps: Update dependency rollup to v4 (#238) (3c7737c)
  • deps: Update dependency rollup to ^3.29.3 (d6daebb)
  • deps: Update dependency rollup to ^3.29.1 (5d65b9c)
  • deps: Update dependency rollup-plugin-dts to v6 (#228) (a65a87d)
  • deps: Update dependency commander to v11 (#211) (a27ba0f)
  • deps: Update dependency rollup to ^3.25.0 (112112e)
  • deps: Update dependency rollup to ^3.21.2 (#202) (e1e1640)
  • deps: Update dependency rollup to ^3.14.0 (637025b)
  • deps: Update dependency rollup to ^3.5.0 (5612d29)

📝 Documentation

  • readme: Remove all contributors (910d562)

🚀 Features

  • Add support for custom typings file extensions (06f37d1)
  • Bump minimum NodeJS version to 18 (0d6ad56)
    • 💥 BREAKING CHANGE: This update drops support for NodeJS v14 and NodeJS v16, please update to v18 or higher.
  • Update to Commander v10 (a6d0e74)
    • 💥 BREAKING CHANGE: Drops support for Node 14

2.0.0 - (2022-10-16)

🏠 Refactor

  • Bump to v2.0.0 (654e4c7)
    • 💥 BREAKING CHANGE: This package now depends on Rollup v3 and rollup-plugin-dts v5. Please refer to their changelogs for further breaking changes.

🐛 Bug Fixes

  • deps: Update dependency rollup-plugin-dts to v5 (#161) (154423f)
  • deps: Update dependency rollup to v3 (#160) (b8a49c4)
  • deps: Update dependency rollup-plugin-dts to ^4.2.3 (#156) (a4e2715)
  • deps: Update dependency @sapphire/utilities to ^3.11.0 (0c97ba2)
  • deps: Update dependency @sapphire/utilities to ^3.9.3 (#144) (982eb19)

1.0.11 - (2022-08-20)

🐛 Bug Fixes

  • Bump dependencies (8da26cf)
  • deps: Update dependency @sapphire/utilities to ^3.9.0 (54e9296)

1.0.10 - (2022-07-30)

🐛 Bug Fixes

  • Update dependecies (d7dda87)
  • deps: Update dependency @sapphire/utilities to ^3.7.0 (0af5319)

1.0.11 - (2022-08-20)

🐛 Bug Fixes

  • Bump dependencies (8da26cf)
  • deps: Update dependency @sapphire/utilities to ^3.9.0 (54e9296)

1.0.10 - (2022-07-30)

🐛 Bug Fixes

  • Update dependecies (d7dda87)
  • deps: Update dependency @sapphire/utilities to ^3.7.0 (0af5319)

1.0.10 - (2022-07-30)

🐛 Bug Fixes

  • Update dependecies (d7dda87)
  • deps: Update dependency @sapphire/utilities to ^3.7.0 (0af5319)

1.0.9 - (2022-06-26)

🐛 Bug Fixes

  • Fixed regression issue with externals after previous release (53f4272)

1.0.8 - (2022-06-22)

🐛 Bug Fixes

  • Properly handle commander defaults (3325288)

1.0.7 (2022-01-06)

Bug Fixes

  • add typescript to dependencies (ba3cfa8)
  • deps: update all non-major dependencies (d3642ac)

1.0.6 (2021-10-21)

Bug Fixes

  • remove use of timers api to ensure this library works with Node 14 (57c339e)

1.0.5 (2021-10-04)

Bug Fixes

  • deps: update all non-major dependencies (f6cc93f)
  • deps: update dependency colorette to ^2.0.14 (#32) (b0ac896)
  • use latest versions for dependencies (bfbce5c)

1.0.4 (2021-10-01)

Bug Fixes

  • deps: update dependency colorette to v2 (#28) (91e78dd)
  • deps: update dependency rollup to ^2.57.0 (418f97a)
  • deps: update dependency rollup-plugin-dts to v4 (#29) (1ce08d6)

1.0.3 (2021-07-12)

Bug Fixes

  • change engine requirement from Node 16 to Node 14 (6ba5e28)

1.0.2 (2021-07-04)

Bug Fixes

  • fixed rollup not outputting to disk (f2bcd33)

1.0.1 (2021-07-02)

Bug Fixes

  • set an opinionated default of "./dist" for the "--dist" option (3e6e096)

1.0.0 (2021-07-02)

Features

Bug Fixes

  • do not publish source maps (21c9d93)
  • ensure dist can be set through config file (9a1b102)
  • fixed file scanning in type bundler (9375549)
  • fixed getting config file paths (b644e3b)
  • use options.dist for filtering out index.d.ts in cleaning extraneous types (53fb21e)
  • wait for files to be build before running rollup (1eb2b07)

0.0.1-next.0 (2021-07-01)

Features

  • add base CLI tool and parsing options (785ac0c)
  • add build code and remove dist exist checking (b91b873)
  • add first 2 actions (a8ca033)
  • add JSON schema (a6b3987)
  • add README (ebbafdf)
  • add rollup bundling command step (b40916d)
  • add specifying dist and buildScript (c23325a)
  • scaffold up repo (6f579f0)

Bug Fixes

  • do not use cache for bundling types (ef5c57b)
  • exit on error of build and clean (958cd5f)