Code coverage report for lib/input/dependency.js

Statements: 100% (14 / 14)      Branches: 100% (2 / 2)      Functions: 100% (6 / 6)      Lines: 100% (14 / 14)      Ignored: none     

All files » lib/input/ » dependency.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50    25                                     25 68   118               68 69   68 68 4   68 64   109 109         25  
'use strict';
 
var mdeps = require('module-deps'),
  fs = require('fs'),
  path = require('path'),
  babelify = require('babelify'),
  concat = require('concat-stream'),
  moduleFilters = require('../../lib/module_filters');
 
/**
 * Returns a readable stream of dependencies, given an array of entry
 * points and an object of options to provide to module-deps.
 *
 * This stream requires filesystem access, and thus isn't suitable
 * for a browser environment.
 *
 * @param {Array<string>} indexes paths to entry files as strings
 * @param {Object} options optional options passed
 * @param {Function} callback called with (err, inputs)
 * @returns {undefined} calls callback
 */
function dependencyStream(indexes, options, callback) {
  var md = mdeps({
    filter: function (id) {
      return !!options.external || moduleFilters.internalOnly(id);
    },
    transform: [babelify.configure({
      sourceMap: false,
      stage: 0
    })],
    postFilter: moduleFilters.externals(indexes, options)
  });
  indexes.forEach(function (index) {
    md.write(path.resolve(index));
  });
  md.end();
  md.once('error', function (error) {
    return callback(error);
  });
  md.pipe(concat(function (inputs) {
    callback(null, inputs.map(function (input) {
      // un-transform babelify transformed source
      input.source = fs.readFileSync(input.file, 'utf8');
      return input;
    }));
  }));
}
 
module.exports = dependencyStream;