<commit_before>'use strict';

var util      = require('util');
var path      = require('path');
var uglify    = require('uglify-js');
var minimatch = require('minimatch');
var assign    = require('object-assign');

module.exports = function metalsmithUglify(options) {

  // Set up the options
  options = assign({
    filter: '**/*.js',
    preserveComments: false,
    removeOriginal: false,
    sourceMap: false,
    output: {}
  }, options);

  options.fromString = true;

  // https://github.com/terinjokes/gulp-uglify/blob/master/index.js
  if (options.preserveComments === 'all' || options.preserveComments === true) {
    options.output.comments = true;
  } else if (options.preserveComments === 'some') {
    // preserve comments with directives or that start with a bang (!)
    options.output.comments = /^!|@preserve|@license|@cc_on/i;
  } else if (typeof options.preserveComments === 'function') {
    options.output.comments = options.preserveComments;
  }

  return function uglify(files, metalsmith, done) {
    // Get all of the relative filepaths
    Object.keys(files)
      // Filter through so we only get the ones that match the filter
      .filter(filter(options.filter))
      // Uglify the given files and add it to the files object
      .map(function (filepath) {
        var minFilePath = getMinPath(filepath);

        var mangleOptions = assign({}, options);
        if (options.sourceMap) {
          mangleOptions.outSourceMap = minFilePath + '.map';
        }

        var mangled = minify(files[filepath], filepath, mangleOptions);

        // If there was an uglification error, return the error to done
        if (mangled instanceof Error) { return done(mangled); }

        if (mangled.map) {
          var sourceMap = JSON.parse(mangled.map);
          sourceMap.sources[0] = filepath;
          sourceMap.sourcesContent = [String(files[filepath].contents)];
          files[mangleOptions.outSourceMap] = {
            contents: new Buffer(JSON.stringify(sourceMap))
          };
        }


        // Create the new file
        files[minFilePath] = {
          contents: mangled.code<commit_msg>fixes directory nested map paths<commit_after>'use strict';

var util      = require('util');
var path      = require('path');
var uglify    = require('uglify-js');
var minimatch = require('minimatch');
var assign    = require('object-assign');
var url       = require('url');

module.exports = function metalsmithUglify(options) {

  // Set up the options
  options = assign({
    filter: '**/*.js',
    preserveComments: false,
    removeOriginal: false,
    sourceMap: false,
    output: {}
  }, options);

  options.fromString = true;

  // https://github.com/terinjokes/gulp-uglify/blob/master/index.js
  if (options.preserveComments === 'all' || options.preserveComments === true) {
    options.output.comments = true;
  } else if (options.preserveComments === 'some') {
    // preserve comments with directives or that start with a bang (!)
    options.output.comments = /^!|@preserve|@license|@cc_on/i;
  } else if (typeof options.preserveComments === 'function') {
    options.output.comments = options.preserveComments;
  }

  return function uglify(files, metalsmith, done) {
    // Get all of the relative filepaths
    Object.keys(files)
      // Filter through so we only get the ones that match the filter
      .filter(filter(options.filter))
      // Uglify the given files and add it to the files object
      .map(function (filepath) {
        var minFilePath = getMinPath(filepath);

        var mangleOptions = assign({}, options);

        if (options.sourceMap) {
          mangleOptions.outSourceMap = path.basename(minFilePath + '.map');
        }

        var mangled = minify(files[filepath], filepath, mangleOptions);

        // If there was an uglification error, return the error to done
        if (mangled instanceof Error) { return done(mangled); }

        if (mangled.map) {
          var sourceMap = JSON.parse(mangled.map);
          sourceMap.sources[0] = filepath;
          sourceMap.sourcesContent = [String(files[filepath].contents)];
          files[minFilePath + '.map'] = {
            contents: new Buffer(JSON.stringify(sourceMap))
          };
        }


        // Create the new file
        files[minFilePath] = {
          contents: mangled.code
{'fraction_non_alphanumeric': 0.12404888171547153, 'fraction_numerical': 0.0004611482591653217, 'mean_word_length': 2.795275590551181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2939151', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1219, 'n_words': 329}