Make @docmost/git-sync natively consumable by the CommonJS server (and jest):
build to CommonJS (tsconfig module CommonJS, drop type:module, strip .js from
relative imports), and lazy-load the only ESM-only dep (marked) via the dynamic
Function('import()') trick (mirrors docmost-client.loader.ts) with a require()
fallback so vitest's evaluator works too. git-sync tests stay green (314 pass,
3 expected fail).
Add the §13.1 idempotency gate (apps/server .../git-sync-converter-gate.spec.ts):
13 editor-ext docs (paragraphs/headings, marks, links, bullet/ordered/task lists,
blockquote, callouts, code block, hr, table, nested mix) round-trip
content(editor-ext) -> convertProseMirrorToMarkdown -> markdownToProseMirror ->
TiptapTransformer.toYdoc/fromYdoc(tiptapExtensions) -> canonicalize and assert
docsCanonicallyEqual. All green => the vendored converter's docmost-schema is
schema-compatible with editor-ext (no node/mark/attr loss), which the plan §13.1
requires before Phase B. The one intrinsic markdown-image lossiness (width/height
/align can't ride plain ) is isolated in a KNOWN DIVERGENCE block, not
hidden. Server tsc clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
2.0 KiB
JavaScript
40 lines
2.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.stabilizePageFile = stabilizePageFile;
|
|
/**
|
|
* Normalize-on-write helper (SPEC §11 "Резолюция").
|
|
*
|
|
* git diffs byte-for-byte, so writing a page in a NON-fixpoint markdown form
|
|
* would make the next pull re-export it to a slightly different (but stable)
|
|
* form and produce a phantom diff -> churny commits. The converter has a couple
|
|
* of known one-pass asymmetries (a block image after a paragraph adds an empty
|
|
* paragraph; a diagram materializes `data-align`), all of which converge to a
|
|
* fixpoint after ONE `export -> import -> export` round-trip.
|
|
*
|
|
* So at write time we run exactly that one pass and persist the fixpoint form.
|
|
* Already-stable content is unaffected (the pass is idempotent), so re-pulls of
|
|
* unchanged pages produce identical bytes and git sees no diff.
|
|
*/
|
|
const index_1 = require("../lib/index");
|
|
/**
|
|
* Produce the self-contained `.md` file text for a page from its raw
|
|
* ProseMirror `content` + identity meta, in the verified fixpoint form.
|
|
*
|
|
* md1 = convertProseMirrorToMarkdown(content)
|
|
* doc2 = markdownToProseMirror(md1) // one import...
|
|
* stableBody = convertProseMirrorToMarkdown(doc2) // ...and re-export
|
|
* file = serializeDocmostMarkdownBody(meta, stableBody)
|
|
*
|
|
* The single export->import->export pass is the verified fixpoint (SPEC §11):
|
|
* idempotent for already-stable content, and the convergence point for the
|
|
* known converter asymmetries.
|
|
*/
|
|
async function stabilizePageFile(content, meta) {
|
|
const md1 = (0, index_1.convertProseMirrorToMarkdown)(content);
|
|
const doc2 = await (0, index_1.markdownToProseMirror)(md1);
|
|
const stableBody = (0, index_1.convertProseMirrorToMarkdown)(doc2);
|
|
// The meta shape is exactly what `exportPageBody` writes; cast to the lib's
|
|
// DocmostMdMeta (a superset with optional fields) for the serializer.
|
|
return (0, index_1.serializeDocmostMarkdownBody)(meta, stableBody);
|
|
}
|