con un clic
sync-upstream
// Use when upstream @lexical/code has new releases, when user asks to sync/merge/update from facebook/lexical, or when checking if this fork is behind upstream
// Use when upstream @lexical/code has new releases, when user asks to sync/merge/update from facebook/lexical, or when checking if this fork is behind upstream
| name | sync-upstream |
| description | Use when upstream @lexical/code has new releases, when user asks to sync/merge/update from facebook/lexical, or when checking if this fork is behind upstream |
This repo is a minimal fork of @lexical/code with Prism.js removed. Only FacadePrism.ts differs from upstream. All other source files are byte-identical. This constraint makes merges predictable.
src/
index.ts # byte-identical to upstream
CodeNode.ts # byte-identical to upstream
CodeHighlightNode.ts # byte-identical to upstream
CodeExtension.ts # byte-identical to upstream
CodeHighlighterPrism.ts # byte-identical to upstream
FlatStructureUtils.ts # byte-identical to upstream
FacadePrism.ts # ★ ONLY modified file — Prism stubbed out
shared/invariant.ts # shim for monorepo-internal import
.upstream/
VERSION # last synced upstream version
FacadePrism.ts.base # upstream FacadePrism.ts at last sync (for 3-way merge)
.upstream/VERSION with latest @lexical/code npm version./scripts/sync-upstream.sh # sync to latest HEAD
./scripts/sync-upstream.sh v0.42.0 # sync to specific tag
The script handles everything: clone, copy identical files, 3-way merge FacadePrism.ts, rebuild, verify.
Check current version:
cat .upstream/VERSION
Clone upstream at target version:
git clone --depth 1 --branch v0.XX.0 https://github.com/facebook/lexical.git /tmp/lexical-sync
Copy byte-identical files (6 files, direct overwrite):
for f in index.ts CodeNode.ts CodeHighlightNode.ts CodeExtension.ts CodeHighlighterPrism.ts FlatStructureUtils.ts; do
cp /tmp/lexical-sync/packages/lexical-code/src/$f src/$f
done
3-way merge FacadePrism.ts:
git merge-file src/FacadePrism.ts .upstream/FacadePrism.ts.base /tmp/lexical-sync/packages/lexical-code/src/FacadePrism.ts
Update base snapshot:
cp /tmp/lexical-sync/packages/lexical-code/src/FacadePrism.ts .upstream/FacadePrism.ts.base
echo "0.XX.0" > .upstream/VERSION
Rebuild and verify:
pnpm install && pnpm typecheck && pnpm build
# Verify no prismjs in output:
grep -r "prismjs" dist/index.js dist/index.mjs # should return nothing
Our modifications to FacadePrism.ts are in 4 isolated regions. When conflicts arise, preserve these:
// All `import 'prismjs/...'` lines should stay REMOVED
// Local Token/TokenStream types should stay
// Keep our stub:
export const Prism: any = {
languages: {
diff: {PREFIXES: {}},
} as Record<string, any>,
tokenize(code: string, _grammar?: unknown): string[] {
return [code];
},
Token: class { /* ... */ },
};
// Keep: Object.keys(CODE_LANGUAGE_FRIENDLY_NAME_MAP).sort()
// NOT: Object.keys(Prism.languages)...
// Keep: return true;
// NOT: Prism.languages.hasOwnProperty(...)
Everything else (language maps, utility functions, tokenizeDiffHighlight, $getHighlightNodes, $mapTokensToLexicalStructure) should accept upstream changes as-is.
If upstream adds/removes/renames files:
src/, add to IDENTICAL_FILES in sync scriptsrc/ and sync scriptshared/invariant and @lexical/code self-referencepeerDependencies in package.jsonAfter sync, confirm:
pnpm typecheck passes (zero errors)pnpm build succeedsgrep -r "prismjs" dist/index.js dist/index.mjs returns nothingdiff src/$f /tmp/lexical-sync/packages/lexical-code/src/$f.upstream/VERSION updated.upstream/FacadePrism.ts.base updated