Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loading mermaid via esm module #72

Closed
wants to merge 1 commit into from

Conversation

maxbrokman
Copy link

@maxbrokman maxbrokman commented Mar 7, 2023

Fixes #70

Changes

  • Bump default mermaid version to 10.0.2
  • Add support for loading mermaid via an ESM module when requested mermaid version is >= 10
  • Breaking Change: Loading mermaid directly through extra_javascript is no longer possible for version >= 10. This probably requires readme changes not included in this PR. It may be possible for users to include a simple JS file that imports mermaid via esm here instead.

Context

From mermaid v10 onwards mermaid is only distributed as an ESM module. See Mermaid #3590 for discussion on this change.

Users will probably notice this problem if they are following the readme recommended way of loading the latest version of mermaid through extra_javascript as including https://unpkg.com/mermaid/dist/mermaid.min.js resolves to e.g https://unpkg.com/[email protected]/dist/mermaid.min.js which does not exist.

Looking around other projects this seems to be a common issue for libraries including mermaid.

To resolve this mermaid must now be explicitly imported through e.g

<script type="module">
import mermaid from "https://unpkg.com/[email protected]/dist/mermaid.esm.min.mjs"
mermaid.initialize()
</script>

To achieve this this PR makes several changes:

  • Bump default mermaid version to 10.0.2 (latest at time of writing)
  • Split mermaid lib locations constants into pre and post 10 version to account for difference in locations
  • Wrap mermaid lib info in a small value object that also tracks mermaid style (js or esm)
  • Change resolution of mermaid location to make use of the above
  • Change mermaid loader to user <script src="..."> or <script type="module"> as appropriate.

@fralau
Copy link
Owner

fralau commented Mar 7, 2023

Thanks a lot for your contribution.

Could you describe in detail the problem you wanted to solve (what is esm, etc.), and how you solved it?

@fralau fralau added the info needed Further information is requested label Mar 7, 2023
@maxbrokman
Copy link
Author

Ah very sorry @fralau I have sent this to the wrong upstream! Was originally intending to review internally before pushing here but I will update the description shortly

@fralau
Copy link
Owner

fralau commented Mar 7, 2023

Thanks a lot. I believe the right thing to do would be to open an issue to start the discussion and then, when needed the pull request. Looking forward!

@fralau fralau closed this Mar 7, 2023
@maxbrokman
Copy link
Author

@fralau have now provided a description, sorry about that

@fralau fralau reopened this Mar 30, 2023
@fralau
Copy link
Owner

fralau commented Apr 27, 2023

I did my own implementation (to guarantee compatibility with earlier versions). Released in 1.0.0.

@fralau fralau closed this Apr 27, 2023
@flowolf
Copy link

flowolf commented May 25, 2023

this is not yet pushed to pypi - is this planned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info needed Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mermaid 10 is incompatible
3 participants