diff --git a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js index 90dfbb26d..2697d27ee 100644 --- a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js +++ b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js @@ -126,11 +126,14 @@ export function dynamicImportToGlob(node, sourceString) { return glob; } -export const normalizePath = (p) => - p - // remove any ./ inside the path - .replace(/\/\.\//g, '/') - // remove dir/ + ../ pairs - .replace(/([^/.][^/]*\/)(([^/.][^/]*\/)(([^/.][^/]*\/)(\.\.\/))*?(\.\.\/))*?(\.\.\/)/g, '') - // remove unnecessary leading ./ - .replace(/^(\.\/)+(?=\.\.\/)/g, ''); +export function normalizePath(p) { + return ( + p + // remove any ./ inside the path + .replace(/\/\.\//g, '/') + // remove dir/ + ../ pairs + .replace(/([^/.][^/]*\/)(([^/.][^/]*\/)(([^/.][^/]*\/)(\.\.\/))*?(\.\.\/))*?(\.\.\/)/g, '') + // remove unnecessary leading ./ + .replace(/^(\.\/)+(?=\.\.\/)/g, '') + ); +} diff --git a/packages/dynamic-import-vars/src/index.js b/packages/dynamic-import-vars/src/index.js index daad3e8d9..d19cc4f14 100644 --- a/packages/dynamic-import-vars/src/index.js +++ b/packages/dynamic-import-vars/src/index.js @@ -13,7 +13,10 @@ import { normalizePath } from './dynamic-import-to-glob'; -const normalizePathString = normalizePath.toString().substring(10); +const normalizePathString = normalizePath + .toString() + .slice(44, -7) + .replace(/\n {2}/g, '\n'); function dynamicImportVariables({ include, exclude, warnOnError, errorWhenNoFilesFound } = {}) { const filter = createFilter(include, exclude);