mrmd-sync 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrmd-sync",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Production-ready sync server for mrmd - real-time collaboration with file persistence",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import { Awareness } from 'y-protocols/awareness';
11
11
  * Server configuration options
12
12
  */
13
13
  export interface ServerConfig {
14
- /** Base directory for .md files (default: './docs') */
14
+ /** Base directory for .md files (default: '.') */
15
15
  dir?: string;
16
16
 
17
17
  /** WebSocket server port (default: 4444) */
@@ -207,7 +207,7 @@ export interface SyncServer {
207
207
  * import { createServer } from 'mrmd-sync';
208
208
  *
209
209
  * const server = createServer({
210
- * dir: './docs',
210
+ * dir: '.',
211
211
  * port: 4444,
212
212
  * });
213
213
  *
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  } from 'fs';
28
28
  import { join, dirname, relative, resolve } from 'path';
29
29
  import { createHash } from 'crypto';
30
+ import { tmpdir } from 'os';
30
31
 
31
32
  // =============================================================================
32
33
  // PID FILE - Prevents multiple instances on same directory
@@ -259,7 +260,7 @@ class Metrics {
259
260
  // =============================================================================
260
261
 
261
262
  const DEFAULT_CONFIG = {
262
- dir: './docs',
263
+ dir: '.',
263
264
  port: 4444,
264
265
  auth: null,
265
266
  debounceMs: 1000,
@@ -471,7 +472,11 @@ export function createServer(options = {}) {
471
472
 
472
473
  // Resolve directory path
473
474
  const resolvedDir = resolve(dir);
474
- const snapshotDir = join(resolvedDir, '.mrmd-sync');
475
+
476
+ // Use temp directory for state (PID file, Yjs snapshots)
477
+ // Hash the resolved dir to create a unique, deterministic temp path
478
+ const dirHash = createHash('sha256').update(resolvedDir).digest('hex').slice(0, 12);
479
+ const snapshotDir = join(tmpdir(), `mrmd-sync-${dirHash}`);
475
480
 
476
481
  // Security check
477
482
  if (isDangerousPath(resolvedDir) && !dangerouslyAllowSystemPaths) {
@@ -745,7 +750,6 @@ export function createServer(options = {}) {
745
750
 
746
751
  const watcher = watch(join(resolvedDir, '**/*.md'), {
747
752
  ignoreInitial: true,
748
- ignored: [join(snapshotDir, '**')], // Ignore snapshot directory
749
753
  awaitWriteFinish: { stabilityThreshold: 300 },
750
754
  });
751
755
 
@@ -1089,6 +1093,7 @@ export function createServer(options = {}) {
1089
1093
  log.info('Server started', {
1090
1094
  port,
1091
1095
  dir: resolvedDir,
1096
+ stateDir: snapshotDir,
1092
1097
  debounceMs,
1093
1098
  maxConnections,
1094
1099
  persistYjsState,