[ci] yarn format

This commit is contained in:
matthewp 2022-02-02 16:36:23 +00:00 committed by GitHub Actions
parent 3e8844fa87
commit eecc996d7e
2 changed files with 29 additions and 17 deletions

View file

@ -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<CompileResult> {
export async function cachedCompilation(
config: AstroConfig,
filename: string,
source: string | null,
viteTransform: TransformHook,
opts: boolean | undefined
): Promise<CompileResult> {
let cache: CompilationCache;
if (!configCache.has(config)) {
cache = new Map();

View file

@ -13,25 +13,31 @@ interface TrackCSSDependenciesOptions {
export async function trackCSSDependencies(this: RollupPluginContext, opts: TrackCSSDependenciesOptions): Promise<void> {
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<ModuleNode>();
const files = new Set<string>();
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);
}