[lexical-code][lexical-markdown] Use lightweight code-node import in …#8196
[lexical-code][lexical-markdown] Use lightweight code-node import in …#8196gurkerl83 wants to merge 1 commit intofacebook:mainfrom
Conversation
…markdown
## Summary
Decouple `@lexical/markdown` code-block internals from the Prism-heavy `@lexical/code` root export by introducing and consuming a lightweight `@lexical/code/node` subpath.
## Problem
`@lexical/markdown` imported code-node APIs from `@lexical/code` root, which pulls Prism-related modules into markdown-only dependency graphs.
## Changes
- Added new public subpath export: `@lexical/code/node`
- Exposes only node-focused APIs:
- `$createCodeNode`
- `$isCodeNode`
- `CodeNode`
- `DEFAULT_CODE_LANGUAGE`
- `getDefaultCodeLanguage`
- `SerializedCodeNode` (type)
- Switched markdown internals to import from `@lexical/code/node`:
- `MarkdownTransformers.ts`
- `MarkdownShortcuts.ts`
- `utils.ts`
- Added TS path mappings for `@lexical/code/node`.
- Added regression guardrail test to ensure markdown source does not import `@lexical/code` root.
## Compatibility
No markdown API behavior changes (`TRANSFORMERS`, `CODE`, import/export/shortcuts behavior remain unchanged).
## Validation
- `pnpm exec vitest run packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.ts`
- `pnpm exec vitest run packages/lexical-code/src/__tests__/unit/LexicalCodeNode.test.ts`
- `pnpm exec vitest run scripts/__tests__/unit/build.test.ts scripts/__tests__/unit/markdown-deps.test.ts`
Bundle proof (markdown-only entry via esbuild metafile):
- `packages/lexical-code/src/FacadePrism.ts`: **not present**
- `prismjs/components/prism-*`: **not present**
Fixes facebook#5381
Related to facebook#4550 facebook#5424 facebook#6575
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @gurkerl83! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
I’m not sure that this is the best approach. At some point the prism stuff needs to be moved out. I don’t know if it’s worth making this awkward extra module to support that doesn’t follow other lexical conventions and also doesn’t make any progress into extracting prism highlighting into its own package. |
|
Fair point, I can work on this strategy as well 🙂 Another point is that lexical/code is adding also a tone of stuff on lexical/markdown… |
|
The approach here is also not complete for what it is doing, because a lot of tsconfig.json and package.json are maintained by scripts (but due to the nature of json they can't have comments warning about that) so this change would cause problems as soon as those scripts are run. |
Summary
Decouple
@lexical/markdowncode-block internals from the Prism-heavy@lexical/coderoot export by introducing and consuming a lightweight@lexical/code/nodesubpath.Problem
@lexical/markdownimported code-node APIs from@lexical/coderoot, which pulls Prism-related modules into markdown-only dependency graphs.Changes
@lexical/code/node$createCodeNode$isCodeNodeCodeNodeDEFAULT_CODE_LANGUAGEgetDefaultCodeLanguageSerializedCodeNode(type)@lexical/code/node:MarkdownTransformers.tsMarkdownShortcuts.tsutils.ts@lexical/code/node.@lexical/coderoot.Compatibility
No markdown API behavior changes (
TRANSFORMERS,CODE, import/export/shortcuts behavior remain unchanged).Apps that need syntax highlighting should continue to set it up explicitly via
@lexical/code(highlight node/plugin); this PR only removes implicit Prism inclusion from markdown-only paths.Validation
pnpm exec vitest run packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.tspnpm exec vitest run packages/lexical-code/src/__tests__/unit/LexicalCodeNode.test.tspnpm exec vitest run scripts/__tests__/unit/build.test.ts scripts/__tests__/unit/markdown-deps.test.tsBundle proof (markdown-only entry via esbuild metafile):
packages/lexical-code/src/FacadePrism.ts: not presentprismjs/components/prism-*: not presentFixes #5381
Related to #4550 #5424 #6575