fix(build): Bundle the plugin with tsdown to load ESM vim engine - #73
Merged
Conversation
@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.
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.
Problem
The plugin fails to activate on Inkdrop 6:
@replit/codemirror-vim@6.4.0split its engine into@replit/codemirror-vim-core@0.1.0, which is ESM-only ("type": "module", a singleexport function initVim(CM)). Its owndist/index.cjsthereforerequire()s an ESM file. Inkdrop loads plugins through CommonJSrequire(), so activation throws before the plugin ever runs.Fix
Bundle
src/into one CJS file with tsdown, the same approach themermaidandembedplugins use.inkdropand@codemirror/*stay external — those must resolve to the host's instances (via Inkdrop'sexports/@codemirror/*.jsshims) or the plugin's extensions would run against a duplicate@codemirror/stateand be rejected by the editor.@replitpackages, is bundled in.@replit/codemirror-vimmoves todevDependencies; the plugin now has no runtime dependencies.main→./lib/index,lib/gitignored,prepublishOnly: npm run build.Also in this PR
src/vim.js→src/index.tswithexport default new VimPlugin()(tsdown'scjsDefaultemitsmodule.exports = …, so the loader contract is unchanged). Adds@inkdropapp/types,typescript@^7.0.2(matching desktop-v6), and@codemirror/state/viewas devDeps for typechecking.actionsimport in the entry, two leftoverconsole.logcalls in the preview scroll handlers, and avim.visualBlockargument that was alwaysundefined(vimis the extension factory, not vim state).Size
lib/index.jsis 127 KB minified / 40 KB gzipped. Sourcemap attribution:@replit/codemirror-vim-core(vim engine)@replit/codemirror-vim(CM6 adapter)src/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— cleanpnpm lint— 0 warnings, 0 errors over 8 filespnpm build— emits only the five@codemirror/*requires as externalsnode require()oflib/index.jsreturns the plugin instance withactivateand both config keys — theSyntaxErroris gone: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