<commit_before>import RSVP from 'rsvp';
import Ember from 'ember';
import AssetLoadError from '../errors/asset-load';
import BundleLoadError from '../errors/bundle-load';
import JsLoader from '../loaders/js';
import CssLoader from '../loaders/css';

export function RETRY_LOAD_SECRET() { }

/**
 * Merges two manifests' bundles together and returns a new manifest.
 *
 * @param {AssetManifest} input
 * @param {AssetManifest} manifest
 * @return {AssetManifest} output
 */
function reduceManifestBundles(input, manifest) {
  // If manifest doesn't have any bundles, then no reducing to do
  if (!manifest.bundles) {
    return input;
  }

  // Merge the bundles together, checking for collisions
  return Object.keys(manifest.bundles).reduce((output, bundle) => {
    Ember.assert(`The bundle "${bundle}" already exists.`, !output.bundles[bundle]);
    output.bundles[bundle] = manifest.bundles[bundle];
    return output;
  }, input);
}

/**
 * A Service class to load additional assets into the Ember application.
 *
 * @class AssetLoader
 */
export default Ember.Service.extend({
  /**
   * Setup the caches for the service to use when loading assets.
   *
   * @override
   */
  init() {
    this._super(...arguments);

    this.__manifests = [];
    this._setupCache();
    this._initAssetLoaders();
  },

  /**
   * Adds a manifest to the service by merging its bundles with any previously
   * added manifests. Bundle collisions result in an error being thrown.
   *
   * @public
   * @method pushManifest
   * @param {AssetManifest} manifest
   * @return {Void}
   */
  pushManifest(manifest) {
    this.__manifests.push(manifest);
    this.__manifest = this.__manifests.reduce(reduceManifestBundles, { bundles: {} });
  },

  /**
   * Loads a bundle by fetching all of its assets and its dependencies.
   *
   * Returns a Promise that resolve when all assets have been loaded or rejects
   * when one of the assets fails to load. Subsequent calls will return the same
   * Promise.
   *
   * @public
   * @method loadBundle
   * @param {String} name
   * @param {Boolean} retryLoad Warning: only used internally to re-initiate loads, NOT public API
   * @return {Promise} bundlePromise
   */
  loadBundle(name, retryLoad) {
    const cachedPromise = this._getFromCache('bundle', name, retryLoad === RETRY_LOAD_SECRET);

    if (cachedPromise) {
      return cachedPromise;
    }
    
    const bundle = this._getBundle(name);

    const dependencies = bundle.dependencies || [];
    const dependencyPromises = dependencies.map((dependency) => this.loadBundle(dependency, retryLoad));

    const assets = bundle.assets || [];
    const assetPromises = assets.map((asset) => this.loadAsset(asset, retryLoad));

    const bundlePromise = RSVP.allSettled([ ...dependencyPromises, ...assetPromises ]);

    const bundleWithFail = bundlePromise.then((promises) => {
      const rejects = promises.filter((promise) => promise.state === 'rejected');
      const errors = rejects.map((reject) => reject.reason);

      if (errors.length) {<commit_msg>remove the extraneous whitespace<commit_after>import RSVP from 'rsvp';
import Ember from 'ember';
import AssetLoadError from '../errors/asset-load';
import BundleLoadError from '../errors/bundle-load';
import JsLoader from '../loaders/js';
import CssLoader from '../loaders/css';

export function RETRY_LOAD_SECRET() { }

/**
 * Merges two manifests' bundles together and returns a new manifest.
 *
 * @param {AssetManifest} input
 * @param {AssetManifest} manifest
 * @return {AssetManifest} output
 */
function reduceManifestBundles(input, manifest) {
  // If manifest doesn't have any bundles, then no reducing to do
  if (!manifest.bundles) {
    return input;
  }

  // Merge the bundles together, checking for collisions
  return Object.keys(manifest.bundles).reduce((output, bundle) => {
    Ember.assert(`The bundle "${bundle}" already exists.`, !output.bundles[bundle]);
    output.bundles[bundle] = manifest.bundles[bundle];
    return output;
  }, input);
}

/**
 * A Service class to load additional assets into the Ember application.
 *
 * @class AssetLoader
 */
export default Ember.Service.extend({
  /**
   * Setup the caches for the service to use when loading assets.
   *
   * @override
   */
  init() {
    this._super(...arguments);

    this.__manifests = [];
    this._setupCache();
    this._initAssetLoaders();
  },

  /**
   * Adds a manifest to the service by merging its bundles with any previously
   * added manifests. Bundle collisions result in an error being thrown.
   *
   * @public
   * @method pushManifest
   * @param {AssetManifest} manifest
   * @return {Void}
   */
  pushManifest(manifest) {
    this.__manifests.push(manifest);
    this.__manifest = this.__manifests.reduce(reduceManifestBundles, { bundles: {} });
  },

  /**
   * Loads a bundle by fetching all of its assets and its dependencies.
   *
   * Returns a Promise that resolve when all assets have been loaded or rejects
   * when one of the assets fails to load. Subsequent calls will return the same
   * Promise.
   *
   * @public
   * @method loadBundle
   * @param {String} name
   * @param {Boolean} retryLoad Warning: only used internally to re-initiate loads, NOT public API
   * @return {Promise} bundlePromise
   */
  loadBundle(name, retryLoad) {
    const cachedPromise = this._getFromCache('bundle', name, retryLoad === RETRY_LOAD_SECRET);

    if (cachedPromise) {
      return cachedPromise;
    }

    const bundle = this._getBundle(name);

    const dependencies = bundle.dependencies || [];
    const dependencyPromises = dependencies.map((dependency) => this.loadBundle(dependency, retryLoad));

    const assets = bundle.assets || [];
    const assetPromises = assets.map((asset) => this.loadAsset(asset, retryLoad));

    const bundlePromise = RSVP.allSettled([ ...dependencyPromises, ...assetPromises ]);

    const bundleWithFail = bundlePromise.then((promises) => {
      const rejects = promises.filter((promise) => promise.state === 'rejected');
      const errors = rejects.map((reject) => reject.reason);

      if (errors.length) {
{'fraction_non_alphanumeric': 0.12064737616478666, 'fraction_numerical': 0.0, 'mean_word_length': 3.565671641791045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1052810', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1717, 'n_words': 535}