Skip to content

fix(build): Bundle the plugin with tsdown to load ESM vim engine - #73

Merged
craftzdog merged 2 commits into
masterfrom
feat/bundle
Aug 8, 2026
Merged

fix(build): Bundle the plugin with tsdown to load ESM vim engine#73
craftzdog merged 2 commits into
masterfrom
feat/bundle

Conversation

@craftzdog

@craftzdog craftzdog commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Problem

The plugin fails to activate on Inkdrop 6:

SyntaxError: Failed to construct 'ContextifyScript': Unexpected token 'export'
  at .../@replit/codemirror-vim-core/vim.js:41
  at Object.<anonymous> (.../@replit/codemirror-vim/dist/index.cjs:3:25)
  at Object.<anonymous> (.../packages/vim/src/vim.js:1:177)

@replit/codemirror-vim@6.4.0 split its engine into @replit/codemirror-vim-core@0.1.0, which is ESM-only ("type": "module", a single export function initVim(CM)). Its own dist/index.cjs therefore require()s an ESM file. Inkdrop loads plugins through CommonJS require(), so activation throws before the plugin ever runs.

Fix

Bundle src/ into one CJS file with tsdown, the same approach the mermaid and embed plugins use.

  • inkdrop and @codemirror/* stay external — those must resolve to the host's instances (via Inkdrop's exports/@codemirror/*.js shims) or the plugin's extensions would run against a duplicate @codemirror/state and be rejected by the editor.
  • Everything else, including both @replit packages, is bundled in. @replit/codemirror-vim moves to devDependencies; the plugin now has no runtime dependencies.
  • main./lib/index, lib/ gitignored, prepublishOnly: npm run build.

Also in this PR

  • TypeScript — all 8 sources converted; src/vim.jssrc/index.ts with export default new VimPlugin() (tsdown's cjsDefault emits module.exports = …, so the loader contract is unchanged). Adds @inkdropapp/types, typescript@^7.0.2 (matching desktop-v6), and @codemirror/state/view as devDeps for typechecking.
  • oxlint / oxfmt replace eslint / prettier, matching the sibling plugins.
  • Three dead bits the type checker surfaced: an unused actions import in the entry, two leftover console.log calls in the preview scroll handlers, and a vim.visualBlock argument that was always undefined (vim is the extension factory, not vim state).

Size

lib/index.js is 127 KB minified / 40 KB gzipped. Sourcemap attribution:

bytes share
@replit/codemirror-vim-core (vim engine) 92 KB 74.3%
@replit/codemirror-vim (CM6 adapter) 27 KB 21.5%
plugin src/ 5 KB 4.2%

This is smaller than before: the installed plugin used to carry 740 KB of node_modules, of which 324 KB of unminified JS was parsed on every load. Treeshaking can't reduce it further — the engine is one 7,164-line function behind a single export.

Test plan

  • pnpm typecheck — clean
  • pnpm lint — 0 warnings, 0 errors over 8 files
  • pnpm build — emits only the five @codemirror/* requires as externals
  • Plain node require() of lib/index.js returns the plugin instance with activate and both config keys — the SyntaxError is gone
  • Load in Inkdrop 6 and exercise: normal/insert/visual mode classes, :w / :n / :prev / :preview, <C-n>/<C-p> completion nav, yank/paste against the system clipboard across note switches, relative line numbers toggle, preview-pane scroll commands

@replit/codemirror-vim@6.4.0 depends on @replit/codemirror-vim-core,
which is ESM-only. Inkdrop loads plugins through CommonJS require(), so
the transitive require() of the engine threw a SyntaxError on activation.

Bundle src/ into a single CJS file with tsdown, keeping `inkdrop` and
@codemirror/* external so the plugin's extensions still share the host
editor's module instances. Also migrates the source to TypeScript and
replaces eslint/prettier with oxlint/oxfmt.

Drops three dead bits surfaced by the type checker: an unused `actions`
import, two leftover console.log calls in the preview scroll handlers,
and a `vim.visualBlock` argument that was always undefined.
@craftzdog
craftzdog merged commit 5e37e57 into master Aug 8, 2026
1 check passed
@craftzdog
craftzdog deleted the feat/bundle branch August 8, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant