decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Fix(#7442): dynamic loading of codemirror language modes

Open fgnass opened this issue 9 months ago • 0 comments

Currently, the code widget does not work properly in ESM builds as it calls require() with a dynamic argument, hence the dynamic loading of language modes is broken (see #7442).

This PR fixes this by using a map of loader functions that use dynamic imports with static paths. The map is generated by the same script that creates the languages.json file.

NOTE: Ideally, we would use https://github.com/codemirror/language-data instead, which internally uses the same approach, but this requires codemirror 6.x which in turn is not supported by react-codemirror2, the wrapper library that is currently used. In the long term switching to https://www.npmjs.com/package/@uiw/react-codemirror would probably make sense, but this would require a huge refactoring.

fgnass avatar Mar 28 '25 15:03 fgnass