<commit_before>const loaderUtils = require('loader-utils');
const path = require('path');
const deepMerge = require('./lib/deep-merge');

function _removeModuleSyntax (moduleSource) {
  return moduleSource
        .replace(/^ ?module.exports ?= ?/i, '')
        .replace(/\;$/g, '');
};

module.exports = function(source) {
  const callback = this.async();
  const options = loaderUtils.getOptions(this);
  const overridePath = path.resolve(this.context, options.override);

  this.cacheable && this.cacheable();

  this.loadModule(overridePath,
    function(err, overrideSource, sourceMap, module) {
      if (err) { return callback(err); }

      const baseObj = JSON.parse(_removeModuleSyntax(source));
      const overrideObj = JSON.parse(_removeModuleSyntax(overrideSource));
      let mergedModule;

      if (!!options.baseNamespace && !!options.overrideNamespace) {
        mergedModule = {
          [options.baseNamespace]: deepMerge(baseObj[options.baseNamespace],
          overrideObj[options.overrideNamespace])
        };
      } else {
        mergedModule = deepMerge(baseObj, overrideObj);
      }

      callback(null, JSON.stringify(mergedModule));
    });
};<commit_msg>Handle null overrides and same module overrides<commit_after>const loaderUtils = require('loader-utils');
const path = require('path');
const deepMerge = require('./lib/deep-merge');

function _removeModuleSyntax (moduleSource) {
  return moduleSource
        .replace(/^ ?module.exports ?= ?/i, '')
        .replace(/\;$/g, '');
};

module.exports = function(source) {
  const callback = this.async();
  const options = loaderUtils.getOptions(this);

  this.cacheable && this.cacheable();

  if (!!options.override && options.override !== this.resourcePath) {
    this.loadModule(path.resolve(this.context, options.override),
      function(err, overrideSource, sourceMap, module) {
        if (err) { return callback(err); }

        const baseObj = JSON.parse(_removeModuleSyntax(source));
        const overrideObj = JSON.parse(_removeModuleSyntax(overrideSource));
        let mergedModule;

        if (!!options.baseNamespace && !!options.overrideNamespace) {
          mergedModule = {
            [options.baseNamespace]: deepMerge(baseObj[options.baseNamespace],
            overrideObj[options.overrideNamespace])
          };
        } else {
          mergedModule = deepMerge(baseObj, overrideObj);
        }

        callback(null, JSON.stringify(mergedModule));
      });
  } else {
    callback(null, JSON.stringify(source));
  }
};
{'fraction_non_alphanumeric': 0.13897637795275591, 'fraction_numerical': 0.0, 'mean_word_length': 3.4423076923076925, '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': '1473453', 'n_tokens_mistral': 697, 'n_tokens_neox': 682, 'n_words': 134}