From c299d7b6a4bf452d4db62161f4fd701ff3b74d4c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 23 May 2022 19:54:53 +0200 Subject: [PATCH] fix: `fresh manifest --watch` reliability (#210) Cache invalidation in the new `fresh manifest --watch` was not correct, making the command unreliable. --- src/cli/manifest.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cli/manifest.ts b/src/cli/manifest.ts index ed714211..63a78265 100644 --- a/src/cli/manifest.ts +++ b/src/cli/manifest.ts @@ -180,23 +180,23 @@ export async function manifest(directory: string, watch: boolean) { if (!watch) return; const watcher = Deno.watchFs(directory, { recursive: true }); - for await (const _ of watcher) { + for await (const e of watcher) { + if (e.kind === "access") continue; const newManifest = await collect(directory); - // check if the manifests are identical - const routesSet = new Set([ - ...currentManifest.routes, - ...newManifest.routes, - ]); - const islandsSet = new Set([ - ...currentManifest.islands, - ...newManifest.islands, - ]); if ( - routesSet.size !== newManifest.routes.length || - islandsSet.size !== newManifest.islands.length + !arraysEqual(newManifest.routes, currentManifest.routes) || + !arraysEqual(newManifest.islands, currentManifest.islands) ) { currentManifest = newManifest; await generate(directory, currentManifest); } } } + +function arraysEqual(a: T[], b: T[]): boolean { + if (a.length !== b.length) return false; + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; +}