Bug fixes

This commit is contained in:
david 2023-04-11 21:48:05 +10:00
parent fd3392fb23
commit 2b40438341

View file

@ -1,11 +1,10 @@
import CheapWatch from "cheap-watch"; import CheapWatch from "cheap-watch";
import { config } from "./config"; import { config } from "./config";
import { EventType } from "./eventTypes"; import { EventType } from "./eventTypes";
import { mkdir } from "fs/promises"; import { mkdir, readdir } from "fs/promises";
import { resolve } from "path"; import { resolve } from "path";
import type { Signal } from "signal-js"; import type { Signal } from "signal-js";
import type { File } from "./interfaces"; import type { File } from "./interfaces";
import fs from "node:fs";
function isError(err: unknown): err is NodeJS.ErrnoException { function isError(err: unknown): err is NodeJS.ErrnoException {
return (err as NodeJS.ErrnoException).code !== undefined; return (err as NodeJS.ErrnoException).code !== undefined;
@ -21,13 +20,13 @@ export async function setupWatch(signaller: Signal) {
} }
} }
const excludedPaths = config.get("exclude").map((path) => resolve(path)); const promises = config.get("exclude")
const excludedFiles = new Set<string>(); .map(path => readdir(resolve(path)).catch(err => {
for (const excludedPath of excludedPaths) { console.log(`Failed to excluded item ${path}: ${err}`);
for (const excludedFile of fs.readdirSync(excludedPath)) { return [];
excludedFiles.add(excludedFile); }));
} const excludedFiles = new Set(await Promise.all(promises)
} .then(lists => lists.flat()));
const fileFilter = (file: File) => { const fileFilter = (file: File) => {
// If the file is excluded, skip all other checks and ignore it. // If the file is excluded, skip all other checks and ignore it.