<commit_before>/* jslint node: true, esnext: true */

function addKeyword(pkg, regex, keyword) {
  if (pkg.name.match(regex)) {
    if (!pkg.keywords.find(k => k === keyword)) {
      pkg.keywords.push(keyword);
    }
  }
}

export default function (target, template, context, options = {}) {
  target = JSON.parse(target);
  template = JSON.parse(template);

  context.properties.module = target.module;
  context.properties.main = target.main || 'indes.js';

  const deepPropeties = ['scripts', 'devDependencies', 'engines'];

  let extraBuild, buildOutput;

  if (target.scripts && target.scripts.build) {
    let m = target.scripts.build.match(/--output=([^\s]+)/);
    if (m) {
      buildOutput = m[1];
    }
    m = target.scripts.build.match(/\&\&\s*(.+)/);
    if (m) {
      extraBuild = m[1];
    }
  }

  deepPropeties.forEach(p => {
    if (target[p] === undefined) {
      target[p] = {};
    }
    Object.assign(target[p], template[p]);
  });

  Object.keys(template).forEach(p => {
    if (p !== 'template') {<commit_msg>fix: prevent deep recursion by checking for self referencing {{main}} and {{module}} entries<commit_after>/* jslint node: true, esnext: true */

function addKeyword(pkg, regex, keyword) {
  if (pkg.name.match(regex)) {
    if (!pkg.keywords.find(k => k === keyword)) {
      pkg.keywords.push(keyword);
    }
  }
}

export default function (target, template, context, options = {}) {
  target = JSON.parse(target);
  template = JSON.parse(template);

  if (target.module && !target.module.match(/\{\{module\}\}/)) {
    context.properties.module = target.module;
  }

  context.properties.main = target.main && !target.main.match(/\{\{main\}\}/) ? target.main : 'index.js';

  const deepPropeties = ['scripts', 'devDependencies', 'engines'];

  let extraBuild, buildOutput;

  if (target.scripts && target.scripts.build) {
    let m = target.scripts.build.match(/--output=([^\s]+)/);
    if (m) {
      buildOutput = m[1];
    }
    m = target.scripts.build.match(/\&\&\s*(.+)/);
    if (m) {
      extraBuild = m[1];
    }
  }

  deepPropeties.forEach(p => {
    if (target[p] === undefined) {
      target[p] = {};
    }
    Object.assign(target[p], template[p]);
  });

  Object.keys(template).forEach(p => {
    if (p !== 'template') {
{'fraction_non_alphanumeric': 0.19903339191564148, 'fraction_numerical': 0.0017574692442882249, 'mean_word_length': 3.0806451612903225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '454458', 'n_tokens_mistral': 787, 'n_tokens_neox': 759, 'n_words': 153}