Files
backnotprop__plannotator/packages/shared/annotate-reference-roots-node.ts
Michael Ramos 195328f7a6 Persist saved annotate file edits in drafts (#936)
* Persist saved annotate file edits in drafts

* Handle stale saved file edit context

* Test source edit conflict actions

* Return source metadata for single-file docs

* Fix saved file edit conflict races

* Handle deleted source files in annotate edits

* Tighten annotate missing-file recovery

* Reset edit state for missing file reopen

* Tighten source edit restore path handling

* Harden source edit recovery paths

* Harden source edit disk reconciliation

* Fix live file tree startup delay

* Document file tree watcher startup ordering

* Preserve source save through missing files and symlinks

* Harden missing source file recovery

* Tighten annotate source edit boundaries
2026-06-18 21:31:25 -07:00

40 lines
1.1 KiB
TypeScript

import { realpathSync } from "fs";
import { dirname } from "path";
import { resolveUserPath } from "./resolve-file";
export interface AnnotateReferenceRootOptions {
mode?: string;
filePath: string;
folderPath?: string;
initialSingleFileSourcePath?: string | null;
}
export function getAnnotateReferenceRootPaths(options: AnnotateReferenceRootOptions): string[] {
const roots: string[] = [];
const addRoot = (root: string | null | undefined) => {
if (!root) return;
const resolved = resolveUserPath(root);
if (!roots.includes(resolved)) roots.push(resolved);
try {
const real = realpathSync(resolved);
if (!roots.includes(real)) roots.push(real);
} catch {
/* Missing source paths still contribute their lexical parent. */
}
};
if (options.mode === "annotate-folder" && options.folderPath) {
addRoot(options.folderPath);
return roots;
}
addRoot(process.cwd());
if (/^https?:\/\//i.test(options.filePath)) {
return roots;
}
addRoot(dirname(options.filePath));
addRoot(options.initialSingleFileSourcePath ? dirname(options.initialSingleFileSourcePath) : null);
return roots;
}