Skip to content

Commit

Permalink
Add comments per review
Browse files Browse the repository at this point in the history
  • Loading branch information
sersorrel committed May 7, 2021
1 parent ee19fd5 commit df3f1c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,23 @@ class CspHtmlWebpackPlugin {
return compileCb(null, htmlPluginData);
}

// get all nonces for script and style tags
// get all nonces for linked script and style tags
const scriptNonce = this.setNonce($, 'script-src', 'script[src]');
const styleNonce = this.setNonce($, 'style-src', 'link[rel="stylesheet"]');

// get all shas for script and style tags
// get all shas for inline script and style tags
const scriptShas = this.getShas($, 'script-src', 'script:not([src])');
const styleShas = this.getShas($, 'style-src', 'style:not([href])');

// find scripts and styles that were linked to in this HtmlWebpackPlugin instance's output
const includedScripts = $('script[src]')
.map((i, element) => $(element).attr('src'))
.get();
const includedStyles = $('link[rel="stylesheet"]')
.map((i, element) => $(element).attr('href'))
.get();

// get all the shas for scripts and styles generated and linked to by this HtmlWebpackPlugin instance
const linkedScriptShas = this.scriptFilesToHash
.filter((filename) =>
includedScripts.includes(path.join(this.publicPath, filename))
Expand Down
6 changes: 4 additions & 2 deletions test-utils/webpack-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ function webpackCompile(
* Helper to create a basic webpack config which can then be used in the compile function
* @param plugins[] - array of plugins to pass into webpack
* @param {string} publicPath - publicPath setting for webpack
* @param {string} entry - filename of the entrypoint to use
* @param {Object} extraWebpackConfig - extra config to pass to webpack
* @return {{mode: string, output: {path: string, filename: string}, entry: string, plugins: *}}
*/
function createWebpackConfig(
plugins,
publicPath = undefined,
entry = 'index.js',
extra = {}
extraWebpackConfig = {}
) {
return {
mode: 'none',
Expand All @@ -89,7 +91,7 @@ function createWebpackConfig(
filename: 'index.bundle.js',
},
plugins,
...extra,
...extraWebpackConfig,
};
}

Expand Down

0 comments on commit df3f1c9

Please sign in to comment.