<commit_before>'use strict';

var PLUGIN_NAME = 'gulp-rollup';

var util         = require('util');
var gutil        = require('gulp-util');
var PluginError  = gutil.PluginError;
var File         = gutil.File;
var Transform    = require('readable-stream').Transform;
var hypothetical = require('rollup-plugin-hypothetical');
var path         = require('path');

function GulpRollup(options) {
  var self = this;

  Transform.call(self, { objectMode: true });

  options = options || {};

  var wonderland = {};
  var entries = [], haveSourcemaps;

  var entryFiles = Promise.resolve(options.entry).then(function(entryFiles) {
    if (typeof entryFiles === 'string') {
      return [entryFiles];
    } else if (Array.isArray(entryFiles)) {
      if (entryFiles.some(function(entryFile) {
        return typeof entryFile !== 'string';
      })) {
        throw new Error('options.entry must include only strings!');
      }
      return entryFiles;
    } else {
      throw new Error('options.entry must be a string or array of strings!');
    }
  });

  self._transform = function(file, enc, cb) {
    if (!file.isBuffer()) {
      self.emit('error', new PluginError(PLUGIN_NAME, 'Input files must be buffered!'));
      return cb();
    }

    if (haveSourcemaps === undefined) {
      haveSourcemaps = file.sourceMap !== undefined;
    } else if (haveSourcemaps !== (file.sourceMap !== undefined)) {
      self.emit('error', new PluginError(PLUGIN_NAME, 'Mixing of sourcemapped and non-sourcemapped files!'));
      return cb();
    }

    if (haveSourcemaps) {
      wonderland[file.path] = {
        code: file.contents.toString(),
        map:  file.sourceMap
      };
    } else {
      wonderland[file.path] = file.contents.toString();
    }

    // taking advantage of hypothetical's state-of-the-art resolving capabilities.
    var onederland = {}; // ohoho, funny pun. I laugh.
    onederland[file.path] = '';
    var finder = hypothetical({ files: onederland, allowRealFiles: true });
    // now let's see if this is an entry file.
    entryFiles = entryFiles.then(function(entryFiles) {
      entryFiles.forEach(function(entryFile, i) {
        if (!entries[i] && finder.resolveId(entryFile)) {
          entries[i] = file;
        }
      });
      return entryFiles;
    });

    cb();
  };<commit_msg>Select the last matching entry file rather than the first<commit_after>'use strict';

var PLUGIN_NAME = 'gulp-rollup';

var util         = require('util');
var gutil        = require('gulp-util');
var PluginError  = gutil.PluginError;
var File         = gutil.File;
var Transform    = require('readable-stream').Transform;
var hypothetical = require('rollup-plugin-hypothetical');
var path         = require('path');

function GulpRollup(options) {
  var self = this;

  Transform.call(self, { objectMode: true });

  options = options || {};

  var wonderland = {};
  var entries = [], haveSourcemaps;

  var entryFiles = Promise.resolve(options.entry).then(function(entryFiles) {
    if (typeof entryFiles === 'string') {
      return [entryFiles];
    } else if (Array.isArray(entryFiles)) {
      if (entryFiles.some(function(entryFile) {
        return typeof entryFile !== 'string';
      })) {
        throw new Error('options.entry must include only strings!');
      }
      return entryFiles;
    } else {
      throw new Error('options.entry must be a string or array of strings!');
    }
  });

  self._transform = function(file, enc, cb) {
    if (!file.isBuffer()) {
      self.emit('error', new PluginError(PLUGIN_NAME, 'Input files must be buffered!'));
      return cb();
    }

    if (haveSourcemaps === undefined) {
      haveSourcemaps = file.sourceMap !== undefined;
    } else if (haveSourcemaps !== (file.sourceMap !== undefined)) {
      self.emit('error', new PluginError(PLUGIN_NAME, 'Mixing of sourcemapped and non-sourcemapped files!'));
      return cb();
    }

    if (haveSourcemaps) {
      wonderland[file.path] = {
        code: file.contents.toString(),
        map:  file.sourceMap
      };
    } else {
      wonderland[file.path] = file.contents.toString();
    }

    // taking advantage of hypothetical's state-of-the-art resolving capabilities.
    var onederland = {}; // ohoho, funny pun. I laugh.
    onederland[file.path] = '';
    var finder = hypothetical({ files: onederland, allowRealFiles: true });
    // now let's see if this is an entry file.
    entryFiles = entryFiles.then(function(entryFiles) {
      entryFiles.forEach(function(entryFile, i) {
        if (finder.resolveId(entryFile)) {
          entries[i] = file;
        }
      });
      return entryFiles;
    });

    cb();
  };
{'fraction_non_alphanumeric': 0.13887100236102168, 'fraction_numerical': 0.0, 'mean_word_length': 2.8768718801996673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5019985', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1356, 'n_words': 350}