From 95a8255718dfa111a7a7bf8a0ea26634ea1c7391 Mon Sep 17 00:00:00 2001 From: himanshuub2 <2121997him@gmail.com> Date: Sun, 7 Apr 2024 23:42:06 +0530 Subject: [PATCH] adds includePattern as options --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2934b6c..1140dee 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import transformSvg from './transformSvg'; import fileExistsWithCaseSync from './fileExistsWithCaseSync'; let ignoreRegex; +let includeRegex; export default declare(({ assertVersion, @@ -48,9 +49,18 @@ export default declare(({ if (typeof importPath !== 'string') { throw new TypeError('`applyPlugin` `importPath` must be a string'); } - const { ignorePattern, caseSensitive, filename: providedFilename } = state.opts; + const { + ignorePattern, includePattern, caseSensitive, filename: providedFilename, + } = state.opts; const { file, filename } = state; let newPath; + if (includePattern) { + includeRegex = includeRegex || new RegExp(includePattern); + + if (!includeRegex.test(importPath)) { + return undefined; + } + } if (ignorePattern) { // Only set the ignoreRegex once: ignoreRegex = ignoreRegex || new RegExp(ignorePattern);