Repository navigation
Ship native ESM to avoid bundling an extra KaTeX copy - #12
Merged
Merged
Conversation
Preserve ESM KaTeX imports to avoid bundling an additional CommonJS copy in ESM consumers. Build and watch both formats with matching source maps and declarations, and validate package entry points and rendering parity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Resolve the package-version inconsistency and add runtime/type assertions against an extracted npm pack tarball.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds native ESM packaging alongside CommonJS to prevent duplicate KaTeX bundling while preserving existing behavior.
Changes:
- Adds conditional ESM/CommonJS exports and ESM declarations.
- Builds both formats with source maps and expanded validation.
- Documents ESM usage and updates generated artifacts.
| File | Reviewed changes |
|---|---|
types.d.ts |
Declaration formatting updates. |
test/package.js |
Entry-point, type, source-map, and parity checks. |
README.md |
Native ESM usage documentation. |
package.json |
Conditional exports and dual-format build configuration. |
package-lock.json |
Package metadata synchronization. |
dist/index.mjs.map |
Generated ESM source map. |
dist/index.mjs |
Generated native ESM runtime. |
dist/index.d.mts |
ESM TypeScript declaration. |
build/compile.js |
Dual-format compilation and watch support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Keep the ESM packaging PR at version 1.1.6; the maintainer will handle the version bump and release separately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
The packaging fix in #10 made clean installs work, but routed both
importandrequireto CommonJS. MarkEdit-preview imports KaTeX as ESM, while the plugin then required CommonJS KaTeX, so Vite bundled an additional copy. This fixes that packaging regression without changing the parser.Changes
importto nativedist/index.mjsandrequireto the existingdist/index.js..d.mtsdeclaration for native ESM TypeScript consumers, preserving the CommonJS types and existing declaration subpath.Validation
npm packtarball.npm run verify-dist.The new bundle removes the additional top-level CommonJS KaTeX module and returns exactly to the original-source bundle size. Mermaid retains its own pre-existing KaTeX dependency.