fix(example): mount monaco directly instead of react-monaco-editor, cover example in CI - #3
Merged
Merged
Conversation
react-monaco-editor imports `monaco-editor/esm/vs/editor/editor.api`, but
monaco-editor 0.56 added an `exports` map ("./*": "./esm/vs/*.js") that
rewrites that specifier to ./esm/vs/esm/vs/editor/editor.api.js, which the
package does not ship. This broke `yarn build` in ./example, failing the
publish workflow's GitHub Pages deploy. Its latest release (0.59.0) still
peer-depends on monaco-editor ^0.52.0 and has not adapted.
Drop the wrapper and create the editor with monaco.editor.create, importing
through the supported `monaco-editor/editor/editor.api` specifier. Switching
dialects now uses setModelLanguage so the editor's contents are preserved
instead of being remounted.
Also add an `example` job to CI. The example consumes the package via
`file:../`, so it is the only check that exercises the built entry points and
the monaco-editor peer dependency as a real consumer would; previously a break
there was only discovered mid-release. react-scripts runs eslint during a
production build, so the job covers lint and compilation.
Remove the unreferenced CRA boilerplate App.css.
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
yarn buildin./examplefails, which breaks the GitHub Pages deploy at the end of the publish workflow:react-monaco-editordoesimport * as monaco from "monaco-editor/esm/vs/editor/editor.api", but monaco-editor 0.56 added anexportsmap:That rewrites the old specifier to
./esm/vs/esm/vs/editor/editor.api.js, which the package doesn't ship. This is upstream fallout from the monaco 0.56 upgrade in 1d50b6a —react-monaco-editor's latest release (0.59.0) still peer-depends onmonaco-editor@^0.52.0and hasn't adapted, so there's no version to upgrade to.Changes
Drop
react-monaco-editorand mount the editor directly withmonaco.editor.create, importing via the supportedmonaco-editor/editor/editor.apispecifier.monaco.editor.setModelLanguageon the existing model, so the editor's contents survive a dialect change (previously the wrapper remounted with reset state).MonacoEnvironment.getWorkeris set inindex.js; without it monaco tries to load its editor worker from a CDN-style absolute path that doesn't exist here. webpack 5 bundles the worker from thenew URL(..., import.meta.url)form.example/src/App.css— unreferenced CRA boilerplate (spinning-logo styles).Add an
examplejob to CI. The example consumes the package throughfile:../, so it's the only check that exercises the built entry points and themonaco-editorpeer dependency the way a real consumer does. The publish workflow builds it to deploy Pages, so without this job a break is only discovered mid-release — which is exactly what happened here.react-scriptsruns eslint as part of a production build, so the job covers lint and compilation.Verification
yarn lint,yarn test(228 passed), andyarn buildpass at the root;yarn install --frozen-lockfile+yarn buildpass in./example, all from a clean clone of this branch.pgsql, which lazy-loads from monaco's own language definitions.WHERE created_at > now()via real keyboard events and checking the resulting tokens.MonacoEnvironment.getWorkerand watching forerror/messageerrorplus the extra chunk fetch.yarn startcompiles successfully.examplejob fail with the original error.Note
The 117 Dependabot alerts on this repo are pre-existing (mostly
react-scripts5.0.1's transitive dev deps) and out of scope here.