Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/node_modules/laravel-mix/src/ |
let concat = require('concat');
let babel = require('@babel/core');
let glob = require('glob');
let Log = require('./Log');
class FileCollection {
/**
* Create a new FileCollection instance.
*
* @param {Array|string} files
*/
constructor(files = []) {
this.files = [].concat(files);
}
/**
* Fetch the underlying files.
*/
get() {
return this.files;
}
/**
* Merge all files in the collection into one.
*
* @param {object} output
* @param {object} wantsBabel
*/
merge(output, wantsBabel = false) {
return concat(this.files, output.makeDirectories().path()).then(
contents => {
if (this.shouldCompileWithBabel(wantsBabel, output)) {
output.write(this.babelify(contents));
}
return new File(output.makeDirectories().path());
}
);
}
/**
* Determine if we should add a Babel pass to the concatenated file.
*
* @param {Boolean} wantsBabel
* @param {Object} output
*/
shouldCompileWithBabel(wantsBabel, output) {
return wantsBabel && output.extension() === '.js';
}
/**
* Apply Babel to the given contents.
*
* @param {string} contents
*/
babelify(contents) {
let babelConfig = Config.babel();
delete babelConfig.cacheDirectory;
return babel.transform(contents, babelConfig).code;
}
/**
* Copy the src files to the given destination.
*
* @param {string} destination
* @param {string|array|null} src
*/
copyTo(destination, src = this.files) {
this.assets = this.assets || [];
this.destination = destination;
if (Array.isArray(src)) {
src.forEach(file => this.copyTo(destination, new File(file)));
return;
}
if (src.isDirectory()) {
return src.copyTo(destination.path());
}
if (src.contains('*')) {
let files = glob.sync(src.path(), { nodir: true });
if (!files.length) {
Log.feedback(
`Notice: The ${src.path()} search produced no matches.`
);
}
return this.copyTo(destination, files);
}
if (destination.isDirectory()) {
destination = destination.append(src.name());
}
src.copyTo(destination.path());
this.assets = this.assets.concat(destination);
return destination.path();
}
}
module.exports = FileCollection;