From e2736c7f3d8349e326763272380dba56829fda4a Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Fri, 18 Oct 2024 17:11:16 -0400 Subject: [PATCH] Node has not implemented toString() revision --- .../src/dynamic-import-to-glob.js | 19 +++++++++++-------- packages/dynamic-import-vars/src/index.js | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) 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);