0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -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

View file

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

View file

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