# vinyl-sources

> Record and read sources used to transform a vinyl file

Latest version **1.0.1** (published 2015-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install vinyl-sources
pnpm add vinyl-sources
yarn add vinyl-sources
bun add vinyl-sources
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-06-20 |
| First published | 2015-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stephen Taylor |
| Maintainers | meandmycode |
| Keywords | vinyl, cache, dependencies, sources, gulp |

## Links

- npm: https://www.npmjs.com/package/vinyl-sources
- Repository: https://github.com/meandmycode/vinyl-sources
- Issues: https://github.com/meandmycode/vinyl-sources/issues
- npm.io page: https://npm.io/package/vinyl-sources

## Dependencies (1)

- [vinyl](https://npm.io/package/vinyl.md) ^0.5.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-06-20
- 1.0.0 — 2015-05-30
- 0.1.0 — 2015-04-05

## README

# vinyl-sources

Record and read sources used to transform a vinyl file.

[![NPM Version](https://img.shields.io/npm/v/vinyl-sources.svg)](https://www.npmjs.com/package/vinyl-sources)
[![Build Status](https://img.shields.io/travis/meandmycode/vinyl-sources.svg)](https://travis-ci.org/meandmycode/vinyl-sources)
[![Coveralls Status](https://coveralls.io/repos/meandmycode/vinyl-sources/badge.png)](https://coveralls.io/r/meandmycode/vinyl-sources)
[![Dependency Status](https://david-dm.org/meandmycode/vinyl-sources.png?theme=shields.io)](https://david-dm.org/meandmycode/vinyl-sources)


## Installation

```
npm install vinyl-sources
```

## Usage

```js
var sources = require('vinyl-sources');
sources.record(vinylFile, sourcePaths);
```

## Example (gulp plugin)

```js
var through = require('through2');
var sources = require('vinyl-sources');
var myTransform = require('myTransform');

module.exports = function(options) {

  return through.obj(function transform(file, encoding, callback) {

    var result = myTransform(file.contents, options);
    file.contents = new Buffer(result.code);

    // record transformation sources to the vinyl file
    sources.record(file, result.sources);

    callback(null, file);

  });

};
```

## Example (iterating sources)

```js
var through = require('through2');
var sources = require('vinyl-sources');

module.exports = function(options) {

  return through.obj(function transform(file, encoding, callback) {
  
    sources.iterateSources(file, function(source, sourcePath) {
    
      // `source` is a vinyl file representing a single source file
      // `sourcePath` is an array of vinyl files representing the in-order ancestry of the current `source`
      // i.e., when a source file also has sources of it's own, this callback will be called with each child 
      // source and the parent source will be `sourcePath[0]`.
    
    });

    callback(null, file);

  });

};
```

## Example (getting all sources)

```js
var through = require('through2');
var sources = require('vinyl-sources');

module.exports = function(options) {

  return through.obj(function transform(file, encoding, callback) {
  
    var fileSources = sources.getSources(file);
    
    // `fileSources` is an array of all sources (direct sources of `file` and sources of sources)

    callback(null, file);

  });

};
```

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