diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index 616ec7aec..d52a8be17 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -94,17 +94,17 @@ async function compile(config: AstroConfig, filename: string, source: string, vi // throw CSS transform errors here if encountered if (cssTransformError) throw cssTransformError; - const compileResult: CompileResult = Object.create(transformResult, { + const compileResult: CompileResult = Object.create(transformResult, { rawCSSDeps: { - value: rawCSSDeps - } + value: rawCSSDeps, + }, }); return compileResult; } export function isCached(config: AstroConfig, filename: string) { - return configCache.has(config) && (configCache.get(config)!).has(filename); + return configCache.has(config) && configCache.get(config)!.has(filename); } export function invalidateCompilation(config: AstroConfig, filename: string) { @@ -114,7 +114,13 @@ export function invalidateCompilation(config: AstroConfig, filename: string) { } } -export async function cachedCompilation(config: AstroConfig, filename: string, source: string | null, viteTransform: TransformHook, opts: boolean | undefined): Promise { +export async function cachedCompilation( + config: AstroConfig, + filename: string, + source: string | null, + viteTransform: TransformHook, + opts: boolean | undefined +): Promise { let cache: CompilationCache; if (!configCache.has(config)) { cache = new Map(); diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index f39d3fecd..84f06cda5 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -13,25 +13,31 @@ interface TrackCSSDependenciesOptions { export async function trackCSSDependencies(this: RollupPluginContext, opts: TrackCSSDependenciesOptions): Promise { const { viteDevServer, filename, deps, id } = opts; // Dev, register CSS dependencies for HMR. - if(viteDevServer) { + if (viteDevServer) { const mod = viteDevServer.moduleGraph.getModuleById(id); - if(mod) { - const cssDeps = (await Promise.all(Array.from(deps).map((spec) => { - return this.resolve(spec, id); - }))).filter(Boolean).map(dep => (dep as ResolvedId).id); + if (mod) { + const cssDeps = ( + await Promise.all( + Array.from(deps).map((spec) => { + return this.resolve(spec, id); + }) + ) + ) + .filter(Boolean) + .map((dep) => (dep as ResolvedId).id); const { moduleGraph } = viteDevServer; // record deps in the module graph so edits to @import css can trigger // main import to hot update const depModules = new Set(mod.importedModules); for (const dep of cssDeps) { - depModules.add(moduleGraph.createFileOnlyEntry(dep)) + depModules.add(moduleGraph.createFileOnlyEntry(dep)); } // Update the module graph, telling it about our CSS deps. moduleGraph.updateModuleInfo(mod, depModules, new Set(), true); for (const dep of cssDeps) { - this.addWatchFile(dep); + this.addWatchFile(dep); } } } @@ -45,13 +51,13 @@ export function handleHotUpdate(ctx: HmrContext, config: AstroConfig) { // that needs to be rerun. const filtered = new Set(); const files = new Set(); - for(const mod of ctx.modules) { - if(mod.file && isCached(config, mod.file)) { + for (const mod of ctx.modules) { + if (mod.file && isCached(config, mod.file)) { filtered.add(mod); files.add(mod.file); } - for(const imp of mod.importers) { - if(imp.file && isCached(config, imp.file)) { + for (const imp of mod.importers) { + if (imp.file && isCached(config, imp.file)) { filtered.add(imp); files.add(imp.file); } @@ -60,7 +66,7 @@ export function handleHotUpdate(ctx: HmrContext, config: AstroConfig) { // Invalidate happens as a separate step because a single .astro file // produces multiple CSS modules and we want to return all of those. - for(const file of files) { + for (const file of files) { invalidateCompilation(config, file); }