chore(package.json): add purify.js
and purify.min.js
to exports as targetable modules
#1053
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.
Summary
This PR is per discussions had in the issue:
Adds
purify.js
and minifiedpurify.min.js
to the package.json exports field, allowing for each script to be called as it was prior to DOMPurify v3.2.0.DOMPurify was migrated over to utilizing exports in commit
faf296da9b412d93023dde1c8f86599cb7b13beb
and is provided in the link below:DOMPurify v3.1.7 is the last version that utilized the old
main
field withoutexports
.This PR simply allows for the above two files to be targeted. The new entries were added as their own named exports, and do not override the defaults configured by DOMPurify; so existing users will have no issues after updating, all imports will remain the same.
Tested this on both a project utilizing webpack (all existing DOMPurify calls continued to work as normal), and also tested on a new project not utilizing Webpack, and only using the existing exports and all functionality continued to work.
As we know,
exports
was introduced in Nodev12.7.0
as a succession to the oldermain
functionality, allowing developers to control that aspects of a library can be called.With the edits made in the PR, webpack behaves as it originally did where each file can now be targeted and loaded when desired.
Background & Context
At present, using DOMpurify in combination with webpack 5. To control the dev and production environment, being able to use an alias, and to decide when to minify and when to not, we would need access to each of the two files individually.
Without this change, webpack does not build, and throws a failure error:
To temporarily circumvent this issue, we had to do away with calling the uncompressed and minified files all-together, which means we cannot specify which files get minified and which ones do not.
According to the webpack documentation, webpack has a way to ignore the export fields by defining
exportsFields: []
in thewebpack.config.js
file, but it is global only. It cannot be controlled based on each alias. You either get all or nothing. And that would kill many other packages using exports.Webpack's documentation makes note of the behavior it takes in regards to exports:
At the time of writing this, I am currently on webpack
5.97.1
.Tasks
DOMPurify.sanitize
)For webpack users, they can configure DOMPurify as a normal alias within
webpack.config.js
Dependencies