feat!: externalize codemirror, react-codemirror2, and prop-types (semver-major) - #648
feat!: externalize codemirror, react-codemirror2, and prop-types (semver-major)#648erunion wants to merge 2 commits into
Conversation
Re-enables minification (disabled by a workaround in #595 that no longer applies, since the dev demo uses a fully separate webpack config), vendors just the ~600 lines of the `codemirror-graphql` mode that we actually use instead of pulling in `graphql-language-service` and all of `graphql` (566 KB of unused validation rules), drops the now-dead `codemirror/mode/meta` import, and adds a `files` allowlist so the npm tarball only ships `dist`.
These are already runtime `dependencies` that every consumer installs, so bundling them into `dist/index.js` too was double-shipping and prevented the consumer's own bundler from deduping CodeMirror against any other copy in their app. Extends `externals` (following the existing `react`/`react-dom`/`@readme/variable` precedent) to cover `codemirror`, `react-codemirror2`, `prop-types`, and deep `codemirror/mode/*`, `codemirror/addon/*` requires -- excluding `.css` imports, which stay bundled via style-loader so consumers don't need their own CSS handling for our node_modules imports. BREAKING CHANGE: consumers must have `codemirror`, `react-codemirror2`, and `prop-types` resolvable in their own dependency tree (they already are, since these are `dependencies` of this package) and use a bundler that can resolve `require()` calls against node_modules.
domharrington
left a comment
There was a problem hiding this comment.
I think this LGTM! I'm guessing you're not focused on this right now with other things - can I help get this over the line? What else needs to happen with it?
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
💤 Files with no reviewable changes (1)
WalkthroughThe change vendors GraphQL lexer, grammar, parser, indentation, and CodeMirror mode modules locally. CodeMirror loading now registers the local GraphQL mode instead of the external package, while an unused metadata import is removed. The package whitelist is restricted to build outputs, the external GraphQL mode dependency is removed, production minification is enabled, and webpack externalizes non-CSS CodeMirror modules. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)package.jsonTraceback (most recent call last): Comment |
Summary
Stacked on #647 (Phase 1). This is Phase 2 from the same bundle-size plan: semver-major, should not ship until Phase 1 is merged, released, and this has been smoke-tested in the main readme app.
codemirror,react-codemirror2, andprop-typesare already runtimedependencies— every consumer installs them — yet they were also compiled intodist/index.js. That's double-shipping, and it prevented the consumer's own bundler from deduping CodeMirror against any other copy already in their app.externalsinwebpack.config.js(same precedent as the existingreact/react-dom/@readme/variableentries) to covercodemirror,react-codemirror2,prop-types, plus a function external for deep requires (codemirror/mode/*/*,codemirror/addon/*,codemirror/lib/codemirror) — excluding.cssimports, which stay bundled viastyle-loaderso consumers don't need their own CSS handling for ournode_modulesimports.dist/index.node.jsis unaffected —src/index.node.tsonly imports the pure utils, no CodeMirror.Result, on top of Phase 1's ~510 KB / ~158 KB gzip:
The published bundle becomes just ReadMe's own code + CSS. Consumers still load CodeMirror, but exactly one copy, resolved and tree-shaken by their own build.
Test plan
npm test— full vitest suite passes (294 tests)npm run build—dist/index.jsis 47,200 bytes raw / 14,557 bytes gzipnpm pack, installed the tarball into a scratch consumer with realcodemirror/react/prop-types/react-codemirror2deps@readme/syntax-highlighter/browserand bundles it — confirmed the consumer's own webpack resolvescodemirror(907 KB, 41 modules) from its ownnode_modules, proving the externalizedrequire()calls pass through correctlyjsdomand rendered agraphqland ajavascriptsample — output tokenizes identically to Phase 1 /mainNot in scope