Skip to content

Conversation

AnujRNair
Copy link
Contributor

Summary

This PR allows a developer to define a custom processFn method to overwrite the default behaviour of inlining the policy into the head of the document we're currently processing.

Covers a request from #44, and an issue raised in #57

Implementation Details

  • Moved the current processing into a defaultProcessFn function, and made it the default behaviour so as to be backwards compatible.
  • Allowed the developer to overwrite this function with a custom function defined in either the CspHtmlWebpackPlugin additionalOpts object, or from the HtmlWebpackPlugin instance cspPlugin object. This can allow for different processing functions per HtmlWebpackPlugin instance
  • Added tests
  • Updated readme

@codecov
Copy link

codecov bot commented Apr 8, 2020

Codecov Report

Merging #58 into master will increase coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   93.85%   94.06%   +0.20%     
==========================================
  Files           2        2              
  Lines         114      118       +4     
  Branches       22       22              
==========================================
+ Hits          107      111       +4     
  Misses          6        6              
  Partials        1        1              
Impacted Files Coverage Δ
plugin.js 92.70% <100.00%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f05fd49...b56efa7. Read the comment docs.

@AnujRNair AnujRNair mentioned this pull request Apr 8, 2020
4 tasks
bcanseco
bcanseco previously approved these changes Apr 8, 2020
Copy link

@bcanseco bcanseco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I like that you included the cheerio object as well.

@fcsonline
Copy link

Awesome! Thanks!

plugin.js Outdated
@@ -18,6 +18,31 @@ try {
}
}

/**
* The default function for adding the CSP to the head of a document
* Can be overwritten to allow the developer can process the CSP in their own way

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Lil typo here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed!

@jasonTheNorris
Copy link

Nice! Give the people what they want! One little nit, but otherwise looks good. +1

Anuj Nair added 2 commits April 9, 2020 09:30
New option in additionalOpts to allow the developer to use the built CSP in any way they want to.
`processFn` can either be defined on the CspHtmlWebpackPlugin, or in individual HtmlWebpackPlugin instances
…the full configuration is not needed to enable this plugin
Copy link

@jasonTheNorris jasonTheNorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇

@AnujRNair AnujRNair merged commit 67426d5 into master Apr 9, 2020
@AnujRNair AnujRNair deleted the an-custom-process-function branch April 9, 2020 16:34
@AnujRNair
Copy link
Contributor Author

I've now merged this and bumped the npm package version - thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants