Skip to content

Commit

Permalink
Handle nesting better
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Oct 18, 2024
1 parent 9b6d4bc commit c5aff19
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/src/dynamic-import-to-glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ export const normalizePath = (p) =>
// remove any ./ inside the path
.replace(/\/\.\//g, '/')
// remove dir/ + ../ pairs
.replace(/([^/.][^/]*\/)(([^/.][^/]*\/)(\.\.\/))?(\.\.\/)/g, '')
.replace(/([^/.][^/]*\/)(([^/.][^/]*\/)(([^/.][^/]*\/)(\.\.\/))*?(\.\.\/))*?(\.\.\/)/g, '')
// remove unnecessary leading ./
.replace(/^(\.\/)+(?=\.\.\/)/g, '');
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down Expand Up @@ -43,15 +43,15 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
case './module-dir-a/module-a-1.js': return import('./module-a-1-fiunS6HF.js');␊
case './module-dir-a/module-a-2.js': return import('./module-a-2-qepdcyXv.js');␊
case './module-dir-b/module-b-1.js': return import('./module-b-1-3qdzaV4G.js');␊
case './module-dir-b/module-b-2.js': return import('./module-b-2-_8gpxG1i.js');␊
case './sub-dir/fixture-upwards-path.js': return import('./fixture-upwards-path-qW3pa8f7.js');␊
case './sub-dir/fixture-upwards-path.js': return import('./fixture-upwards-path-gQ8U7UtJ.js');␊
default: return new Promise(function(resolve, reject) {␊
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(␊
reject.bind(null, new Error("Unknown variable dynamic import: " + normalPath))␊
Expand All @@ -76,7 +76,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down Expand Up @@ -106,7 +106,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down Expand Up @@ -138,7 +138,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down Expand Up @@ -168,15 +168,15 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
case './module-dir-a/module-a-1.js': return import('./module-a-1-fiunS6HF.js');␊
case './module-dir-a/module-a-2.js': return import('./module-a-2-qepdcyXv.js');␊
case './module-dir-b/module-b-1.js': return import('./module-b-1-3qdzaV4G.js');␊
case './module-dir-b/module-b-2.js': return import('./module-b-2-_8gpxG1i.js');␊
case './sub-dir/fixture-upwards-path.js': return import('./fixture-upwards-path-qW3pa8f7.js');␊
case './sub-dir/fixture-upwards-path.js': return import('./fixture-upwards-path-gQ8U7UtJ.js');␊
default: return new Promise(function(resolve, reject) {␊
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(␊
reject.bind(null, new Error("Unknown variable dynamic import: " + normalPath))␊
Expand All @@ -190,7 +190,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand All @@ -209,7 +209,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down Expand Up @@ -277,7 +277,7 @@ Generated by [AVA](https://avajs.dev).
// remove any ./ inside the path␊
.replace(/\\/\\.\\//g, '/')␊
// remove dir/ + ../ pairs␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))?(\\.\\.\\/)/g, '')␊
.replace(/([^/.][^/]*\\/)(([^/.][^/]*\\/)(([^/.][^/]*\\/)(\\.\\.\\/))*?(\\.\\.\\/))*?(\\.\\.\\/)/g, '')␊
// remove unnecessary leading ./␊
.replace(/^(\\.\\/)+(?=\\.\\.\\/)/g, '');␊
switch (normalPath) {␊
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ test('escapes []', (t) => {
'./../فو/bar/../../foo.js',
'../foo/../foo.js',
'./../foo/../bar/.././../foo.js',
'./../foo/bar/.././../foo.js'
'./../foo/bar/.././../foo.js',
'./foo/bar/baz/../qux/../../../../foo.js'
].forEach((p) => {
test(`normalizePath - ${p}`, (t) => {
const normalPath = normalizePath(p);
Expand Down

0 comments on commit c5aff19

Please sign in to comment.