From d90581ae5e8c7567b65607ba4965ba8b123cd805 Mon Sep 17 00:00:00 2001 From: toshify <4579559+toshify@users.noreply.github.com> Date: Fri, 18 Mar 2022 11:10:07 +0100 Subject: [PATCH 1/2] fix: handle relative path glob raw import, fix #7307 --- .../glob-import/__tests__/glob-import.spec.ts | 12 +++++++++++ packages/playground/glob-import/index.html | 20 +++++++++++++++++++ packages/vite/src/node/importGlob.ts | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index fff8d9fe202ebc..701ad5791ded23 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -66,6 +66,11 @@ const rawResult = { } } +// issue #7307 +const relativeRawResult = { + '../dynamic-import/nested/shared.js': 'export const n = 1\n' +} + test('should work', async () => { expect(await page.textContent('.result')).toBe( JSON.stringify(allResult, null, 2) @@ -81,6 +86,13 @@ test('import glob raw', async () => { ) }) +// issue #7307 +test('import relative glob raw', async () => { + expect(await page.textContent('.relative-glob-raw')).toBe( + JSON.stringify(relativeRawResult, null, 2) + ) +}) + if (!isBuild) { test('hmr for adding/removing files', async () => { addFile('dir/a.js', '') diff --git a/packages/playground/glob-import/index.html b/packages/playground/glob-import/index.html index 52d41b817a169c..3790e5928ee5eb 100644 --- a/packages/playground/glob-import/index.html +++ b/packages/playground/glob-import/index.html @@ -1,6 +1,7 @@

 

 

+
+ + diff --git a/packages/vite/src/node/importGlob.ts b/packages/vite/src/node/importGlob.ts index 8ed3ba66d09744..043646a3a5787e 100644 --- a/packages/vite/src/node/importGlob.ts +++ b/packages/vite/src/node/importGlob.ts @@ -146,8 +146,9 @@ export async function transformImportGlob( ) ) } + // issue #7307 entries += ` ${JSON.stringify(file)}: ${JSON.stringify( - await fsp.readFile(path.join(base, file), 'utf-8') + await fsp.readFile(path.join(base, files[i]), 'utf-8') )},` } else { const importeeUrl = isCSSRequest(importee) ? `${importee}?used` : importee From cb9fd210f8be7dc7241663492dc8bd8820cf5944 Mon Sep 17 00:00:00 2001 From: toshify <4579559+toshify@users.noreply.github.com> Date: Sat, 19 Mar 2022 10:54:53 +0100 Subject: [PATCH 2/2] fix: handle relative path glob raw import, fix #7307 Contain test within `glob-import`-folder Remove comments referencing issue number --- .../playground/glob-import/__tests__/glob-import.spec.ts | 6 +++--- packages/playground/glob-import/index.html | 7 +++---- packages/vite/src/node/importGlob.ts | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index 701ad5791ded23..ebdf6c0ab29193 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -66,9 +66,10 @@ const rawResult = { } } -// issue #7307 const relativeRawResult = { - '../dynamic-import/nested/shared.js': 'export const n = 1\n' + '../glob-import/dir/baz.json': { + msg: 'baz' + } } test('should work', async () => { @@ -86,7 +87,6 @@ test('import glob raw', async () => { ) }) -// issue #7307 test('import relative glob raw', async () => { expect(await page.textContent('.relative-glob-raw')).toBe( JSON.stringify(relativeRawResult, null, 2) diff --git a/packages/playground/glob-import/index.html b/packages/playground/glob-import/index.html index 3790e5928ee5eb..64f456aeb4d6a2 100644 --- a/packages/playground/glob-import/index.html +++ b/packages/playground/glob-import/index.html @@ -1,7 +1,7 @@

 

 

-
+