npm package: @invisiburu/gulp-memoize
Description: A task memoize plugin for Gulp
Author: Maksym Nesterov
Latest version: 1.0.0

# gulp-memoize

[![NPM version][npm]][npm-url]
[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]

[npm]: https://img.shields.io/npm/v/gulp-memoize.svg
[npm-url]: https://www.npmjs.com/package/gulp-memoize

[node]: https://img.shields.io/node/v/gulp-memoize.svg
[node-url]: https://nodejs.org

[deps]: https://img.shields.io/david/invisiburu/gulp-memoize.svg
[deps-url]: https://david-dm.org/invisiburu/gulp-memoize

[build]: https://travis-ci.org/invisiburu/gulp-memoize.svg?branch=master
[build-url]: https://travis-ci.org/invisiburu/gulp-memoize

[coverage]: https://img.shields.io/coveralls/invisiburu/gulp-memoize.svg
[coverage-url]: https://coveralls.io/r/invisiburu/gulp-memoize

Based on the [gulp-cache](https://github.com/jgable/gulp-cache)

A task memoize proxy task for [gulp](http://gulpjs.com/).

## Install

```bash
npm i -D gulp-memoize
# or
yarn add -D gulp-memoize
```

## Usage

```js
import gulp from 'gulp';
import favicons from 'gulp-favicons';
import srcset from 'gulp-srcset';
import memoize from 'gulp-memoize';

gulp.task('favicon', () =>
    gulp.src('src/favicon.svg')
        .pipe(memoize(
            // Target plugin, the output of which will be memoized.
            favicons(faviconsConfig),
            // Options for `gulp-memoize` plugin.
            {
                // Report on every restored file
                verbose: true
            }
        ))
        .pipe(gulp.dest('./favicons'))
);

gulp.task('images', () =>
    gulp.src('src/**/*.{jpg,png,svg}')
        .pipe(memoize(srcset(srcsetRules)))
        .pipe(gulp.dest('./images'))
);
```

<details>
    <summary>Complex usage example</summary>

```js
import fs from 'fs';
import gulp from 'gulp';
import jshint from 'gulp-jshint';
import memoize from 'gulp-memoize';

const jsHintVersion = '2.4.1';
const jshintOptions = fs.readFileSync('.jshintrc');

function makeHashKey(file) {
    // Key off the file contents, jshint version and options
    return `${file.contents.toString('utf8')}${jshintVersion}${jshintOptions}`;
}

gulp.task('lint', () =>
    gulp.src('src/**/*.js')
        .pipe(memoize(
            // Target plugin, the output of which will be memoized.
            jshint('.jshintrc'),
            // Options for `gulp-memoize` plugin.
            {
                key: makeHashKey,
                verbose: true
            }
        ))
        .pipe(jshint.reporter('default'))
});
```

</details>

## API

### `memoize(pluginToMemoize [, options])`

#### `pluginToMemoize`

Target task, the output of which will be memoized.

#### `options`

Options for `gulp-memoize` plugin.

##### `options.verbose`

> [Optional] Should the plugin report on every restored file

- Defaults to `false`

##### `options.key`

> [Optional] What to use to determine the uniqueness of an input file for this task.

- Can return a string or a `Promise` that resolves to a string.

- The result of this method is converted to a unique MD5 hash automatically; no need to do this yourself.

- Defaults to `file.contents` if a Buffer, or `undefined` if a Stream.

##### `options.memo`

> [Optional] Custom Memo instance. Default is `new Map<string, Vinyl[]>()`.

- Should implement the [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) interface

- Keys of the Memo are strings, values are arrays of Vinyl files

##### `options.clearMemoOnFlush`

> [Optional] Should the memo be cleared after the task execution

- Defaults to `true`

## License

[The MIT License (MIT)](./LICENSE)

Copyright (c) 2021 - present [Maksym Nesterov](https://github.com/invisiburu)
Copyright (c) 2014 - present [Jacob Gable](http://jacobgable.com)