HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/releases/20210303111656Z/node_modules/gulp-uglyfly/index.js
'use strict';
var parallelize = require('parallel-transform'),
	cpus = require('os').cpus().length,
	buffer = require('vinyl-buffer'),
	uglyfly = require('uglyfly-js'),
	deepExtend = require('deep-extend'),
	PluginError = require('gulp-util/lib/PluginError'),
	pluginName = 'gulp-uglyfly';


function adjustOptions(opts, file) {
	var preserveComments = opts && opts.preserveComments,
		commentsOptionOverride,
		defaultOptions,
		options;

	if (preserveComments === 'all') {
		commentsOptionOverride = true;
	} else if (preserveComments === 'some') {
		commentsOptionOverride = /^!|@preserve|@license|@cc_on/i;
	} else if (typeof preserveComments === 'function') {
		commentsOptionOverride = preserveComments;
	}

	defaultOptions = {
		sourceMapURL: false
	};

	if (file && file.sourceMap) {
		if (file.sourceMap.mappings !== '') {
			defaultOptions.inSourceMap = file.sourceMap;
		}
		if (file.relative) {
			defaultOptions.outSourceMap = String(file.relative);
		}
	}

	options = opts ? deepExtend(defaultOptions, opts) : defaultOptions;

	delete options.parallelism;
	delete options.preserveComments;

	if (commentsOptionOverride) {
		options.output = options.output || {};
		options.output.comments = commentsOptionOverride;
	}

	return options;
}

function createError(file, err) {
	var filePath,
		msg;
	filePath = file.path ? String(file.path) : '';
	if(filePath.length === 0) {
		filePath = 'ANONYMOUS FILE';
	}
	if (typeof err === 'string') {
		return new PluginError(pluginName, filePath + ': ' + err, {
			fileName: filePath,
			showStack: false
		});
	}

	msg = err.message || err.msg || /* istanbul ignore next */ 'unspecified error';

	return new PluginError(pluginName, filePath + ': ' + msg, {
		fileName: filePath,
		lineNumber: err.line,
		stack: err.stack,
		showStack: false
	});
}

function minify(opts) {
	var parallelism = cpus;
	opts = deepExtend({}, opts || {});
	if (opts.parallelism && (typeof opts.parallelism === 'number')) {
		parallelism = opts.parallelism;
	}
	return buffer().pipe(parallelize(parallelism, function (file, callback) {
		var options,
			inSourceMap,
			dontAddSources;

		if (file.isNull()) {
			return callback(null, file);
		}

		dontAddSources = (opts.sourceMapIncludeSources === false);

		if(typeof opts.getCustomFileOptions === 'function') {
			opts = opts.getCustomFileOptions(file, opts) || {};
			delete opts.getCustomFileOptions;
		}

		options = adjustOptions(opts, file);
		inSourceMap = options.inSourceMap;
		if (inSourceMap) {
			options.sourceMapIncludeSources = false; //these would be overwritten anyway
		}

		try {
			uglyfly.minify(file, options, function (err, results) {
				var outSourceMap;

				if (err) {
					return callback(createError(file, err));
				}

				file.contents = new Buffer(results.code);

				if ((typeof results.map === 'string') || (results.map instanceof String)) {
					outSourceMap = JSON.parse(results.map);
					if (outSourceMap) {
						file.sourceMap = outSourceMap;
						if (inSourceMap && !dontAddSources) {
							file.sourceMap.sourcesContent = inSourceMap.sourcesContent;
							file.sourceMap.sources = inSourceMap.sources;

						}
					}
				}

				return callback(null, file);

			});
		} catch (e) {
			return callback(createError(file, e));
		}

	}));
}

module.exports = minify;