# rollup-timer

> Times Rollup plugins by monkey-patching plugin API functions.

Latest version **0.3.4** (published 2017-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-timer
pnpm add rollup-timer
yarn add rollup-timer
bun add rollup-timer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2017-03-13 |
| First published | 2016-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Tim De Pauw |
| Maintainers | timdp |

## Links

- npm: https://www.npmjs.com/package/rollup-timer
- Repository: https://github.com/timdp/rollup-timer
- Homepage: https://github.com/timdp/rollup-timer#readme
- Issues: https://github.com/timdp/rollup-timer/issues
- npm.io page: https://npm.io/package/rollup-timer

## Dependencies (6)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.1
- [is-stream](https://npm.io/package/is-stream.md) ^1.1.0
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^2.1.0
- [is-promise](https://npm.io/package/is-promise.md) ^2.1.0
- [stats-lite](https://npm.io/package/stats-lite.md) ^2.0.3

## Recent versions

- 0.3.4 (latest) — 2017-03-13
- 0.3.3 — 2017-03-12
- 0.3.2 — 2017-03-12
- 0.3.1 — 2016-07-07
- 0.3.0 — 2016-07-07
- 0.2.0 — 2016-07-05
- 0.1.0 — 2016-07-05

## README

# rollup-timer

[![npm](https://img.shields.io/npm/v/rollup-timer.svg)](https://www.npmjs.com/package/rollup-timer) [![Dependencies](https://img.shields.io/david/timdp/rollup-timer.svg)](https://david-dm.org/timdp/rollup-timer) [![Build Status](https://img.shields.io/travis/timdp/rollup-timer/master.svg)](https://travis-ci.org/timdp/rollup-timer) [![Coverage Status](https://img.shields.io/coveralls/timdp/rollup-timer/master.svg)](https://coveralls.io/r/timdp/rollup-timer) [![JavaScript Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

Times Rollup plugins by monkey-patching plugin API functions.

<p align="center"><img alt="Example"
src="https://raw.githubusercontent.com/timdp/rollup-timer/master/example.png"></p>

**Warning:** At the time of this writing, the latest version of
[rollup-plugin-commonjs](https://www.npmjs.com/package/rollup-plugin-commonjs)
is incompatible with rollup-timer. Until
[this issue](https://github.com/rollup/rollup-plugin-commonjs/issues/128) is
resolved, timings for rollup-plugin-commonjs will be incomplete.

## Installation

```bash
npm i --save-dev rollup-timer
```

## Usage

```js
import rollup from 'rollup'
import time from 'rollup-timer'

// Monkey-patch rollup.rollup and plugin API functions
time(rollup)

const options = {
  // ... Your Rollup options here ...
}
rollup.rollup(options)
  .then(function () {
    console.info('Done!')
  })
  .catch(function (err) {
    console.error(err)
  })
```

## Advanced

The `time` function returns a patched version of its input. Instead of passing
the full `rollup` exports, you can also just pass `rollup.rollup`. The code
above can therefore also be written as:

```js
import {rollup} from 'rollup' // ← Named import of rollup.rollup
import time from 'rollup-timer'

// Obtain a patched rollup function
const timedRollup = time(rollup)

// Use the patched function instead of the original
timedRollup(options)
  .then(function () {
    console.info('Done!')
  })
  .catch(function (err) {
    console.error(err)
  })
```

Additionally, if the function that you pass to `time` returns a stream rather
than a promise, reporting will occur on the stream's `end` event. This allows
you to use [rollup-stream](https://www.npmjs.com/package/rollup-stream) directly
as well.

## API

If you want more control, you can use the timer API directly. To do so, you
import the `RollupTimer` class instead of the default export `time()`. The class
has two member functions: `time(plugins)` and `report()`.

Although [rollup-stream](https://www.npmjs.com/package/rollup-stream) is
supported out of the box, here's an example that uses those two functions:

```js
// 1. Import rollup-stream and some plugins
import rollupStream from 'rollup-stream'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'

// 2. Import RollupTimer
import {RollupTimer} from 'rollup-timer'

// 3. Create timer
const timer = new RollupTimer()

const options = {
  plugins: timer.time([ // ← 4. Wrap your plugins in timer.time()
    nodeResolve({jsnext: true, main: true}),
    commonjs({include: 'node_modules/**'})
  ])
  // ... Add other Rollup options as usual ...
}
rollupStream(options)
  .once('end', function () {
    // 5. Write the timing report to the console
    timer.report()
    console.info('Done!')
  })
```

## Caveat

Rollup version 0.33.0 introduced the `name` property for plugins, which is used
in the report generated by rollup-timer. If a plugin has not been updated to
supply this property, the report will fall back to the numeric index of the
plugin, which doesn't look that great. In this case, you are encouraged to
submit a pull request for the plugin that adds its name.

## Author

[Tim De Pauw](https://tmdpw.eu/)

## License

MIT

---
_Source: https://npm.io/package/rollup-timer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
