<commit_before>/*global module, require, Buffer */
module.exports = function (grunt) {
	'use strict';

	grunt.registerMultiTask('big-assets', 'List biggest project dependencies', function () {

		var _ = require('underscore'),
			madge = require('madge'),
			print = require('node-print'),
			ProgressBar = require('progress'),
			uglify = require('uglify-js'),
			fs = require('fs'),
			dependencyTree,
			options,
			table = [],
			tableHTML = '',
			tableTemplate,
			walkDepTree;

		function getUglifiedSize(file) {
			return (Buffer.byteLength(uglify.minify(file).code, 'utf8') / 1024).toFixed(2);
		};

		options = this.options({
			base: '', // base folder for project Javascript, defined without trailing slash
			reportPath: undefined,
			fieldOrder: ['name', 'requiredByCount', 'requiredBy', 'sizeKB', 'sizeKBUglified'],
			fieldNames: ['Filename', '# Dependent Modules', 'Dependent Modules', 'Filesize (KB)', 'Uglified filesize (KB)']
		});

		dependencyTree = madge(options.base, {
			format: 'amd'
		});

		walkDepTree = _.memoize(function (paths, alreadySeen) {
			if (!alreadySeen) {
				alreadySeen = [];
			}
			// Given a set of AMD module paths, walk the dependency for each path until the ultimate
			// dependency is reached, returning the list of top-level dependencies for each path.
			var nextDeps = _.map(paths, function (path) {
				var depends;

				depends = dependencyTree.depends(path);

				if (!depends.length || _.contains(alreadySeen, path)) {
					// There are no more dependencies to check, or we've already checked this one
					return path;
				} else {
					alreadySeen.push(path);
					return walkDepTree(depends, alreadySeen);
				}
			});

			return _.uniq(_.flatten(nextDeps));
		});

		// Loop through file groups
		this.files.forEach(function (file) {
			var bar, filesInGroup;

			// Exclude nonexistent files
			filesInGroup = file.src.filter(function (filepath) {
				if (!grunt.file.exists(filepath)) {
					grunt.log.warn('Source file "' + filepath + '" not found.');
					return false;<commit_msg>Fix logic error in handling of circular dependencies<commit_after>/*global module, require, Buffer */
module.exports = function (grunt) {
	'use strict';

	grunt.registerMultiTask('big-assets', 'List biggest project dependencies', function () {

		var _ = require('underscore'),
			madge = require('madge'),
			print = require('node-print'),
			ProgressBar = require('progress'),
			uglify = require('uglify-js'),
			fs = require('fs');

		var dependencyTree,
			options,
			table = [],
			tableHTML = '',
			tableTemplate,
			walkDepTree;

		function getUglifiedSize(file) {
			return (Buffer.byteLength(uglify.minify(file).code, 'utf8') / 1024).toFixed(2);
		}

		options = this.options({
			base: '', // base folder for project Javascript, defined without trailing slash
			reportPath: '',
			fieldOrder: ['name', 'requiredByCount', 'requiredBy', 'sizeKB', 'sizeKBUglified'],
			fieldNames: ['Filename', '# Dependent Modules', 'Dependent Modules', 'Filesize (KB)', 'Uglified filesize (KB)']
		});

		dependencyTree = madge(options.base, {
			format: 'amd'
		});

		walkDepTree = _.memoize(function (paths, alreadySeen) {
			if (!alreadySeen) {
				alreadySeen = [];
			}
			// Given a set of AMD module paths, walk the dependencies for each path until the ultimate
			// dependency is reached, returning the list of top-level dependencies for each path.
			var nextDeps = _.map(paths, function (path) {
				var depends;

				depends = dependencyTree.depends(path);

				if (!depends.length) {
					// We've hit the end of the dependency tree
					return path;
				} else if (_.contains(alreadySeen, path)) {
					// We've hit a circular dependency
					return [];
				} else {
					alreadySeen.push(path);
					return walkDepTree(depends, alreadySeen);
				}
			});

			return _.uniq(_.flatten(nextDeps));
		});

		// Loop through file groups
		this.files.forEach(function (file) {
			var bar, filesInGroup;

			// Exclude nonexistent files
			filesInGroup = file.src.filter(function (filepath) {
				if (!grunt.file.exists(filepath)) {
					grunt.log.warn('Source file "' + filepath + '" not found.');
					return false;
{'fraction_non_alphanumeric': 0.13950143815915628, 'fraction_numerical': 0.0028763183125599234, 'mean_word_length': 3.560655737704918, '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': '7278219', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1258, 'n_words': 345}