mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix(glob): trigger HMR for glob in a package (#14117)
This commit is contained in:
parent
72d5d4d833
commit
86cbf6977d
@ -58,8 +58,10 @@ export function getAffectedGlobModules(
|
||||
(!affirmed.length || affirmed.some((glob) => isMatch(file, glob))) &&
|
||||
(!negated.length || negated.every((glob) => isMatch(file, glob))),
|
||||
)
|
||||
)
|
||||
modules.push(...(server.moduleGraph.getModulesByFile(id) || []))
|
||||
) {
|
||||
const mod = server.moduleGraph.getModuleById(id)
|
||||
if (mod) modules.push(mod)
|
||||
}
|
||||
}
|
||||
modules.forEach((i) => {
|
||||
if (i?.file) server.moduleGraph.onFileChange(i.file)
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
page,
|
||||
removeFile,
|
||||
untilBrowserLogAfter,
|
||||
untilUpdated,
|
||||
viteTestUrl,
|
||||
withRetry,
|
||||
} from '~utils'
|
||||
@ -131,6 +132,12 @@ test('unassigned import processes', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('import glob in package', async () => {
|
||||
expect(await page.textContent('.in-package')).toBe(
|
||||
JSON.stringify(['/pkg-pages/foo.js']),
|
||||
)
|
||||
})
|
||||
|
||||
if (!isBuild) {
|
||||
test('hmr for adding/removing files', async () => {
|
||||
const resultElement = page.locator('.result')
|
||||
@ -190,6 +197,22 @@ if (!isBuild) {
|
||||
response = await request.catch(() => ({ status: () => -1 }))
|
||||
expect(response.status()).toBe(-1)
|
||||
})
|
||||
|
||||
test('hmr for adding/removing files in package', async () => {
|
||||
const resultElement = page.locator('.in-package')
|
||||
|
||||
addFile('pkg-pages/bar.js', '// empty')
|
||||
await untilUpdated(
|
||||
() => resultElement.textContent(),
|
||||
JSON.stringify(['/pkg-pages/foo.js', '/pkg-pages/bar.js'].sort()),
|
||||
)
|
||||
|
||||
removeFile('pkg-pages/bar.js')
|
||||
await untilUpdated(
|
||||
() => resultElement.textContent(),
|
||||
JSON.stringify(['/pkg-pages/foo.js']),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
test('tree-shake eager css', async () => {
|
||||
|
4
playground/glob-import/import-meta-glob-pkg/index.js
Normal file
4
playground/glob-import/import-meta-glob-pkg/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
export const g = import.meta.glob('/pkg-pages/*.js')
|
||||
document.querySelector('.in-package').textContent = JSON.stringify(
|
||||
Object.keys(g).sort(),
|
||||
)
|
5
playground/glob-import/import-meta-glob-pkg/package.json
Normal file
5
playground/glob-import/import-meta-glob-pkg/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@vitejs/test-import-meta-glob-pkg",
|
||||
"type": "module",
|
||||
"main": "./index.js"
|
||||
}
|
@ -23,6 +23,8 @@
|
||||
<pre class="escape-alias"></pre>
|
||||
<h2>Sub imports</h2>
|
||||
<pre class="sub-imports"></pre>
|
||||
<h2>In package</h2>
|
||||
<pre class="in-package"></pre>
|
||||
|
||||
<script type="module" src="./dir/index.js"></script>
|
||||
<script type="module">
|
||||
@ -151,6 +153,10 @@
|
||||
.join(' ')
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
import '@vitejs/test-import-meta-glob-pkg'
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
console.log('Ran scripts')
|
||||
</script>
|
||||
|
@ -11,5 +11,8 @@
|
||||
"build": "vite build",
|
||||
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vitejs/test-import-meta-glob-pkg": "file:./import-meta-glob-pkg"
|
||||
}
|
||||
}
|
||||
|
1
playground/glob-import/pkg-pages/foo.js
Normal file
1
playground/glob-import/pkg-pages/foo.js
Normal file
@ -0,0 +1 @@
|
||||
// empty
|
@ -670,7 +670,13 @@ importers:
|
||||
|
||||
playground/fs-serve: {}
|
||||
|
||||
playground/glob-import: {}
|
||||
playground/glob-import:
|
||||
dependencies:
|
||||
'@vitejs/test-import-meta-glob-pkg':
|
||||
specifier: file:./import-meta-glob-pkg
|
||||
version: file:playground/glob-import/import-meta-glob-pkg
|
||||
|
||||
playground/glob-import/import-meta-glob-pkg: {}
|
||||
|
||||
playground/hmr: {}
|
||||
|
||||
@ -10801,6 +10807,11 @@ packages:
|
||||
vue: 3.3.4
|
||||
dev: false
|
||||
|
||||
file:playground/glob-import/import-meta-glob-pkg:
|
||||
resolution: {directory: playground/glob-import/import-meta-glob-pkg, type: directory}
|
||||
name: '@vitejs/test-import-meta-glob-pkg'
|
||||
dev: false
|
||||
|
||||
file:playground/import-assertion/import-assertion-dep:
|
||||
resolution: {directory: playground/import-assertion/import-assertion-dep, type: directory}
|
||||
name: '@vitejs/test-import-assertion-dep'
|
||||
|
Loading…
Reference in New Issue
Block a user