Bug fixes

This commit is contained in:
david 2023-04-11 21:48:05 +10:00
parent fd3392fb23
commit 043a2d34b1
7 changed files with 25 additions and 26 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env -S node --experimental-specifier-resolution=node
import { start } from "../src/index";
import { start } from "../src/index.js";
await start();

View file

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

View file

@ -1,6 +1,6 @@
import { setupWatch } from "./fileWatch";
import { config, loadConfig } from "./config";
import { setupSocket } from "./networking/webSocket";
import { setupWatch } from "./fileWatch.js";
import { config, loadConfig } from "./config.js";
import { setupSocket } from "./networking/webSocket.js";
import signal from "signal-js";
import { RawData } from "ws";
import {

View file

@ -1,7 +1,7 @@
import { readFileSync } from "fs";
import { config } from "../config";
import { config } from "../config.js";
import { join } from "path";
import type { FileEvent, Message } from "../interfaces";
import type { FileEvent, Message } from "../interfaces.js";
let messageCounter = 0;

View file

@ -1,11 +1,11 @@
import { messageTracker } from "./messageTracker";
import { messageTracker } from "./messageTracker.js";
import { Stats, writeFile } from "fs";
import { RawData } from "ws";
import { config } from "../config";
import { EventType } from "../eventTypes";
import { fileChangeEventToMsg } from "./messageGenerators";
import { config } from "../config.js";
import { EventType } from "../eventTypes.js";
import { fileChangeEventToMsg } from "./messageGenerators.js";
import type { Signal } from "signal-js";
import { Message } from "../interfaces";
import { Message } from "../interfaces.js";
function deserialize(data: RawData): Message {
const msg = JSON.parse(data.toString());

View file

@ -1,4 +1,4 @@
import type { Message } from "../interfaces";
import type { Message } from "../interfaces.js";
class MessageTracker {
data = new Map<number, Message>();

View file

@ -1,9 +1,9 @@
import type { Signal } from "signal-js";
import { WebSocketServer } from "ws";
import { config } from "../config";
import { EventType } from "../eventTypes";
import { Message } from "../interfaces";
import { messageTracker } from "./messageTracker";
import { config } from "../config.js";
import { EventType } from "../eventTypes.js";
import { Message } from "../interfaces.js";
import { messageTracker } from "./messageTracker.js";
export function setupSocket(signaller: Signal) {
const wss = new WebSocketServer({ port: config.get("port") });