Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ test('escapes special chars in globs without mangling user supplied glob suffix'
.toEqual(expectedNames)
})

test('escape literal parenthesis in glob pattern', async () => {
// https://github.com/vitejs/vite/issues/22166
// Backslash-escaped parens must match literal "(" / ")" in both dev and build.
await expect
.poll(async () =>
JSON.parse(await page.textContent('.escape-literal-parenthesis')),
)
.toStrictEqual(['/escape/(parenthesis)/mod/index.js'])
})

test('subpath imports', async () => {
await expect
.poll(async () => await page.textContent('.subpath-imports'))
Expand Down
13 changes: 13 additions & 0 deletions playground/glob-import/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ <h2>Escape relative glob</h2>
<pre class="escape-relative"></pre>
<h2>Escape alias glob</h2>
<pre class="escape-alias"></pre>
<h2>Escape literal parenthesis</h2>
<pre class="escape-literal-parenthesis"></pre>
<h2>Subpath imports</h2>
<pre class="subpath-imports"></pre>
<h2>Subpath imports (sub dir)</h2>
Expand Down Expand Up @@ -150,6 +152,17 @@ <h2>Base</h2>
document.querySelector('.escape-alias').textContent = alias.sort().join('\n')
</script>

<script type="module">
// https://github.com/vitejs/vite/issues/22166
// Backslash-escaped glob metachars must match their literal counterparts
// consistently in dev and build.
const literalParen = import.meta.glob('/escape/\\(parenthesis\\)/mod/*.js', {
eager: true,
})
document.querySelector('.escape-literal-parenthesis').textContent =
JSON.stringify(Object.keys(literalParen).sort())
</script>

<script type="module">
const subpathImports = import.meta.glob('#imports/*', { eager: true })
document.querySelector('.subpath-imports').textContent = Object.values(
Expand Down
Loading