Make glob optional in concats.js

Added:
- Condition to process includes with glob if it's available.

Changed:
- Utility 'glob.js' to not throw an error if a glob function is unavailable.
This commit is contained in:
Chauncey McAskill
2022-02-08 15:18:18 -05:00
parent c9056b27d8
commit 5e07473396
2 changed files with 29 additions and 11 deletions

View File

@@ -56,21 +56,25 @@ export const productionConcatFilesArgs = [
* @todo Add support for minification. * @todo Add support for minification.
* *
* @async * @async
* @param {object} [globOptions=null] - Customize the glob options. * @param {object|boolean} [globOptions=null] - Customize the glob options.
* If `null`, default production options are used. * If `null`, default production options are used.
* If `false`, the glob function will be ignored.
* @param {object} [concatOptions=null] - Customize the concatenation options. * @param {object} [concatOptions=null] - Customize the concatenation options.
* If `null`, default production options are used. * If `null`, default production options are used.
* @return {Promise} * @return {Promise}
*/ */
export default async function concatFiles(globOptions = null, concatOptions = null) { export default async function concatFiles(globOptions = null, concatOptions = null) {
if (glob) {
if (globOptions == null) { if (globOptions == null) {
globOptions = productionGlobOptions; globOptions = productionGlobOptions;
} else if ( } else if (
globOptions !== false &&
globOptions !== developmentGlobOptions && globOptions !== developmentGlobOptions &&
globOptions !== productionGlobOptions globOptions !== productionGlobOptions
) { ) {
globOptions = Object.assign({}, defaultGlobOptions, globOptions); globOptions = Object.assign({}, defaultGlobOptions, globOptions);
} }
}
if (concatOptions == null) { if (concatOptions == null) {
concatOptions = productionConcatOptions; concatOptions = productionConcatOptions;
@@ -97,7 +101,13 @@ export default async function concatFiles(globOptions = null, concatOptions = nu
includes = includes.map((path) => template(path)); includes = includes.map((path) => template(path));
outfile = template(outfile); outfile = template(outfile);
let files = await glob(includes, globOptions); let files;
if (glob && globOptions) {
files = await glob(includes, globOptions);
} else {
files = includes;
}
if (concatOptions.removeDuplicates) { if (concatOptions.removeDuplicates) {
files = files.map((path) => normalize(path)); files = files.map((path) => normalize(path));

View File

@@ -22,7 +22,15 @@ const candidates = [
'glob', 'glob',
]; ];
export default await importGlob(); let glob;
try {
glob = await importGlob();
} catch (err) {
// do nothing
}
export default glob;
/** /**
* Imports the first available glob function. * Imports the first available glob function.