2022-10-24 10:08:36 +01:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const NODE_MODULES = 'node_modules';
|
|
|
|
|
/**
|
|
|
|
|
* @param {string[]} pluginsPath – an array of paths to the plugins from the user's directory
|
|
|
|
|
* @returns {RegExp} a regex that will exclude _all_ node_modules except for the plugins in the pluginsPath array.
|
|
|
|
|
*/
|
|
|
|
|
const createPluginsExcludePath = (pluginsPath = []) => {
|
|
|
|
|
/**
|
|
|
|
|
* If there aren't any plugins in the node_modules array, just return the node_modules regex
|
|
|
|
|
* without complicating it.
|
|
|
|
|
*/
|
2023-08-22 09:37:43 +01:00
|
|
|
|
if (pluginsPath.length === 0) {
|
2022-10-24 10:08:36 +01:00
|
|
|
|
return /node_modules/;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 09:37:43 +01:00
|
|
|
|
return new RegExp(`${NODE_MODULES}/(?!(${pluginsPath.join('|')}))`);
|
2022-10-24 10:08:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-08-22 09:37:43 +01:00
|
|
|
|
module.exports = { createPluginsExcludePath };
|