fix: do not apply user plugins when spawning temporary Vite server for content collections

This commit is contained in:
Nate Moore 2023-02-24 16:20:32 -06:00
parent 4d75396362
commit ccaed8f74b
3 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix regression that caused some stateful Vite plugins to assume they were running in `dev` mode during the `build`.

View file

@ -31,6 +31,7 @@ interface CreateViteOptions {
logging: LogOptions; logging: LogOptions;
mode: 'dev' | 'build' | string; mode: 'dev' | 'build' | string;
fs?: typeof nodeFs; fs?: typeof nodeFs;
allowUserPlugins?: boolean;
} }
const ALWAYS_NOEXTERNAL = [ const ALWAYS_NOEXTERNAL = [
@ -48,7 +49,7 @@ const ALWAYS_NOEXTERNAL = [
/** Return a common starting point for all Vite actions */ /** Return a common starting point for all Vite actions */
export async function createVite( export async function createVite(
commandConfig: vite.InlineConfig, commandConfig: vite.InlineConfig,
{ settings, logging, mode, fs = nodeFs }: CreateViteOptions { settings, logging, mode, fs = nodeFs, allowUserPlugins = true }: CreateViteOptions
): Promise<vite.InlineConfig> { ): Promise<vite.InlineConfig> {
const astroPkgsConfig = await crawlFrameworkPkgs({ const astroPkgsConfig = await crawlFrameworkPkgs({
root: fileURLToPath(settings.config.root), root: fileURLToPath(settings.config.root),
@ -170,7 +171,9 @@ export async function createVite(
// 3. integration-provided vite config, via the `config:setup` hook // 3. integration-provided vite config, via the `config:setup` hook
// 4. command vite config, passed as the argument to this function // 4. command vite config, passed as the argument to this function
let result = commonConfig; let result = commonConfig;
result = vite.mergeConfig(result, settings.config.vite || {}); if (allowUserPlugins) {
result = vite.mergeConfig(result, settings.config.vite || {});
}
result = vite.mergeConfig(result, commandConfig); result = vite.mergeConfig(result, commandConfig);
if (result.plugins) { if (result.plugins) {
sortPlugins(result.plugins); sortPlugins(result.plugins);

View file

@ -39,7 +39,8 @@ export async function sync(
optimizeDeps: { entries: [] }, optimizeDeps: { entries: [] },
logLevel: 'silent', logLevel: 'silent',
}, },
{ settings, logging, mode: 'build', fs } // Important to disallow user-provided Vite plugins that might be stateful!
{ settings, logging, mode: 'build', fs, allowUserPlugins: false }
) )
); );