-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Vitest with content collections (#7233)
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix `getViteConfig` and Vitest setup with content collections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type fsMod from 'node:fs'; | ||
import type { Plugin, ViteDevServer } from 'vite'; | ||
import type { AstroSettings } from '../@types/astro'; | ||
import { attachContentServerListeners } from '../content/server-listeners.js'; | ||
import type { LogOptions } from '../core/logger/core.js'; | ||
|
||
/** | ||
* Listen for Astro content directory changes and generate types. | ||
* | ||
* This is a separate plugin for `getViteConfig` as the `attachContentServerListeners` API | ||
* needs to be called at different times in `astro dev` and `getViteConfig`. For `astro dev`, | ||
* it needs to be called after the Astro server is started (packages/astro/src/core/dev/dev.ts). | ||
* For `getViteConfig`, it needs to be called after the Vite server is started. | ||
*/ | ||
export function astroContentListenPlugin({ | ||
settings, | ||
logging, | ||
fs, | ||
}: { | ||
settings: AstroSettings; | ||
logging: LogOptions; | ||
fs: typeof fsMod; | ||
}): Plugin { | ||
let server: ViteDevServer; | ||
|
||
return { | ||
name: 'astro:content-listen', | ||
apply: 'serve', | ||
configureServer(_server) { | ||
server = _server; | ||
}, | ||
async buildStart() { | ||
await attachContentServerListeners({ | ||
fs: fs, | ||
settings, | ||
logging, | ||
viteServer: server, | ||
}); | ||
}, | ||
}; | ||
} |