0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-17 23:11:29 -05:00

fix: do not use fs mock

This commit is contained in:
Florian Lefebvre 2024-08-12 17:16:15 +02:00
parent d835645adf
commit 5bee7ff39b
2 changed files with 5 additions and 7 deletions
packages/astro/src

View file

@ -133,7 +133,7 @@ export async function createVite(
// the build to run very slow as the filewatcher is triggered often.
mode !== 'build' && vitePluginAstroServer({ settings, logger, fs }),
envVitePlugin({ settings }),
astroEnv({ settings, mode, fs, sync }),
astroEnv({ settings, mode, sync }),
markdownVitePlugin({ settings, logger }),
htmlVitePlugin(),
mdxVitePlugin(),

View file

@ -1,4 +1,4 @@
import type fsMod from 'node:fs';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { type Plugin, loadEnv } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
@ -15,11 +15,10 @@ import { getEnvFieldType, validateEnvVariable } from './validators.js';
interface AstroEnvPluginParams {
settings: AstroSettings;
mode: 'dev' | 'build' | string;
fs: typeof fsMod;
sync: boolean;
}
export function astroEnv({ settings, mode, fs, sync }: AstroEnvPluginParams): Plugin | undefined {
export function astroEnv({ settings, mode, sync }: AstroEnvPluginParams): Plugin | undefined {
if (sync) {
return;
}
@ -49,7 +48,7 @@ export function astroEnv({ settings, mode, fs, sync }: AstroEnvPluginParams): Pl
});
templates = {
...getTemplates(schema, fs, validatedVariables),
...getTemplates(schema, validatedVariables),
internal: `export const schema = ${JSON.stringify(schema)};`,
};
},
@ -126,11 +125,10 @@ function validatePublicVariables({
function getTemplates(
schema: EnvSchema,
fs: typeof fsMod,
validatedVariables: ReturnType<typeof validatePublicVariables>,
) {
let client = '';
let server = fs.readFileSync(MODULE_TEMPLATE_URL, 'utf-8');
let server = readFileSync(MODULE_TEMPLATE_URL, 'utf-8');
let onSetGetEnv = '';
for (const { key, value, context } of validatedVariables) {