Skip to content

Commit

Permalink
fix: handle relative path glob raw import, fix vitejs#7307
Browse files Browse the repository at this point in the history
Contain test within `glob-import`-folder
Remove comments referencing issue number
  • Loading branch information
toshify committed Mar 19, 2022
1 parent d90581a commit cb9fd21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/playground/glob-import/__tests__/glob-import.spec.ts
Expand Up @@ -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 () => {
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions packages/playground/glob-import/index.html
@@ -1,7 +1,7 @@
<pre class="result"></pre>
<pre class="result-node_modules"></pre>
<pre class="globraw"></pre>
<pre class="relative-glob-raw"><!--issue #7307--></pre>
<pre class="relative-glob-raw"></pre>

<script type="module" src="./dir/index.js"></script>
<script type="module">
Expand Down Expand Up @@ -55,16 +55,15 @@
</script>

<script type="module">
// issue #7307
const relativeRawModules = import.meta.globEager(
'../dynamic-import/nested/shar*.js',
'../glob-import/dir/*.json',
{
as: 'raw'
}
)
const relativeGlobRaw = {}
Object.keys(relativeRawModules).forEach((key) => {
relativeGlobRaw[key] = relativeRawModules[key]
relativeGlobRaw[key] = JSON.parse(relativeRawModules[key])
})
document.querySelector('.relative-glob-raw').textContent = JSON.stringify(
relativeGlobRaw,
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/importGlob.ts
Expand Up @@ -146,7 +146,6 @@ export async function transformImportGlob(
)
)
}
// issue #7307
entries += ` ${JSON.stringify(file)}: ${JSON.stringify(
await fsp.readFile(path.join(base, files[i]), 'utf-8')
)},`
Expand Down

0 comments on commit cb9fd21

Please sign in to comment.