diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 2b11585ca..9bb1ff371 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -68,7 +68,7 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg filtered.add(mod); files.add(mod.file); } - + for (const imp of mod.importers) { if (imp.file && isCached(config, imp.file)) { filtered.add(imp); @@ -88,9 +88,9 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg const mods = ctx.modules.filter((m) => !m.url.endsWith('=')); // Add hoisted scripts so these get invalidated - for(const mod of mods) { - for(const imp of mod.importedModules) { - if(imp.id?.includes('?astro&type=script')) { + for (const mod of mods) { + for (const imp of mod.importedModules) { + if (imp.id?.includes('?astro&type=script')) { mods.push(imp); } } diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 47ecfee1e..9ed6f983b 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -127,9 +127,9 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu throw new Error(`Requests for hoisted scripts must include an index`); } // HMR hoisted script only exists to make them appear in the module graph. - if(opts?.ssr) { + if (opts?.ssr) { return { - code: `/* client hoisted script, empty in SSR: ${id} */` + code: `/* client hoisted script, empty in SSR: ${id} */`, }; } @@ -190,15 +190,17 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu } let i = 0; - while(i < transformResult.scripts.length) { + while (i < transformResult.scripts.length) { deps.add(`${id}?astro&type=script&index=${i}`); SUFFIX += `import "${id}?astro&type=script&index=${i}";`; i++; } // We only need to define deps if there are any - if(deps.size > 1) { - SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from(deps).join('","')}"], (...mods) => mods);` + if (deps.size > 1) { + SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from( + deps + ).join('","')}"], (...mods) => mods);`; } else { SUFFIX += `\nif (import.meta.hot) { import.meta.hot.accept(mod => mod); @@ -209,7 +211,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu if (isPage) { SUFFIX += `\nimport "${PAGE_SSR_SCRIPT_ID}";`; } - + return { code: `${code}${SUFFIX}`, map, diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index bc3447214..a510f2eee 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -22,7 +22,6 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig '' ); const privateKeys = Object.keys(fullEnv).filter((key) => { - // don't inject `PUBLIC_` variables, Vite handles that for us for (const envPrefix of envPrefixes) { if (key.startsWith(envPrefix)) return false; @@ -34,10 +33,12 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig if (privateKeys.length === 0) { return null; } - return Object.fromEntries(privateKeys.map((key) => { - if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`]; - return [key, JSON.stringify(fullEnv[key])] - })); + return Object.fromEntries( + privateKeys.map((key) => { + if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`]; + return [key, JSON.stringify(fullEnv[key])]; + }) + ); } function getReferencedPrivateKeys(source: string, privateEnv: Record): Set {