Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ export async function transformGlobImport(
}

let importPath = relative(dir, file)
if (importPath[0] !== '.') importPath = `./${importPath}`
if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
importPath = `./${importPath}`
}

let filePath: string
if (options.base) {
Expand Down
1 change: 1 addition & 0 deletions playground/glob-import/.foo/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'dot-folder-test'
4 changes: 4 additions & 0 deletions playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ test('unassigned import processes', async () => {
)
})

test('dot folder issue', async () => {
expect(await page.textContent('.dot-folder-test')).toMatch(/SUCCESS:/)
})

test('import glob in package', async () => {
expect(await page.textContent('.in-package')).toBe(
JSON.stringify(['/pkg-pages/foo.js']),
Expand Down
19 changes: 19 additions & 0 deletions playground/glob-import/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ <h2>In package</h2>
<pre class="in-package"></pre>
<h2>Base</h2>
<pre class="result-base"></pre>
<h2>Dot Folder Issue</h2>
<pre class="dot-folder-test"></pre>

<script type="module" src="./dir/index.js"></script>
<script type="module">
Expand Down Expand Up @@ -187,3 +189,20 @@ <h2>Base</h2>
2,
)
</script>

<script type="module">
// Test case for dot folder issue
try {
console.log('Testing dot folder globs...')
console.log(import.meta.glob('./foo/test.ts'))
console.log(import.meta.glob('./inner/.foo/test.ts'))
console.log(import.meta.glob('./.foo/test.ts'))

const dotFolderResult = import.meta.glob('./.foo/test.ts', { eager: true })
document.querySelector('.dot-folder-test').textContent =
'SUCCESS: ' + JSON.stringify(dotFolderResult, null, 2)
} catch (error) {
document.querySelector('.dot-folder-test').textContent =
'ERROR: ' + error.message
}
</script>
1 change: 1 addition & 0 deletions playground/glob-import/inner/.foo/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'inner-dot-folder-test'
16 changes: 16 additions & 0 deletions playground/glob-import/simple-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="test-result"></div>
<script type="module">
// Simple test case for the issue
const dotFolderGlob = import.meta.glob('./.foo/test.ts', { eager: true })
console.log('Dot folder glob result:', dotFolderGlob)
document.querySelector('.test-result').textContent =
JSON.stringify(dotFolderGlob)
</script>
</body>
</html>