recordForEditor
uses node:path
.tcm/packages.json: for each scratch file, where the packages tcm provides to it are. The editor's TypeScript (through tcm's plugin) resolves the file's imports with it, the same way tcm does.
import type { CodebaseCore } from "#codebase/tcmts/cli/codebase"; import fs from "node:fs"; import path_1 from "node:path"; export function recordForEditor(cb: CodebaseCore, file: string, dirs: Map<string, string>) { const out = path_1.join(cb.lay.tcmDir, "packages.json"); let current: { files: Record<string, Record<string, string>> } = { files: {} }; try { current = JSON.parse(fs.readFileSync(out, "utf8")); } catch { // none yet } const entry = Object.fromEntries( [...dirs].sort().map(([name, dir]) => [name, path_1.basename(dir)]), ); const before = JSON.stringify(current.files[file] ?? {}); if (before === JSON.stringify(entry)) return; if (dirs.size) current.files[file] = entry; else delete current.files[file]; fs.writeFileSync( out, JSON.stringify({ cacheDir: cb.lay.cacheDir, files: current.files }, null, 2) + "\n", ); }