Skip to content

Commit

Permalink
Node has not implemented toString() revision
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Oct 18, 2024
1 parent 943df50 commit e2736c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/dynamic-import-vars/src/dynamic-import-to-glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
);
}
5 changes: 4 additions & 1 deletion packages/dynamic-import-vars/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e2736c7

Please sign in to comment.