<commit_before>/* jshint node: true */
'use strict';

var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var writeFile = require('broccoli-file-creator');
var Babel = require('broccoli-babel-transpiler');
var getBabelOptions = require('./lib/get-babel-options');
var Rollup = require('./lib/rollup-with-dependencies');
var rollupReplace = require('rollup-plugin-replace');
var Funnel = require('broccoli-funnel');
var existsSync = require('exists-sync');
var hashForDep = require('hash-for-dep');
var addonUtils = require('./lib/addon-utils');

module.exports = {
  name: 'ember-service-worker',

  included: function(app) {
    if (this._super.included) {
      this._super.included.apply(this, arguments);
    }

    // Configures Ember CLI's build system to not add a fingerprint to sw.js
    this.app = app;
    this.app.options = this.app.options || {};
    this.app.options.fingerprint = this.app.options.fingerprint || {};
    this.app.options.fingerprint.exclude = this.app.options.fingerprint.exclude || [];
    this.app.options.fingerprint.exclude.push('sw.js');

    this._projectVersion = hashForDep(this.project.root);
  },

  postprocessTree: function(type, tree) {
    if (type !== 'all') {
      return tree;
    }

    var self = this;
    var plugins = this._findPluginsFor(this.project);

    var swjsTemplate = '';
    var registrationTemplate = '';
    var serviceWorkerTrees = [];
    var serviceWorkerRegistrationTrees = [];

    // Add the project itself as a possible plugin, this way user can add custom
    // service-worker code in their app, without needing to build a plugin.
    plugins = [this].concat(plugins, this.project);

    // Builds the trees for the sw.js asset and the service-worker registration
    // script.
    plugins.forEach(function(plugin) {
      var pluginServiceWorkerTree = self._serviceWorkerTreeFor(plugin);
      var pluginServiceWorkerRegistrationTree = self._serviceWorkerRegistrationTreeFor(plugin);
      var pluginName = addonUtils.getName(plugin);

      if (pluginServiceWorkerTree) {
        serviceWorkerTrees.push(pluginServiceWorkerTree);
        swjsTemplate += 'import "' + pluginName + '/service-worker";';
      }

      if (pluginServiceWorkerRegistrationTree) {
        serviceWorkerRegistrationTrees.push(pluginServiceWorkerRegistrationTree);
        registrationTemplate += 'import "' + pluginName + '/service-worker-registration";';
      }
    });

    serviceWorkerTrees.push(writeFile('sw.js', swjsTemplate));
    var serviceWorkerTree = mergeTrees(serviceWorkerTrees, { overwrite: true });

    serviceWorkerRegistrationTrees.push(writeFile('sw-registration.js', registrationTemplate));
    var serviceWorkerRegistrationTree = mergeTrees(serviceWorkerRegistrationTrees, { overwrite: true });

    serviceWorkerTree = this._rollupTree(serviceWorkerTree, 'sw.js');
    serviceWorkerRegistrationTree = this._rollupTree(serviceWorkerRegistrationTree, 'sw-registration.js');

    return mergeTrees([serviceWorkerTree, serviceWorkerRegistrationTree, tree], { overwrite: true });
  },

  contentFor: function(type, config) {
    if (type === 'body-footer' && config.environment !== 'test') {
      var rootURL = this._getRootURL();
<commit_msg>Only import index.js if present<commit_after>/* jshint node: true */
'use strict';

var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var writeFile = require('broccoli-file-creator');
var Babel = require('broccoli-babel-transpiler');
var getBabelOptions = require('./lib/get-babel-options');
var Rollup = require('./lib/rollup-with-dependencies');
var rollupReplace = require('rollup-plugin-replace');
var Funnel = require('broccoli-funnel');
var existsSync = require('exists-sync');
var hashForDep = require('hash-for-dep');
var addonUtils = require('./lib/addon-utils');

module.exports = {
  name: 'ember-service-worker',

  included: function(app) {
    if (this._super.included) {
      this._super.included.apply(this, arguments);
    }

    // Configures Ember CLI's build system to not add a fingerprint to sw.js
    this.app = app;
    this.app.options = this.app.options || {};
    this.app.options.fingerprint = this.app.options.fingerprint || {};
    this.app.options.fingerprint.exclude = this.app.options.fingerprint.exclude || [];
    this.app.options.fingerprint.exclude.push('sw.js');

    this._projectVersion = hashForDep(this.project.root);
  },

  postprocessTree: function(type, tree) {
    if (type !== 'all') {
      return tree;
    }

    var self = this;
    var plugins = this._findPluginsFor(this.project);

    var swjsTemplate = '';
    var registrationTemplate = '';
    var serviceWorkerTrees = [];
    var serviceWorkerRegistrationTrees = [];

    // Add the project itself as a possible plugin, this way user can add custom
    // service-worker code in their app, without needing to build a plugin.
    plugins = [this].concat(plugins, this.project);

    // Builds the trees for the sw.js asset and the service-worker registration
    // script.
    plugins.forEach(function(plugin) {
      var pluginServiceWorkerTree = self._serviceWorkerTreeFor(plugin);
      var pluginServiceWorkerRegistrationTree = self._serviceWorkerRegistrationTreeFor(plugin);
      var pluginName = addonUtils.getName(plugin);

      if (pluginServiceWorkerTree) {
        serviceWorkerTrees.push(pluginServiceWorkerTree);
        if (existsSync(pluginServiceWorkerTree._inputNodes[0]._inputNodes[0]._directoryPath + '/index.js')) {
          swjsTemplate += 'import "' + pluginName + '/service-worker";';
        }
      }

      if (pluginServiceWorkerRegistrationTree) {
        serviceWorkerRegistrationTrees.push(pluginServiceWorkerRegistrationTree);
        if (existsSync(pluginServiceWorkerRegistrationTree._inputNodes[0]._inputNodes[0]._directoryPath + '/index.js')) {
          registrationTemplate += 'import "' + pluginName + '/service-worker-registration";';
        }
      }
    });

    serviceWorkerTrees.push(writeFile('sw.js', swjsTemplate));
    var serviceWorkerTree = mergeTrees(serviceWorkerTrees, { overwrite: true });

    serviceWorkerRegistrationTrees.push(writeFile('sw-registration.js', registrationTemplate));
    var serviceWorkerRegistrationTree = mergeTrees(serviceWorkerRegistrationTrees, { overwrite: true });

    serviceWorkerTree = this._rollupTree(serviceWorkerTree, 'sw.js');
    serviceWorkerRegistrationTree = this._rollupTree(serviceWorkerRegistrationTree, 'sw-registration.js');

    return mergeTrees([serviceWorkerTree, serviceWorkerRegistrationTree, tree], { overwrite: true });
  },

  contentFor: function(type, config) {
    if (type === 'body-footer' && config.environment !== 'test') {
      var rootURL = this._getRootURL();

{'fraction_non_alphanumeric': 0.12932308601832693, 'fraction_numerical': 0.0005911912503694946, 'mean_word_length': 4.08033033033033, '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': '2024816', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1851, 'n_words': 398}