cure53 / DOMPurify

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
https://cure53.de/purify
Other
13.67k stars 698 forks source link

chore: packagejson conditional exports #874

Closed ssi02014 closed 10 months ago

ssi02014 commented 10 months ago

Summary

@cure53 👋 Even if you currently import DOMPurify with import, it will import files in umd format.

// react env
import DOMPurify from "dompurify";

스크린샷 2023-11-09 오후 11 35 33

We can apply Conditional Exports so that we get files in esm format when importing with import, and files in cjs format when importing with require.

Reference

https://nodejs.org/api/packages.html#conditional-exports https://nodejs.org/api/packages.html#dual-commonjses-module-packages

Also, why not change it to a .mjs file extension to make it clear that it is an esm format?


It seems like a lot of file changes, but I reinstalled the dependencies and built, and there are differences like line breaks. 😂

스크린샷 2023-11-09 오후 11 43 45

cure53 commented 10 months ago

Oh, nice, thanks! Just wondering for version purposes, will this break things for folks after a release?

ssi02014 commented 10 months ago

@cure53 I don't think this changes much !

If you use import, you'll get "./node_modules/dompurify/dist/purify.es.mjs", and if you use require, you'll get "./node_modules/dompurify/dist/purify.cjs.js".

If the build files we provide are good, then everything should be fine.

cure53 commented 10 months ago

Awesome, thank you very much :bow: :smile: