1. gitRemote is NOT yet consumed (the vendored engine has no remote-push path,
SPEC §7). Corrected the buildSettings docstring (it wrongly called gitRemote
"load-bearing") and marked the env -> validation -> getter -> buildSettings
chain as inert SCAFFOLDING for the deferred remote-push feature at all three
sites. Kept the wiring (harmless; removing only churns).
2. .env.example: document that GIT_SYNC_REMOTE_TEMPLATE substitutes the literal
"{spaceId}" per-space (with the example), so an operator doesn't point every
space at one remote.
3. Extracted the copy-pasted CJS->ESM dynamic-import bridge
(`new Function('s','return import(s)')`) into one shared
common/helpers/esm-import.ts; git-sync.loader, docmost-client.loader and
mcp.service now import it and keep their own typed loadX() wrappers.
Deferred (notes only, not implemented):
- lcs.ts + three-way-merge.ts could move into packages/git-sync, but that engine
is vendored (manual re-sync) — added a one-line note at three-way-merge.ts to
revisit once the re-sync story is settled.
- schema-core single source + BullMQ/fencing remain documented from prior rounds.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { pathToFileURL } from 'node:url';
|
|
import { esmImport } from '../../common/helpers/esm-import';
|
|
import type {
|
|
VaultGit as VaultGitClass,
|
|
vaultGitEnv as vaultGitEnvFn,
|
|
runCycle as runCycleFn,
|
|
parseDocmostMarkdown as parseDocmostMarkdownFn,
|
|
markdownToProseMirror as markdownToProseMirrorFn,
|
|
} from '@docmost/git-sync';
|
|
|
|
/**
|
|
* Runtime value-export surface of the ESM-only `@docmost/git-sync` package that
|
|
* the server consumes. Types are imported with `import type` (erased at compile,
|
|
* no runtime require); only the VALUE exports below need the dynamic-load
|
|
* treatment so a CJS `require()` of the ESM package never happens.
|
|
*/
|
|
interface GitSyncModule {
|
|
VaultGit: typeof VaultGitClass;
|
|
vaultGitEnv: typeof vaultGitEnvFn;
|
|
runCycle: typeof runCycleFn;
|
|
parseDocmostMarkdown: typeof parseDocmostMarkdownFn;
|
|
markdownToProseMirror: typeof markdownToProseMirrorFn;
|
|
}
|
|
|
|
// The CJS->ESM dynamic-import bridge lives in one shared helper
|
|
// (common/helpers/esm-import.ts); see it for why `import()` must be hidden from
|
|
// the TS commonjs downleveler. The typed `loadGitSync()` wrapper stays here.
|
|
|
|
// Memoize the in-flight/loaded module so the dynamic import runs at most once.
|
|
let modulePromise: Promise<GitSyncModule> | null = null;
|
|
|
|
/**
|
|
* Lazily load the ESM-only `@docmost/git-sync` package (cached). Resolves the
|
|
* package entry to an absolute path, then imports it as a `file://` URL so the
|
|
* package "exports" map is honoured without bare-specifier resolution-base
|
|
* fragility.
|
|
*/
|
|
export async function loadGitSync(): Promise<GitSyncModule> {
|
|
if (!modulePromise) {
|
|
modulePromise = (async () => {
|
|
const entry = require.resolve('@docmost/git-sync');
|
|
const mod = (await esmImport(
|
|
pathToFileURL(entry).href,
|
|
)) as GitSyncModule;
|
|
return mod;
|
|
})().catch((err) => {
|
|
// Do not cache a rejected import — allow the next call to retry.
|
|
modulePromise = null;
|
|
throw err;
|
|
});
|
|
}
|
|
return modulePromise;
|
|
}
|