redraft-local 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist-server/cli.mjs +50 -10
  2. package/package.json +1 -1
@@ -6,7 +6,12 @@ import { Command } from "commander";
6
6
 
7
7
  // server/fs/watcher.ts
8
8
  import chokidar from "chokidar";
9
- import { readdirSync, readFileSync } from "node:fs";
9
+ import {
10
+ existsSync,
11
+ readdirSync,
12
+ readFileSync,
13
+ watch as fsWatch
14
+ } from "node:fs";
10
15
  import { relative as relative2, resolve as resolve2 } from "node:path";
11
16
  import ignore2 from "ignore";
12
17
 
@@ -273,11 +278,7 @@ function toRelativePath(basePath, filePath) {
273
278
  }
274
279
  return relativePath;
275
280
  }
276
- function startWatcher(basePath, onEvent) {
277
- const watcher = chokidar.watch(basePath, {
278
- ignoreInitial: true,
279
- persistent: true
280
- });
281
+ function startWatcher(basePath, onEvent, watchFn = (path, opts) => fsWatch(path, opts)) {
281
282
  const ignoreMatcher = loadIgnoreMatcher(basePath);
282
283
  const pendingEvents = /* @__PURE__ */ new Map();
283
284
  let flushTimer;
@@ -314,14 +315,53 @@ function startWatcher(basePath, onEvent) {
314
315
  }
315
316
  }, 100);
316
317
  };
317
- watcher.on("add", (filePath) => queueEvent("file:created", filePath));
318
- watcher.on("change", (filePath) => queueEvent("file:changed", filePath));
319
- watcher.on("unlink", (filePath) => queueEvent("file:deleted", filePath));
320
- return () => {
318
+ const stopFlush = () => {
321
319
  if (flushTimer) {
322
320
  clearTimeout(flushTimer);
323
321
  flushTimer = void 0;
324
322
  }
323
+ };
324
+ if (process.platform === "darwin" || process.platform === "win32") {
325
+ const nativeWatcher = watchFn(basePath, {
326
+ recursive: true,
327
+ persistent: true
328
+ });
329
+ nativeWatcher.on(
330
+ "change",
331
+ (eventType, filename) => {
332
+ if (!filename) {
333
+ return;
334
+ }
335
+ const name = Buffer.isBuffer(filename) ? filename.toString() : filename;
336
+ const absolutePath = resolve2(basePath, name);
337
+ if (eventType === "rename") {
338
+ const type = existsSync(absolutePath) ? "file:created" : "file:deleted";
339
+ queueEvent(type, absolutePath);
340
+ } else {
341
+ queueEvent("file:changed", absolutePath);
342
+ }
343
+ }
344
+ );
345
+ nativeWatcher.on("error", (err) => {
346
+ console.error("[redraft] watcher error:", err);
347
+ });
348
+ return () => {
349
+ stopFlush();
350
+ nativeWatcher.close();
351
+ };
352
+ }
353
+ const watcher = chokidar.watch(basePath, {
354
+ ignoreInitial: true,
355
+ persistent: true
356
+ });
357
+ watcher.on("add", (filePath) => queueEvent("file:created", filePath));
358
+ watcher.on("change", (filePath) => queueEvent("file:changed", filePath));
359
+ watcher.on("unlink", (filePath) => queueEvent("file:deleted", filePath));
360
+ watcher.on("error", (err) => {
361
+ console.error("[redraft] watcher error:", err);
362
+ });
363
+ return () => {
364
+ stopFlush();
325
365
  void watcher.close();
326
366
  };
327
367
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redraft-local",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Local-first proposal review tool — serve and review Markdown proposals from any directory",
5
5
  "repository": {
6
6
  "type": "git",