From 6a9bba702c3f35d39f757fdee9c3840669cb69e6 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Wed, 13 May 2026 11:12:40 +0000 Subject: [PATCH] chore: ran prettier --- src/LiveSyncBaseCore.ts | 11 +++--- .../cli/commands/daemonCommand.unit.spec.ts | 12 +++---- src/apps/cli/commands/runCommand.ts | 34 ++++++++++++------- src/apps/cli/commands/types.ts | 11 +++++- src/apps/cli/main.ts | 5 +-- .../managers/CLIStorageEventManagerAdapter.ts | 6 +++- ...CLIStorageEventManagerAdapter.unit.spec.ts | 5 +-- .../cli/serviceModules/CLIServiceModules.ts | 22 +++++++----- src/apps/cli/serviceModules/IgnoreRules.ts | 6 ++-- .../serviceModules/IgnoreRules.unit.spec.ts | 5 +-- src/apps/cli/vite.config.ts | 3 +- .../ObsidianVaultAdapter.ts | 2 +- 12 files changed, 73 insertions(+), 49 deletions(-) diff --git a/src/LiveSyncBaseCore.ts b/src/LiveSyncBaseCore.ts index a3945fd..9a49451 100644 --- a/src/LiveSyncBaseCore.ts +++ b/src/LiveSyncBaseCore.ts @@ -35,11 +35,12 @@ export class LiveSyncBaseCore< TCommands extends IMinimumLiveSyncCommands = IMinimumLiveSyncCommands, > implements - LiveSyncLocalDBEnv, - LiveSyncReplicatorEnv, - LiveSyncJournalReplicatorEnv, - LiveSyncCouchDBReplicatorEnv, - HasSettings { + LiveSyncLocalDBEnv, + LiveSyncReplicatorEnv, + LiveSyncJournalReplicatorEnv, + LiveSyncCouchDBReplicatorEnv, + HasSettings +{ addOns = [] as TCommands[]; /** diff --git a/src/apps/cli/commands/daemonCommand.unit.spec.ts b/src/apps/cli/commands/daemonCommand.unit.spec.ts index 1adb967..2e2a341 100644 --- a/src/apps/cli/commands/daemonCommand.unit.spec.ts +++ b/src/apps/cli/commands/daemonCommand.unit.spec.ts @@ -257,12 +257,12 @@ describe("daemon command", () => { // failure 1: 30000*2=60000, failure 2: 30000*4=120000, // failure 3: 30000*8=240000, failure 4: 30000*16=480000→capped, 5→cap, 6→cap const expectedIntervals = [ - baseMs * 2, // after failure 1: 60000 - baseMs * 4, // after failure 2: 120000 - baseMs * 8, // after failure 3: 240000 - 300_000, // after failure 4 (would be 480000, capped) - 300_000, // after failure 5 (cap) - 300_000, // after failure 6 (cap) + baseMs * 2, // after failure 1: 60000 + baseMs * 4, // after failure 2: 120000 + baseMs * 8, // after failure 3: 240000 + 300_000, // after failure 4 (would be 480000, capped) + 300_000, // after failure 5 (cap) + 300_000, // after failure 6 (cap) ]; for (const expected of expectedIntervals) { diff --git a/src/apps/cli/commands/runCommand.ts b/src/apps/cli/commands/runCommand.ts index c90fa94..9f7df02 100644 --- a/src/apps/cli/commands/runCommand.ts +++ b/src/apps/cli/commands/runCommand.ts @@ -43,10 +43,13 @@ export async function runCommand(options: CLIOptions, context: CLICommandContext // 3. Re-enable sync. const restoreSyncSettings = async () => { - await core.services.setting.applyPartial({ - ...context.originalSyncSettings, - suspendFileWatching: false, - }, true); + await core.services.setting.applyPartial( + { + ...context.originalSyncSettings, + suspendFileWatching: false, + }, + true + ); // applySettings fires the full lifecycle: onSuspending → onResumed. // ModuleReplicatorCouchDB starts continuous replication on onResumed // via fireAndForget. @@ -54,10 +57,13 @@ export async function runCommand(options: CLIOptions, context: CLICommandContext // Lifecycle events (onSuspending) may re-enable suspension flags. // Clear them explicitly after the lifecycle completes. applyPartial // with true is a direct store write — it does not re-trigger lifecycle. - await core.services.setting.applyPartial({ - suspendFileWatching: false, - suspendParseReplicationResult: false, - }, true); + await core.services.setting.applyPartial( + { + suspendFileWatching: false, + suspendParseReplicationResult: false, + }, + true + ); }; if (options.interval) { log(`Polling mode: syncing every ${options.interval}s`); @@ -80,7 +86,9 @@ export async function runCommand(options: CLIOptions, context: CLICommandContext currentIntervalMs = Math.min(baseIntervalMs * Math.pow(2, consecutiveFailures), maxIntervalMs); console.error(`[Daemon] Poll error (${consecutiveFailures} consecutive):`, err); if (consecutiveFailures >= 5) { - console.error(`[Daemon] Warning: ${consecutiveFailures} consecutive failures, backing off to ${Math.round(currentIntervalMs / 1000)}s`); + console.error( + `[Daemon] Warning: ${consecutiveFailures} consecutive failures, backing off to ${Math.round(currentIntervalMs / 1000)}s` + ); } } pollTimer = setTimeout(poll, currentIntervalMs); @@ -99,9 +107,11 @@ export async function runCommand(options: CLIOptions, context: CLICommandContext log("LiveSync active"); const currentSettings = core.services.setting.currentSettings(); if (!currentSettings.liveSync && !currentSettings.syncOnStart) { - console.error("[Daemon] Warning: liveSync and syncOnStart are both disabled in settings. " + - "No sync will occur. Set liveSync=true in your settings file for continuous sync, " + - "or use --interval for polling mode."); + console.error( + "[Daemon] Warning: liveSync and syncOnStart are both disabled in settings. " + + "No sync will occur. Set liveSync=true in your settings file for continuous sync, " + + "or use --interval for polling mode." + ); } } diff --git a/src/apps/cli/commands/types.ts b/src/apps/cli/commands/types.ts index ca01152..d6ccee5 100644 --- a/src/apps/cli/commands/types.ts +++ b/src/apps/cli/commands/types.ts @@ -37,7 +37,16 @@ export interface CLICommandContext { databasePath: string; core: LiveSyncBaseCore; settingsPath: string; - originalSyncSettings: Pick; + originalSyncSettings: Pick< + ObsidianLiveSyncSettings, + | "liveSync" + | "syncOnStart" + | "periodicReplication" + | "syncOnSave" + | "syncOnEditorSave" + | "syncOnFileOpen" + | "syncAfterMerge" + >; } export const VALID_COMMANDS = new Set([ diff --git a/src/apps/cli/main.ts b/src/apps/cli/main.ts index 535d137..7067c70 100644 --- a/src/apps/cli/main.ts +++ b/src/apps/cli/main.ts @@ -280,16 +280,13 @@ export async function main() { // chokidar's ignored option is populated when beginWatch() fires during onLoad(). const watchEnabled = options.command === "daemon"; const vaultPath = - options.command === "mirror" && options.commandArgs[0] - ? path.resolve(options.commandArgs[0]) - : databasePath; + options.command === "mirror" && options.commandArgs[0] ? path.resolve(options.commandArgs[0]) : databasePath; let ignoreRules: IgnoreRules | undefined; if (options.command === "daemon" || options.command === "mirror") { ignoreRules = new IgnoreRules(vaultPath); await ignoreRules.load(); } - // Create service context and hub const context = new NodeServiceContext(databasePath); const serviceHubInstance = new NodeServiceHub(databasePath, context); diff --git a/src/apps/cli/managers/CLIStorageEventManagerAdapter.ts b/src/apps/cli/managers/CLIStorageEventManagerAdapter.ts index 9abc5fd..c2f11e1 100644 --- a/src/apps/cli/managers/CLIStorageEventManagerAdapter.ts +++ b/src/apps/cli/managers/CLIStorageEventManagerAdapter.ts @@ -97,7 +97,11 @@ class CLIConverterAdapter implements IStorageEventConverterAdapter { class CLIWatchAdapter implements IStorageEventWatchAdapter { private _watcher: FSWatcher | undefined; - constructor(private basePath: string, private ignoreRules?: IgnoreRules, private watchEnabled: boolean = false) {} + constructor( + private basePath: string, + private ignoreRules?: IgnoreRules, + private watchEnabled: boolean = false + ) {} private _toNodeFile(filePath: string, stats: Stats | undefined): NodeFile { return { diff --git a/src/apps/cli/managers/CLIStorageEventManagerAdapter.unit.spec.ts b/src/apps/cli/managers/CLIStorageEventManagerAdapter.unit.spec.ts index edfb222..5af69a9 100644 --- a/src/apps/cli/managers/CLIStorageEventManagerAdapter.unit.spec.ts +++ b/src/apps/cli/managers/CLIStorageEventManagerAdapter.unit.spec.ts @@ -60,10 +60,7 @@ describe("CLIStorageEventManagerAdapter", () => { await adapter.watch.beginWatch(handlers); expect(chokidar.watch).toHaveBeenCalledTimes(1); - expect(chokidar.watch).toHaveBeenCalledWith( - "/base", - expect.objectContaining({ ignoreInitial: true }) - ); + expect(chokidar.watch).toHaveBeenCalledWith("/base", expect.objectContaining({ ignoreInitial: true })); }); it("add event produces NodeFile with correct relative path via onCreate", async () => { diff --git a/src/apps/cli/serviceModules/CLIServiceModules.ts b/src/apps/cli/serviceModules/CLIServiceModules.ts index 6c4cce5..50d185a 100644 --- a/src/apps/cli/serviceModules/CLIServiceModules.ts +++ b/src/apps/cli/serviceModules/CLIServiceModules.ts @@ -25,7 +25,7 @@ export function initialiseServiceModulesCLI( core: LiveSyncBaseCore, services: InjectableServiceHub, ignoreRules?: IgnoreRules, - watchEnabled: boolean = false, + watchEnabled: boolean = false ): ServiceModules { const storageAccessManager = new StorageAccessManager(); @@ -39,13 +39,19 @@ export function initialiseServiceModulesCLI( }); // CLI-specific storage event manager - const storageEventManager = new StorageEventManagerCLI(basePath, core, { - fileProcessing: services.fileProcessing, - setting: services.setting, - vaultService: services.vault, - storageAccessManager: storageAccessManager, - APIService: services.API, - }, ignoreRules, watchEnabled); + const storageEventManager = new StorageEventManagerCLI( + basePath, + core, + { + fileProcessing: services.fileProcessing, + setting: services.setting, + vaultService: services.vault, + storageAccessManager: storageAccessManager, + APIService: services.API, + }, + ignoreRules, + watchEnabled + ); // Close the file watcher during graceful shutdown so the process can exit cleanly. services.appLifecycle.onUnload.addHandler(async () => { diff --git a/src/apps/cli/serviceModules/IgnoreRules.ts b/src/apps/cli/serviceModules/IgnoreRules.ts index 9764fd2..0b7fc41 100644 --- a/src/apps/cli/serviceModules/IgnoreRules.ts +++ b/src/apps/cli/serviceModules/IgnoreRules.ts @@ -55,7 +55,9 @@ export class IgnoreRules { continue; } if (trimmed.startsWith("import:")) { - console.error(`[IgnoreRules] Warning: unrecognised directive '${trimmed}' — only 'import: .gitignore' is supported`); + console.error( + `[IgnoreRules] Warning: unrecognised directive '${trimmed}' — only 'import: .gitignore' is supported` + ); continue; } this._addPattern(trimmed); @@ -105,7 +107,7 @@ export class IgnoreRules { if (raw.startsWith("!")) { throw new Error( `[IgnoreRules] Negation pattern '${raw}' is not supported. ` + - `Remove it from .livesync/ignore or use a separate include/exclude file.` + `Remove it from .livesync/ignore or use a separate include/exclude file.` ); } this.patterns.push(this._normalisePattern(raw)); diff --git a/src/apps/cli/serviceModules/IgnoreRules.unit.spec.ts b/src/apps/cli/serviceModules/IgnoreRules.unit.spec.ts index 59bfb12..4f6a606 100644 --- a/src/apps/cli/serviceModules/IgnoreRules.unit.spec.ts +++ b/src/apps/cli/serviceModules/IgnoreRules.unit.spec.ts @@ -122,10 +122,7 @@ describe("IgnoreRules", () => { describe("load() with comments and blank lines", () => { it("skips # comment lines and blank lines", async () => { const vaultPath = await createVault(); - await writeIgnoreFile( - vaultPath, - "# This is a comment\n\n \n*.tmp\n# another comment\nbuild/\n" - ); + await writeIgnoreFile(vaultPath, "# This is a comment\n\n \n*.tmp\n# another comment\nbuild/\n"); const rules = new IgnoreRules(vaultPath); await rules.load(); expect(rules.shouldIgnore("scratch.tmp")).toBe(true); diff --git a/src/apps/cli/vite.config.ts b/src/apps/cli/vite.config.ts index 74c4ba6..11104cd 100644 --- a/src/apps/cli/vite.config.ts +++ b/src/apps/cli/vite.config.ts @@ -47,7 +47,8 @@ function injectBanner(): import("vite").Plugin { // Insert after the shebang line if present, otherwise at the top. if (chunk.code.startsWith("#!")) { const newline = chunk.code.indexOf("\n"); - chunk.code = chunk.code.slice(0, newline + 1) + fileReaderPolyfillBanner + chunk.code.slice(newline + 1); + chunk.code = + chunk.code.slice(0, newline + 1) + fileReaderPolyfillBanner + chunk.code.slice(newline + 1); } else { chunk.code = fileReaderPolyfillBanner + chunk.code; } diff --git a/src/serviceModules/FileSystemAdapters/ObsidianVaultAdapter.ts b/src/serviceModules/FileSystemAdapters/ObsidianVaultAdapter.ts index 78d3559..bb89774 100644 --- a/src/serviceModules/FileSystemAdapters/ObsidianVaultAdapter.ts +++ b/src/serviceModules/FileSystemAdapters/ObsidianVaultAdapter.ts @@ -7,7 +7,7 @@ import type { TFile, App, TFolder } from "obsidian"; * Vault adapter implementation for Obsidian */ export class ObsidianVaultAdapter implements IVaultAdapter { - constructor(private app: App) { } + constructor(private app: App) {} async read(file: TFile): Promise { return await this.app.vault.read(file);