├── examples ├── disabled │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── hwp-public-path │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── non-web-build │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── warn-hot-reload │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── dynamic-named-chunks │ ├── chunk.js │ ├── README.md │ ├── package.json │ ├── webpack.config.js │ └── index.js ├── electron-renderer │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── hwp-subdirectories │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── hwp-output-parent-dir │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── multiple-common-chunks │ ├── pageA.js │ ├── pageB.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── basic │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── dll-plugin │ ├── a.js │ ├── b.js │ ├── c.jsx │ ├── alpha.js │ ├── beta.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── hwp-basic │ ├── index.js │ ├── package.json │ └── webpack.config.js ├── issue-147 │ ├── async.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── issue-152 │ ├── index.js │ ├── package.json │ ├── en.json │ └── webpack.config.js ├── issue-221 │ ├── index.js │ ├── package.json │ └── webpack.config.js ├── lazy-e2e │ ├── index.js │ ├── nested1.js │ ├── nested2.js │ ├── package.json │ └── webpack.config.js ├── no-warn-filename │ ├── b.js │ ├── README.md │ ├── a.js │ ├── package.json │ └── webpack.config.js ├── webpack-fix-style-only-entries │ ├── style.css │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── hwp-externals │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── lazy-modified │ ├── index.js │ ├── corrupt.js │ ├── README.md │ ├── nested.js │ ├── package.json │ └── webpack.config.js ├── minimal-sri-hashes │ ├── lazy.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── terser-banner │ ├── index.js │ ├── package.json │ └── webpack.config.js ├── webpack4-contenthash │ ├── chunk.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── no-error-invalid-config │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── webpack-assets-manifest │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── webpack-preload │ ├── index.js │ ├── README.md │ ├── lazy-chunk-1.js │ ├── package.json │ ├── lazy-chunk-2.js │ └── webpack.config.js ├── hwp-custom-template │ ├── index.js │ ├── stylesheet.css │ ├── README.md │ ├── package.json │ ├── index.ejs │ └── webpack.config.js ├── issue-154 │ ├── style.css │ ├── index.js │ ├── package.json │ └── webpack.config.js ├── webpack4-contenthash-issue-83 │ ├── chunk.js │ ├── index.js │ ├── README.md │ ├── index.css │ ├── package.json │ └── webpack.config.js ├── lazy-hashes-simple │ ├── 2.js │ ├── index.js │ ├── 1.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── dynamic-modified │ ├── corrupt.js │ ├── README.md │ ├── index.js │ ├── package.json │ └── webpack.config.js ├── sourcemap-code-splitting │ ├── 1.js │ ├── 2.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── lazy-hashes-cycles │ ├── leaf.js │ ├── 2.js │ ├── 3.js │ ├── index.js │ ├── 1.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── lazy-hashes-group │ ├── grouped1.js │ ├── grouped2.js │ ├── index.js │ ├── README.md │ ├── inter.js │ ├── package.json │ └── webpack.config.js ├── lazy-hashes-multiple-parents │ ├── leaf.js │ ├── 1.js │ ├── 2.js │ ├── index.js │ ├── README.md │ ├── package.json │ └── webpack.config.js ├── mini-css-extract-plugin │ ├── style.module.css │ ├── index.js │ ├── package.json │ └── webpack.config.js └── mutually-dependent-chunks │ ├── README.md │ ├── chunk1.js │ ├── chunk2.js │ ├── chunk3.js │ ├── main.js │ ├── package.json │ └── webpack.config.js ├── wsi-test-helper ├── .gitignore ├── .dir-locals.el ├── tsconfig.json ├── package.json └── index.ts ├── smoke-test ├── .yarnrc.yml ├── src │ ├── index.js │ └── chunk.js ├── .gitignore ├── README.md ├── package.json └── webpack.config.js ├── .prettierignore ├── webpack-subresource-integrity ├── src │ ├── __tests__ │ │ ├── __fixtures__ │ │ │ ├── unresolved │ │ │ │ └── src │ │ │ │ │ └── index.js │ │ │ └── simple-project │ │ │ │ └── src │ │ │ │ └── index.js │ │ ├── hwp-error.test.ts │ │ ├── test-utils.ts │ │ ├── examples.test.ts │ │ └── integration.test.ts │ ├── __mocks__ │ │ └── html-webpack-plugin.js │ ├── globals.ts │ ├── integrity.ts │ ├── types.ts │ ├── hooks.ts │ ├── reporter.ts │ ├── scc.ts │ ├── manifest.ts │ ├── util.ts │ ├── index.ts │ └── plugin.ts ├── tsconfig.json ├── .nycrc ├── tsconfig-mjs.json ├── jest.config.js ├── tsconfig-base.json ├── etc │ └── webpack-subresource-integrity.api.md ├── LICENSE └── package.json ├── .eslintignore ├── CHANGELOG.md ├── .vscode └── settings.json ├── .gitignore ├── nyc-apply-source-map ├── package.json └── index.js ├── .yarnrc.yml ├── .codeclimate.yml ├── LICENSE ├── .eslintrc.js ├── .github └── workflows │ ├── compat.yml │ ├── publish.yml │ └── test.yml ├── package.json ├── README.md └── MIGRATE-v1-to-v5.md /examples/disabled/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hwp-public-path/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/non-web-build/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/warn-hot-reload/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/dynamic-named-chunks/chunk.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/electron-renderer/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hwp-subdirectories/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hwp-output-parent-dir/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/multiple-common-chunks/pageA.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/multiple-common-chunks/pageB.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/basic/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/dll-plugin/a.js: -------------------------------------------------------------------------------- 1 | module.exports = "a"; 2 | -------------------------------------------------------------------------------- /examples/dll-plugin/b.js: -------------------------------------------------------------------------------- 1 | module.exports = "b"; 2 | -------------------------------------------------------------------------------- /examples/dll-plugin/c.jsx: -------------------------------------------------------------------------------- 1 | module.exports = 'ok'; 2 | -------------------------------------------------------------------------------- /examples/hwp-basic/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/issue-147/async.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/issue-147/index.js: -------------------------------------------------------------------------------- 1 | import("./async"); 2 | -------------------------------------------------------------------------------- /examples/issue-152/index.js: -------------------------------------------------------------------------------- 1 | require("./en.json"); 2 | -------------------------------------------------------------------------------- /examples/issue-221/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/lazy-e2e/index.js: -------------------------------------------------------------------------------- 1 | import("./nested1"); 2 | -------------------------------------------------------------------------------- /examples/lazy-e2e/nested1.js: -------------------------------------------------------------------------------- 1 | import("./nested2"); 2 | -------------------------------------------------------------------------------- /examples/lazy-e2e/nested2.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/no-warn-filename/b.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/webpack-fix-style-only-entries/style.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/dll-plugin/alpha.js: -------------------------------------------------------------------------------- 1 | module.exports = "alpha"; 2 | -------------------------------------------------------------------------------- /examples/dll-plugin/beta.js: -------------------------------------------------------------------------------- 1 | module.exports = "beta"; 2 | -------------------------------------------------------------------------------- /examples/hwp-externals/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/lazy-modified/index.js: -------------------------------------------------------------------------------- 1 | import("./nested"); 2 | -------------------------------------------------------------------------------- /examples/minimal-sri-hashes/lazy.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/terser-banner/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /wsi-test-helper/.gitignore: -------------------------------------------------------------------------------- 1 | index.js 2 | index.js.map 3 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash/chunk.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/no-error-invalid-config/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/webpack-assets-manifest/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/webpack-preload/index.js: -------------------------------------------------------------------------------- 1 | import("./lazy-chunk-1.js"); 2 | -------------------------------------------------------------------------------- /examples/hwp-custom-template/index.js: -------------------------------------------------------------------------------- 1 | require("./stylesheet.css"); 2 | -------------------------------------------------------------------------------- /examples/issue-154/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: red; 3 | } 4 | -------------------------------------------------------------------------------- /examples/webpack-fix-style-only-entries/index.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash-issue-83/chunk.js: -------------------------------------------------------------------------------- 1 | console.log("ok"); 2 | -------------------------------------------------------------------------------- /smoke-test/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | yarnPath: ../.yarn/releases/yarn-3.4.1.cjs 2 | -------------------------------------------------------------------------------- /smoke-test/src/index.js: -------------------------------------------------------------------------------- 1 | import("./chunk").then(({ func }) => func()); 2 | -------------------------------------------------------------------------------- /examples/lazy-hashes-simple/2.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: 2, 3 | }; 4 | -------------------------------------------------------------------------------- /examples/lazy-modified/corrupt.js: -------------------------------------------------------------------------------- 1 | console.log("this should never load"); 2 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash-issue-83/index.js: -------------------------------------------------------------------------------- 1 | require("./index.css"); 2 | -------------------------------------------------------------------------------- /examples/dynamic-modified/corrupt.js: -------------------------------------------------------------------------------- 1 | console.log("this should never load"); 2 | -------------------------------------------------------------------------------- /examples/lazy-hashes-simple/index.js: -------------------------------------------------------------------------------- 1 | import("./1.js"); 2 | console.log("ok"); 3 | -------------------------------------------------------------------------------- /examples/no-warn-filename/README.md: -------------------------------------------------------------------------------- 1 | # No warning for complex filename templates 2 | -------------------------------------------------------------------------------- /examples/sourcemap-code-splitting/1.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: 1, 3 | }; 4 | -------------------------------------------------------------------------------- /examples/sourcemap-code-splitting/2.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: 2, 3 | }; 4 | -------------------------------------------------------------------------------- /smoke-test/src/chunk.js: -------------------------------------------------------------------------------- 1 | export function func() { 2 | console.log("ok"); 3 | } 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/leaf.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: "leaf", 3 | }; 4 | -------------------------------------------------------------------------------- /examples/no-error-invalid-config/README.md: -------------------------------------------------------------------------------- 1 | # No exception when config is invalid 2 | -------------------------------------------------------------------------------- /smoke-test/.gitignore: -------------------------------------------------------------------------------- 1 | /webpack-subresource-integrity.tgz 2 | /yarn.lock 3 | /.yarn 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/grouped1.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: "grouped1", 3 | }; 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/grouped2.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: "grouped2", 3 | }; 4 | -------------------------------------------------------------------------------- /examples/minimal-sri-hashes/index.js: -------------------------------------------------------------------------------- 1 | import(/* webpackChunkName: "lazyB" */ "./lazy.js"); 2 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/2.js: -------------------------------------------------------------------------------- 1 | import("./3.js"); 2 | export default { 3 | chunk: 2, 4 | }; 5 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/3.js: -------------------------------------------------------------------------------- 1 | import("./1.js"); 2 | export default { 3 | chunk: 3, 4 | }; 5 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/leaf.js: -------------------------------------------------------------------------------- 1 | export default { 2 | chunk: "leaf", 3 | }; 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-simple/1.js: -------------------------------------------------------------------------------- 1 | import("./2.js"); 2 | export default { 3 | chunk: 1, 4 | }; 5 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash-issue-83/README.md: -------------------------------------------------------------------------------- 1 | # Issue 83 2 | 3 | Test case for issue #83 4 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash-issue-83/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: red; 3 | } 4 | -------------------------------------------------------------------------------- /examples/hwp-externals/README.md: -------------------------------------------------------------------------------- 1 | # HtmlWebpackExternalsPlugin #hwp 2 | 3 | Test case for issue #97 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/index.js: -------------------------------------------------------------------------------- 1 | import("./1.js"); 2 | import("./2.js"); 3 | console.log("ok"); 4 | -------------------------------------------------------------------------------- /examples/multiple-common-chunks/README.md: -------------------------------------------------------------------------------- 1 | # Multiple Common Chunks 2 | 3 | Test case for issue #58 4 | -------------------------------------------------------------------------------- /examples/hwp-custom-template/stylesheet.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: rgb(200, 201, 202); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /examples/hwp-public-path/README.md: -------------------------------------------------------------------------------- 1 | # HtmlWebpackPlugin and publicPath #hwp 2 | 3 | Test case for issue #11 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/1.js: -------------------------------------------------------------------------------- 1 | import("./leaf.js"); 2 | export default { 3 | chunk: 1, 4 | }; 5 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/2.js: -------------------------------------------------------------------------------- 1 | import("./leaf.js"); 2 | export default { 3 | chunk: 2, 4 | }; 5 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/index.js: -------------------------------------------------------------------------------- 1 | import("./1.js"); 2 | import("./2.js"); 3 | console.log("ok"); 4 | -------------------------------------------------------------------------------- /examples/mini-css-extract-plugin/style.module.css: -------------------------------------------------------------------------------- 1 | body { background: red; } 2 | 3 | .test { color: green } 4 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/README.md: -------------------------------------------------------------------------------- 1 | # Mutually Dependent Chunks 2 | 3 | Test case for issue #37 4 | -------------------------------------------------------------------------------- /examples/sourcemap-code-splitting/index.js: -------------------------------------------------------------------------------- 1 | import("./1.js"); 2 | import("./2.js"); 3 | console.log("ok"); 4 | -------------------------------------------------------------------------------- /examples/warn-hot-reload/README.md: -------------------------------------------------------------------------------- 1 | # Warning when Used with Hot Reloading 2 | 3 | Test case for issue #46 4 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash/index.js: -------------------------------------------------------------------------------- 1 | require.ensure([], (require) => { 2 | require("./chunk.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/index.js: -------------------------------------------------------------------------------- 1 | import(/* webpackChunkName: "inter" */ "./inter.js"); 2 | console.log("ok"); 3 | -------------------------------------------------------------------------------- /examples/lazy-hashes-simple/README.md: -------------------------------------------------------------------------------- 1 | # Sourcemap and code splitting 2 | 3 | Simple test case for lazy hashes 4 | -------------------------------------------------------------------------------- /examples/hwp-custom-template/README.md: -------------------------------------------------------------------------------- 1 | # HtmlWebpackPlugin and Custom Template #hwp 2 | 3 | Test case for issue #13 4 | -------------------------------------------------------------------------------- /examples/hwp-subdirectories/README.md: -------------------------------------------------------------------------------- 1 | # HtmlWebpackPlugin and Sub-Directories #hwp 2 | 3 | Test case for issue #9 4 | 5 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/1.js: -------------------------------------------------------------------------------- 1 | import("./2.js"); 2 | import("./leaf.js"); 3 | export default { 4 | chunk: 1, 5 | }; 6 | -------------------------------------------------------------------------------- /examples/minimal-sri-hashes/README.md: -------------------------------------------------------------------------------- 1 | # Ensure no superfluous SRI hashes are included 2 | 3 | Test case for issue #101 4 | -------------------------------------------------------------------------------- /examples/no-warn-filename/a.js: -------------------------------------------------------------------------------- 1 | require.ensure([], function requireEnsure(require) { 2 | require("./b.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .pnp.js 2 | *.d.ts 3 | coverage/ 4 | dist/ 5 | webpack-subresource-integrity/*.js 6 | wsi-test-helper/*.js 7 | -------------------------------------------------------------------------------- /examples/basic/README.md: -------------------------------------------------------------------------------- 1 | # With HtmlWebpackPlugin #hwp 2 | 3 | This is a most basic test for use with HtmlWebpackPlugin 4 | -------------------------------------------------------------------------------- /examples/non-web-build/README.md: -------------------------------------------------------------------------------- 1 | # Non-Web build 2 | 3 | Ensure the plugin doesn't crash in a build for a non-web target. 4 | -------------------------------------------------------------------------------- /examples/webpack-fix-style-only-entries/README.md: -------------------------------------------------------------------------------- 1 | # With webpack-fix-style-only-entries 2 | 3 | Test case for issue #106 4 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/__tests__/__fixtures__/unresolved/src/index.js: -------------------------------------------------------------------------------- 1 | console.log("*-*-*-CHUNK-SRI-HASH-foo"); 2 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/README.md: -------------------------------------------------------------------------------- 1 | # Lazy hashes and chunk groups 2 | 3 | Simple test case for lazy hashes with chunk groups 4 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/chunk1.js: -------------------------------------------------------------------------------- 1 | require.ensure([], function ensured(require) { 2 | require("./chunk2.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/chunk2.js: -------------------------------------------------------------------------------- 1 | require.ensure([], function ensured(require) { 2 | require("./chunk3.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/chunk3.js: -------------------------------------------------------------------------------- 1 | require.ensure([], function ensured(require) { 2 | require("./chunk1.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/main.js: -------------------------------------------------------------------------------- 1 | require.ensure([], function ensured(require) { 2 | require("./chunk1.js"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/sourcemap-code-splitting/README.md: -------------------------------------------------------------------------------- 1 | # Sourcemap and code splitting 2 | 3 | Test case for sourcemap and code splitting 4 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash/README.md: -------------------------------------------------------------------------------- 1 | # Ensure contenthash path variable works in Webpack 4.3+ 2 | 3 | Test case for issue #78 4 | -------------------------------------------------------------------------------- /wsi-test-helper/.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((typescript-mode . ((tide-tsserver-executable . "../node_modules/typescript/bin/tsserver")))) 2 | -------------------------------------------------------------------------------- /examples/electron-renderer/README.md: -------------------------------------------------------------------------------- 1 | # Electron Renderer target 2 | 3 | Ensure the plugin doesn't warn for electron-renderer targets. 4 | -------------------------------------------------------------------------------- /examples/hwp-output-parent-dir/README.md: -------------------------------------------------------------------------------- 1 | # HtmlWebpackPlugin and Output into Parent Directory #hwp 2 | 3 | Test case for issue #15 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/README.md: -------------------------------------------------------------------------------- 1 | # Sourcemap and code splitting 2 | 3 | Test case for sourcemap and code splitting 4 | -------------------------------------------------------------------------------- /examples/dll-plugin/index.js: -------------------------------------------------------------------------------- 1 | console.log(require("beta/beta")); 2 | console.log(require("beta/b")); 3 | console.log(require("beta/c.jsx")); 4 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/README.md: -------------------------------------------------------------------------------- 1 | # Sourcemap and code splitting 2 | 3 | Test case for lazy hashes where there is a chunk dependency cycle 4 | -------------------------------------------------------------------------------- /examples/dynamic-modified/README.md: -------------------------------------------------------------------------------- 1 | # With a modified dynamically loaded chunk #hwp 2 | 3 | Ensure that when a chunk is modified, it fails to load. 4 | -------------------------------------------------------------------------------- /examples/webpack-preload/README.md: -------------------------------------------------------------------------------- 1 | # With `/* webpackPreload: "true" */` 2 | 3 | https://github.com/waysact/webpack-subresource-integrity/issues/111 4 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/__tests__/__fixtures__/simple-project/src/index.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-console 2 | console.log("ok"); 3 | -------------------------------------------------------------------------------- /examples/mini-css-extract-plugin/index.js: -------------------------------------------------------------------------------- 1 | import("./style.module.css").then((module) => { 2 | console.log(module["default"] ? "ok" : "error"); 3 | }); 4 | -------------------------------------------------------------------------------- /examples/dll-plugin/README.md: -------------------------------------------------------------------------------- 1 | # DllPlugin Integration #hwp 2 | 3 | Demonstrates how assets generated by DllPlugin can be included with 4 | SRI using html-webpack-plugin. 5 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/__mocks__/html-webpack-plugin.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | get getHooks() { 3 | throw new Error("bogus hwp accessed"); 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /examples/webpack-preload/lazy-chunk-1.js: -------------------------------------------------------------------------------- 1 | setTimeout(() => { 2 | import(/* webpackPreload: true */ "./lazy-chunk-2.js").then((mod) => 3 | mod.test() 4 | ); 5 | }, 750); 6 | -------------------------------------------------------------------------------- /examples/disabled/README.md: -------------------------------------------------------------------------------- 1 | # Plugin Disabled 2 | 3 | Simple example showing that webpack-subresource-integrity doesn't add 4 | an integrity checksum when `enabled` is set to `false`. 5 | -------------------------------------------------------------------------------- /examples/issue-147/README.md: -------------------------------------------------------------------------------- 1 | # Doesn't throw error when a processed tag has no attributes #hwp 2 | 3 | Test for https://github.com/waysact/webpack-subresource-integrity/issues/147 4 | -------------------------------------------------------------------------------- /examples/dynamic-modified/index.js: -------------------------------------------------------------------------------- 1 | import("./corrupt") 2 | .then(function error() { 3 | console.log("error"); 4 | }) 5 | .catch(function ok() { 6 | console.log("ok"); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/dynamic-named-chunks/README.md: -------------------------------------------------------------------------------- 1 | # With a dynamically loaded, named chunk #hwp 2 | 3 | Ensure that when a named chunk is loaded dynamically with Webpack 5, 4 | it receives a SRI hash. 5 | -------------------------------------------------------------------------------- /examples/lazy-modified/README.md: -------------------------------------------------------------------------------- 1 | # With lazy hashes and a modified dynamically loaded chunk #hwp 2 | 3 | Ensure that when a chunk is modified, it fails to load when hashes are 4 | lazy-loaded. 5 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # don't ever lint node_modules 2 | node_modules 3 | # don't lint build output (make sure it's set to your correct build folder name) 4 | dist 5 | # don't lint nyc coverage output 6 | coverage 7 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/inter.js: -------------------------------------------------------------------------------- 1 | import(/* webpackChunkName: "grouped1" */ "./grouped1.js"); 2 | import(/* webpackChunkName: "grouped2" */ "./grouped2.js"); 3 | export default { 4 | chunk: "inter", 5 | }; 6 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-base.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "outDir": "dist/cjs", 6 | "target": "es2015" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "include": ["dist/cjs/*.js"], 4 | "exclude": ["*.test.js", ".pnp.js"], 5 | "cache": false, 6 | "source-map": false, 7 | "sourceMap": false 8 | } 9 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/tsconfig-mjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-base.json", 3 | "compilerOptions": { 4 | "module": "esnext", 5 | "outDir": "dist/mjs", 6 | "target": "esnext" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/lazy-modified/nested.js: -------------------------------------------------------------------------------- 1 | import(/* webpackChunkName: "corrupt" */ "./corrupt") 2 | .then(function error() { 3 | console.log("error"); 4 | }) 5 | .catch(function ok() { 6 | console.log("ok"); 7 | }); 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | Every release is documented on the Github [Releases](https://github.com/waysact/webpack-subresource-integrity/releases) page. 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "search.exclude": { 3 | "**/.yarn": true, 4 | "**/.pnp.*": true 5 | }, 6 | "prettier.prettierPath": ".yarn/sdks/prettier/index.js", 7 | "typescript.tsdk": ".yarn/sdks/typescript/lib", 8 | "typescript.enablePromptUseWorkspaceTsdk": true 9 | } 10 | -------------------------------------------------------------------------------- /wsi-test-helper/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node12/tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "declarationMap": true, 6 | "noEmitOnError": true, 7 | "sourceMap": true, 8 | "strict": true, 9 | "outDir": "dist" 10 | }, 11 | "files": ["index.ts"] 12 | } 13 | -------------------------------------------------------------------------------- /examples/issue-154/index.js: -------------------------------------------------------------------------------- 1 | import "./style.css"; 2 | 3 | window.addEventListener("load", () => { 4 | const { integrity } = document.querySelector("link"); 5 | const loaded = getComputedStyle(document.body).background.match( 6 | /rgb\(255, 0, 0\)/ 7 | ); 8 | 9 | console.log(integrity && loaded ? "ok" : "error"); 10 | }); 11 | -------------------------------------------------------------------------------- /examples/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basic", 3 | "description": "Basic test", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /smoke-test/README.md: -------------------------------------------------------------------------------- 1 | # Smoke Test 2 | 3 | This directory contains a simple smoke test. It checks that with SRI enabled, a 4 | simple page still loads, and that it fails to load when its assets get 5 | corrupted. 6 | 7 | The test is meant to run against a packaged version of the plugin, rather than 8 | the source tree. See Yarn script "test:smoke" in the root directory. 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .nyc_output/ 3 | .nyc_merged/ 4 | coverage/ 5 | coverage.json 6 | examples/**/dist/ 7 | smoke-test/dist/ 8 | webpack-subresource-integrity/dist/ 9 | !webpack-subresource-integrity/dist/**/package.json 10 | yarn-error.log 11 | \*.map 12 | .yarn/* 13 | !.yarn/releases 14 | !.yarn/plugins 15 | .pnp.* 16 | temp/ 17 | tsdoc-metadata.json 18 | *.d.ts 19 | *.d.ts.map 20 | package.tgz 21 | .log/ 22 | -------------------------------------------------------------------------------- /examples/hwp-basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-basic", 3 | "description": "Basic test with html-webpack-plugin", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/webpack-preload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-preload", 3 | "description": "Test case for issue #111", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/lazy-e2e/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-e2e", 3 | "description": "Basic end-to-end test with lazy-loaded hashes", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack4-contenthash", 3 | "description": "Test case for issue #78", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/issue-152/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "issue-152", 3 | "description": "Test case for https://github.com/waysact/webpack-subresource-integrity/issues/152", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "nyc": "*", 10 | "webpack": "5.24.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/dynamic-modified/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamic-modified", 3 | "description": "Ensure that when a chunk is modified, it fails to load.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/warn-hot-reload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "warn-hot-reload", 3 | "description": "Test case for issue #46", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/minimal-sri-hashes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimal-sri-hashes", 3 | "description": "Test case for issue #101", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/globals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Waysact Pty Ltd 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | export const thisPluginName = "webpack-subresource-integrity"; 9 | 10 | // https://www.w3.org/TR/2016/REC-SRI-20160623/#cryptographic-hash-functions 11 | export const standardHashFuncNames = ["sha256", "sha384", "sha512"]; 12 | -------------------------------------------------------------------------------- /examples/issue-221/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "issue-221", 3 | "description": "Test case for https://github.com/waysact/webpack-subresource-integrity/issues/221", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/multiple-common-chunks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multiple-common-chunks", 3 | "description": "Test case for issue #58", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nyc-apply-source-map/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nyc-apply-source-map", 3 | "version": "1.0.0", 4 | "description": "Utility for applying a source map to a set of coverage reports", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "private": true, 8 | "devDependencies": { 9 | "glob": "^7.2.0", 10 | "glob-promise": "^4.2.2", 11 | "istanbul-lib-coverage": "^3.2.0", 12 | "istanbul-lib-source-maps": "^4.0.1", 13 | "source-map": "^0.7.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/lazy-hashes-simple/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-hashes-simple", 3 | "description": "Simple test case for lazy hashes", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mutually-dependent-chunks", 3 | "description": "Test case for issue #37", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/no-warn-filename/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-warn-filename", 3 | "description": "No warning for complex filename templates", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/issue-147/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "issue-147", 3 | "description": "Test for https://github.com/waysact/webpack-subresource-integrity/issues/147", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": "^5.0.0-beta.6", 9 | "nyc": "*", 10 | "script-ext-html-webpack-plugin": "^2.1.5", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "*", 13 | "webpack-subresource-integrity": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/lazy-modified/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-modified", 3 | "description": "Ensure that when a chunk is modified, it fails to load when hashes are lazy-loaded.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/no-error-invalid-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-error-invalid-config", 3 | "description": "No exception when config is invalid", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/webpack-assets-manifest/README.md: -------------------------------------------------------------------------------- 1 | # Integration with webpack-assets-manifest 2 | 3 | [webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest) 4 | has a somewhat 5 | [undocumented feature](https://github.com/webdeveric/webpack-assets-manifest/blob/9261b516209ece4311b77f200b78ff5dc945985f/src/WebpackAssetsManifest.js#L448-L449) 6 | where it will include the `integrity` value generated by this plugin 7 | (by webpack-subresource-integrity) when configured with `integrity: true`. 8 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | packageExtensions: 2 | fastify-static@*: 3 | peerDependencies: 4 | fastify: "*" 5 | html-webpack-include-assets-plugin@*: 6 | peerDependencies: 7 | html-webpack-plugin: "*" 8 | webpack@*: 9 | dependencies: 10 | "@types/json-schema": "*" 11 | 12 | plugins: 13 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 14 | spec: "@yarnpkg/plugin-interactive-tools" 15 | 16 | yarnPath: .yarn/releases/yarn-3.4.1.cjs 17 | 18 | nodeLinker: node-modules 19 | -------------------------------------------------------------------------------- /examples/lazy-hashes-group/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-hashes-group", 3 | "description": "Simple test case for lazy hashes and chunk groups", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/non-web-build/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "non-web-build", 3 | "description": "Ensure the plugin doesn't crash in a build for a non-web target", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/sourcemap-code-splitting/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourcemap-code-splitting", 3 | "description": "Test case for sourcemap and code splitting", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/electron-renderer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-renderer", 3 | "description": "Ensure the plugin doesn't warn for electron-renderer targets.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/terser-banner/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "terser-banner", 3 | "description": "Ensure integrity works with terser-webpack-plugin banners", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "terser-webpack-plugin": "^5.1.4", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/dynamic-named-chunks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamic-named-chunks", 3 | "description": "Ensure that when a named chunk is loaded dynamically with Webpack 5, it receives a SRI hash.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "html-webpack-plugin": ">= 5.0.0-beta.1", 9 | "nyc": "*", 10 | "webpack": "^5.44.0", 11 | "webpack-cli": "4", 12 | "webpack-subresource-integrity": "*", 13 | "wsi-test-helper": "*" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/lazy-hashes-cycles/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-hashes-cycles", 3 | "description": "Test case for lazy hashes where there is a chunk dependency cycle", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: "ts-jest", 3 | testEnvironment: "node", 4 | coverageReporters: ["json"], 5 | automock: false, 6 | coveragePathIgnorePatterns: [ 7 | "/node_modules/", 8 | "test-utils", 9 | ".yarn/cache", 10 | ".pnp.cjs", 11 | ], 12 | rootDir: "src", 13 | testMatch: [ 14 | "**/__tests__/**/*.[jt]s?(x)", 15 | "**/?(*.)+(spec|test).[jt]s?(x)", 16 | "!**/__fixtures__/**", 17 | "!**/test-utils.[jt]s?(x)", 18 | ], 19 | }; 20 | -------------------------------------------------------------------------------- /examples/lazy-hashes-multiple-parents/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazy-hashes-multiple-parents", 3 | "description": "Test case for lazy hashes where a chunk has multiple parents", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/hwp-public-path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-public-path", 3 | "description": "Test case for issue #11", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-select": "^5.1.0", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "htmlparser2": "^8.0.1", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-cli": "4", 15 | "webpack-subresource-integrity": "*", 16 | "wsi-test-helper": "*" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/webpack-preload/lazy-chunk-2.js: -------------------------------------------------------------------------------- 1 | module.exports.test = () => { 2 | const linkTag = Array.from(document.getElementsByTagName("link")).find( 3 | (el) => el.rel === "preload" 4 | ); 5 | const scriptTag = Array.from(document.getElementsByTagName("script")).find( 6 | (el) => linkTag && el.src === linkTag.href 7 | ); 8 | console.log( 9 | scriptTag && 10 | linkTag && 11 | scriptTag.integrity && 12 | scriptTag.integrity === linkTag.integrity 13 | ? "ok" 14 | : "error" 15 | ); 16 | }; 17 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | engines: 3 | eslint: 4 | enabled: true 5 | ratings: 6 | paths: ["webpack-subresource-integrity/src/*.ts"] 7 | exclude_patterns: 8 | - "node_modules/" 9 | - "examples/" 10 | - "smoke-test/" 11 | - ".git/" 12 | - ".github/" 13 | - ".yarn/" 14 | - ".nyc_merged/" 15 | - ".nyc_output/" 16 | - "**/coverage/" 17 | - "**/dist/" 18 | - "**/temp/" 19 | - "**/*.js" 20 | - "**/*.cjs" 21 | - "**/*.d.ts" 22 | - "**/*.map" 23 | - "**/*.tgz" 24 | - "**/.log" 25 | - "**/.eslintrc.js" 26 | -------------------------------------------------------------------------------- /examples/hwp-subdirectories/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-subdirectories", 3 | "description": "Test case for issue #9", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-select": "^5.1.0", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "htmlparser2": "^8.0.1", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-cli": "4", 15 | "webpack-subresource-integrity": "*", 16 | "wsi-test-helper": "*" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/hwp-output-parent-dir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-output-parent-dir", 3 | "description": "Test case for issue #15", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-select": "^5.1.0", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "htmlparser2": "^8.0.1", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-cli": "4", 15 | "webpack-subresource-integrity": "*", 16 | "wsi-test-helper": "*" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/disabled/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "disabled", 3 | "description": "Simple example showing that webpack-subresource-integrity doesn't add an integrity checksum when `enabled` is set to `false`.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-cli": "4", 13 | "webpack-subresource-integrity": "*", 14 | "wsi-test-helper": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/webpack-assets-manifest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-assets-manifest-integration", 3 | "description": "Integration with webpack-assets-manifest", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "expect": "^26.6.2", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "nyc": "*", 11 | "webpack": "^5.44.0", 12 | "webpack-assets-manifest": "3", 13 | "webpack-cli": "4", 14 | "webpack-subresource-integrity": "*", 15 | "wsi-test-helper": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/mini-css-extract-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mini-css-extract-plugin-integration", 3 | "description": "Integration with mini-css-extract-plugin", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-loader": "^5.0.1", 9 | "html-webpack-plugin": ">= 5.0.0-beta.1", 10 | "mini-css-extract-plugin": "^1.3.0", 11 | "nyc": "*", 12 | "webpack": "^5.44.0", 13 | "webpack-cli": "4", 14 | "webpack-subresource-integrity": "*", 15 | "wsi-test-helper": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /smoke-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smoke-test", 3 | "private": true, 4 | "packageManager": "yarn@3.0.0", 5 | "devDependencies": { 6 | "expect": "^27.0.6", 7 | "fs-extra": "^10.0.0", 8 | "html-webpack-plugin": "^5.3.2", 9 | "puppeteer": "^13.5.1", 10 | "serve-handler": "^6.1.3", 11 | "tmp": "^0.2.1", 12 | "webpack": "^5.47.1", 13 | "webpack-cli": "^4.7.2", 14 | "webpack-subresource-integrity": "file:webpack-subresource-integrity.tgz" 15 | }, 16 | "scripts": { 17 | "test": "webpack --no-stats" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/issue-152/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "value", 3 | "key2": "value2", 4 | "key3": "value", 5 | "key4": "value2", 6 | "key5": "value", 7 | "key6": "value2", 8 | "key7": "value", 9 | "key8": "value2", 10 | "key9": "value", 11 | "key10": "value2", 12 | "key11": "value", 13 | "key12": "value2", 14 | "key13": "value", 15 | "key14": "value2", 16 | "key15": "value", 17 | "key16": "value2", 18 | "key17": "value", 19 | "key18": "value2", 20 | "key19": "value", 21 | "key20": "value2", 22 | "key21": "value", 23 | "key22": "value2" 24 | } 25 | -------------------------------------------------------------------------------- /examples/dll-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dll-plugin", 3 | "description": "Demonstrates how assets generated by DllPlugin can be included with SRI using html-webpack-plugin.", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "before-build-webpack": "^0.2.12", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "nyc": "*", 12 | "webpack": "^5.44.0", 13 | "webpack-cli": "4", 14 | "webpack-subresource-integrity": "*", 15 | "wsi-test-helper": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash-issue-83/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack4-contenthash-issue-83", 3 | "description": "Test case for issue #83", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-loader": "^5.0.1", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "mini-css-extract-plugin": "^1.3.0", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-cli": "4", 15 | "webpack-subresource-integrity": "*", 16 | "wsi-test-helper": "*" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/hwp-externals/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-externals", 3 | "description": "Test case for issue #97", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-select": "^5.1.0", 9 | "expect": "^26.6.2", 10 | "html-webpack-externals-plugin": "^3.8.0", 11 | "html-webpack-plugin": ">= 5.0.0-beta.1", 12 | "htmlparser2": "^8.0.1", 13 | "nyc": "*", 14 | "webpack": "^5.44.0", 15 | "webpack-cli": "4", 16 | "webpack-subresource-integrity": "*", 17 | "wsi-test-helper": "*" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/issue-154/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "issue-154", 3 | "description": "Test case for https://github.com/waysact/webpack-subresource-integrity/issues/154", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-loader": "^5.2.6", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": "^5.3.2", 11 | "mini-css-extract-plugin": "^1.3.8", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-cli": "4", 15 | "webpack-subresource-integrity": "*", 16 | "wsi-test-helper": "*" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/hwp-basic/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const { RunInPuppeteerPlugin } = require("wsi-test-helper"); 4 | 5 | module.exports = { 6 | entry: { 7 | index: "./index.js", 8 | }, 9 | output: { 10 | crossOriginLoading: "anonymous", 11 | }, 12 | plugins: [ 13 | new SubresourceIntegrityPlugin({ 14 | hashFuncNames: ["sha256"], 15 | enabled: true, 16 | }), 17 | new HtmlWebpackPlugin(), 18 | new RunInPuppeteerPlugin(), 19 | ], 20 | }; 21 | -------------------------------------------------------------------------------- /examples/hwp-custom-template/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hwp-custom-template", 3 | "description": "Test case for issue #13", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-loader": "5", 9 | "css-select": "^5.1.0", 10 | "expect": "^26.6.2", 11 | "html-webpack-plugin": ">= 5.0.0-beta.1", 12 | "htmlparser2": "^8.0.1", 13 | "mini-css-extract-plugin": "1", 14 | "nyc": "*", 15 | "webpack": "^5.44.0", 16 | "webpack-cli": "4", 17 | "webpack-subresource-integrity": "*", 18 | "wsi-test-helper": "*" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/webpack-preload/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const { RunInPuppeteerPlugin } = require("wsi-test-helper"); 4 | 5 | module.exports = { 6 | entry: { 7 | index: "./index.js", 8 | }, 9 | output: { 10 | crossOriginLoading: "anonymous", 11 | }, 12 | plugins: [ 13 | new SubresourceIntegrityPlugin({ 14 | hashFuncNames: ["sha256", "sha384"], 15 | enabled: true, 16 | }), 17 | new HtmlWebpackPlugin(), 18 | new RunInPuppeteerPlugin(), 19 | ], 20 | }; 21 | -------------------------------------------------------------------------------- /examples/lazy-e2e/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const { RunInPuppeteerPlugin } = require("wsi-test-helper"); 4 | 5 | module.exports = { 6 | entry: { 7 | index: "./index.js", 8 | }, 9 | output: { 10 | crossOriginLoading: "anonymous", 11 | }, 12 | plugins: [ 13 | new SubresourceIntegrityPlugin({ 14 | hashFuncNames: ["sha256"], 15 | enabled: true, 16 | lazyHashes: true, 17 | }), 18 | new HtmlWebpackPlugin(), 19 | new RunInPuppeteerPlugin(), 20 | ], 21 | }; 22 | -------------------------------------------------------------------------------- /examples/hwp-custom-template/index.ejs: -------------------------------------------------------------------------------- 1 | <% for (let index in htmlWebpackPlugin.files.js) { %> 2 | 6 | <% } %> 7 | 8 | <% for (let index in htmlWebpackPlugin.files.css) { %> 9 | 14 | <% } %> 15 | -------------------------------------------------------------------------------- /examples/dynamic-named-chunks/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const { RunInPuppeteerPlugin } = require("wsi-test-helper"); 4 | 5 | module.exports = { 6 | entry: { 7 | index: "./index.js", 8 | }, 9 | output: { 10 | crossOriginLoading: "anonymous", 11 | }, 12 | optimization: { 13 | chunkIds: "named", 14 | }, 15 | plugins: [ 16 | new SubresourceIntegrityPlugin({ 17 | hashFuncNames: ["sha256", "sha384"], 18 | }), 19 | new HtmlWebpackPlugin(), 20 | new RunInPuppeteerPlugin(), 21 | ], 22 | }; 23 | -------------------------------------------------------------------------------- /examples/webpack-fix-style-only-entries/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-fix-style-only-entries", 3 | "description": "Test case for issue #106", 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "private": true, 7 | "devDependencies": { 8 | "css-loader": "^5.0.1", 9 | "expect": "^26.6.2", 10 | "html-webpack-plugin": ">= 5.0.0-beta.1", 11 | "mini-css-extract-plugin": "^1.3.0", 12 | "nyc": "*", 13 | "webpack": "^5.44.0", 14 | "webpack-assets-manifest": "^3.1.1", 15 | "webpack-cli": "4", 16 | "webpack-fix-style-only-entries": "^0.6.1", 17 | "webpack-subresource-integrity": "*", 18 | "wsi-test-helper": "*" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/tsconfig-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node12/tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "declarationMap": true, 6 | "noEmitOnError": true, 7 | "sourceMap": true, 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "noUnusedParameters": true, 11 | "noUnusedLocals": true, 12 | "noImplicitReturns": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noUncheckedIndexedAccess": true, 15 | "noPropertyAccessFromIndexSignature": true, 16 | "noImplicitOverride": true 17 | }, 18 | "include": ["src/**/*"], 19 | "exclude": ["src/**/__mocks__/*", "src/__test__/**/*"] 20 | } 21 | -------------------------------------------------------------------------------- /examples/webpack4-contenthash/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const { RunInPuppeteerPlugin } = require("wsi-test-helper"); 4 | 5 | module.exports = { 6 | entry: "./index.js", 7 | mode: "production", 8 | output: { 9 | filename: "[name].[contenthash].js", 10 | chunkFilename: "[name].[contenthash].js", 11 | crossOriginLoading: "anonymous", 12 | }, 13 | plugins: [ 14 | new HtmlWebpackPlugin(), 15 | new SubresourceIntegrityPlugin({ 16 | hashFuncNames: ["sha256", "sha384"], 17 | }), 18 | new RunInPuppeteerPlugin(), 19 | ], 20 | }; 21 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/__tests__/hwp-error.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Waysact Pty Ltd 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { resolve } from "path"; 9 | import { SubresourceIntegrityPlugin } from ".."; 10 | import { runWebpack } from "./test-utils"; 11 | 12 | jest.mock("html-webpack-plugin"); 13 | 14 | test("error when loading html-webpack-plugin", async () => { 15 | await expect( 16 | runWebpack({ 17 | entry: resolve(__dirname, "./__fixtures__/simple-project/src/"), 18 | plugins: [new SubresourceIntegrityPlugin()], 19 | }) 20 | ).rejects.toThrow("bogus hwp accessed"); 21 | }); 22 | -------------------------------------------------------------------------------- /examples/basic/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const expect = require("expect"); 3 | 4 | module.exports = { 5 | entry: { 6 | index: "./index.js", 7 | }, 8 | output: { 9 | crossOriginLoading: "anonymous", 10 | }, 11 | plugins: [ 12 | new SubresourceIntegrityPlugin({ 13 | hashFuncNames: ["sha256"], 14 | enabled: true, 15 | }), 16 | { 17 | apply: (compiler) => { 18 | compiler.hooks.done.tap("wsi-test", (stats) => { 19 | expect( 20 | !stats.toJson().assets.find((asset) => asset.name == "index.js") 21 | .integrity 22 | ).not.toBeNull(); 23 | }); 24 | }, 25 | }, 26 | ], 27 | }; 28 | -------------------------------------------------------------------------------- /examples/mutually-dependent-chunks/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const expect = require("expect"); 3 | 4 | module.exports = { 5 | mode: "production", 6 | entry: "./main.js", 7 | output: { 8 | filename: "bundle.js", 9 | crossOriginLoading: "anonymous", 10 | }, 11 | plugins: [ 12 | new SubresourceIntegrityPlugin({ hashFuncNames: ["sha256", "sha384"] }), 13 | { 14 | apply: (compiler) => { 15 | compiler.hooks.done.tap("wsi-test", (stats) => { 16 | expect(stats.hasWarnings()).toBeFalsy(); 17 | stats.toJson().assets.forEach((asset) => { 18 | expect(asset.integrity).toMatch(/^sha/); 19 | }); 20 | }); 21 | }, 22 | }, 23 | ], 24 | }; 25 | -------------------------------------------------------------------------------- /examples/issue-221/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const expect = require("expect"); 4 | 5 | module.exports = { 6 | entry: { 7 | "why 1+1=2?": "./index.js", 8 | }, 9 | output: { 10 | crossOriginLoading: "anonymous", 11 | }, 12 | plugins: [ 13 | new SubresourceIntegrityPlugin({ 14 | hashFuncNames: ["sha256"], 15 | enabled: true, 16 | }), 17 | new HtmlWebpackPlugin(), 18 | { 19 | apply: (compiler) => { 20 | compiler.hooks.done.tap("wsi-test", (stats) => { 21 | expect( 22 | stats.toJson().assets.find((asset) => asset.name == "why 1+1=2?.js") 23 | ).toHaveProperty("integrity"); 24 | }); 25 | }, 26 | }, 27 | ], 28 | }; 29 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/src/__tests__/test-utils.ts: -------------------------------------------------------------------------------- 1 | import webpack, { Configuration, Stats, StatsError } from "webpack"; 2 | 3 | const errorFromStats = (stats: Stats | undefined): Error => { 4 | const errors = stats?.toJson()?.errors; 5 | if (!errors) { 6 | return new Error("No stats"); 7 | } 8 | return new Error( 9 | "Error:" + errors.map((error: StatsError) => error.message).join(", ") 10 | ); 11 | }; 12 | 13 | export const runWebpack = (options: Configuration): Promise => 14 | new Promise((resolve, reject) => { 15 | webpack(options, (err: Error | undefined, stats: Stats | undefined) => { 16 | if (err) { 17 | reject(err); 18 | } else if (stats?.hasErrors() === false) { 19 | resolve(stats); 20 | } else { 21 | reject(errorFromStats(stats)); 22 | } 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /wsi-test-helper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wsi-test-helper", 3 | "version": "1.0.0", 4 | "description": "Helpers for webpack-subresource-integrity tests", 5 | "main": "dist/index.js", 6 | "license": "MIT", 7 | "private": true, 8 | "devDependencies": { 9 | "@tsconfig/node12": "^1.0.9", 10 | "@types/connect": "^3.4.35", 11 | "@types/fastify-static": "^0.14.0", 12 | "@types/node": "^14.17.5", 13 | "@types/puppeteer": "^5.4.5", 14 | "@types/serve-static": "^1.13.10", 15 | "connect": "^3.7.0", 16 | "fastify": "^3.29.5", 17 | "fastify-graceful-shutdown": "^3.4.0", 18 | "fastify-static": "^4.7.0", 19 | "get-port": "^5.1.1", 20 | "http-shutdown": "^1.2.2", 21 | "puppeteer": "^13.5.1", 22 | "serve-static": "^1.15.0", 23 | "typescript": "^4.3.5", 24 | "webpack": "^5.44.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/disabled/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const expect = require("expect"); 3 | 4 | module.exports = { 5 | mode: "production", 6 | entry: "./index.js", 7 | output: { 8 | filename: "bundle.js", 9 | }, 10 | plugins: [ 11 | new SubresourceIntegrityPlugin({ 12 | hashFuncNames: ["sha256"], 13 | enabled: false, 14 | }), 15 | { 16 | apply: (compiler) => { 17 | compiler.hooks.done.tapPromise("wsi-test", async (stats) => { 18 | expect(stats.compilation.warnings).toEqual([]); 19 | expect( 20 | Object.keys( 21 | stats.toJson().assets.find((asset) => asset.name === "bundle.js") 22 | ) 23 | ).not.toContain("integrity"); 24 | }); 25 | }, 26 | }, 27 | ], 28 | }; 29 | -------------------------------------------------------------------------------- /examples/electron-renderer/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const expect = require("expect"); 4 | 5 | module.exports = { 6 | mode: "production", 7 | entry: { 8 | index: "./index.js", 9 | }, 10 | target: "electron-renderer", 11 | output: { 12 | crossOriginLoading: "anonymous", 13 | }, 14 | plugins: [ 15 | new SubresourceIntegrityPlugin({ 16 | hashFuncNames: ["sha256", "sha384"], 17 | enabled: true, 18 | }), 19 | new HtmlWebpackPlugin(), 20 | { 21 | apply: (compiler) => { 22 | compiler.hooks.done.tapPromise("wsi-test", async (stats) => { 23 | expect(stats.compilation.warnings).toEqual([]); 24 | expect(stats.compilation.errors).toEqual([]); 25 | }); 26 | }, 27 | }, 28 | ], 29 | }; 30 | -------------------------------------------------------------------------------- /webpack-subresource-integrity/etc/webpack-subresource-integrity.api.md: -------------------------------------------------------------------------------- 1 | ## API Report File for "webpack-subresource-integrity" 2 | 3 | > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). 4 | 5 | ```ts 6 | 7 | import type { Compiler } from 'webpack'; 8 | 9 | // @public 10 | export class SubresourceIntegrityPlugin { 11 | constructor(options?: SubresourceIntegrityPluginOptions); 12 | // (undocumented) 13 | apply(compiler: Compiler): void; 14 | } 15 | 16 | // @public (undocumented) 17 | export interface SubresourceIntegrityPluginOptions { 18 | // (undocumented) 19 | readonly enabled?: "auto" | true | false; 20 | // (undocumented) 21 | readonly hashFuncNames?: [string, ...string[]]; 22 | // (undocumented) 23 | readonly hashLoading?: "eager" | "lazy"; 24 | } 25 | 26 | // (No @packageDocumentation comment for this package) 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /examples/issue-152/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const expect = require("expect"); 3 | 4 | module.exports = { 5 | entry: "./index.js", 6 | output: { 7 | filename: "[contenthash].js", 8 | chunkFilename: "[contenthash].chunk.js", 9 | crossOriginLoading: "anonymous", 10 | }, 11 | optimization: { 12 | moduleIds: "deterministic", 13 | realContentHash: true, 14 | chunkIds: "deterministic", 15 | runtimeChunk: "single", 16 | }, 17 | plugins: [ 18 | new SubresourceIntegrityPlugin({ 19 | hashFuncNames: ["sha256"], 20 | enabled: true, 21 | }), 22 | { 23 | apply: (compiler) => { 24 | compiler.hooks.done.tap("wsi-test", (stats) => { 25 | expect(Object.keys(stats.compilation.assets)).toContain( 26 | "f144a6b271b5e4f2b145.js" 27 | ); 28 | }); 29 | }, 30 | }, 31 | ], 32 | }; 33 | -------------------------------------------------------------------------------- /examples/warn-hot-reload/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const webpack = require("webpack"); 3 | const expect = require("expect"); 4 | 5 | module.exports = { 6 | mode: "production", 7 | entry: "./index.js", 8 | output: { 9 | filename: "bundle.js", 10 | crossOriginLoading: "anonymous", 11 | }, 12 | plugins: [ 13 | new webpack.HotModuleReplacementPlugin(), 14 | new SubresourceIntegrityPlugin({ hashFuncNames: ["sha256", "sha384"] }), 15 | { 16 | apply: (compiler) => { 17 | compiler.hooks.done.tap("wsi-test", (stats) => { 18 | expect(stats.compilation.warnings.length).toEqual(1); 19 | expect(stats.compilation.warnings[0]).toBeInstanceOf(Error); 20 | expect(stats.compilation.warnings[0].message).toMatch( 21 | /may interfere with hot reloading./ 22 | ); 23 | }); 24 | }, 25 | }, 26 | ], 27 | }; 28 | -------------------------------------------------------------------------------- /examples/no-warn-filename/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const expect = require("expect"); 3 | 4 | module.exports = { 5 | mode: "production", 6 | entry: "./a.js", 7 | output: { 8 | filename: "[name]-[hash]-[hash:4]-[id]-[query].js", 9 | chunkFilename: 10 | "[name]-[hash]-[chunkhash]-[hash:4]-[chunkhash:4]-[id]-[query].js", 11 | crossOriginLoading: "anonymous", 12 | }, 13 | plugins: [ 14 | new SubresourceIntegrityPlugin({ hashFuncNames: ["sha256", "sha384"] }), 15 | { 16 | apply: (compiler) => { 17 | compiler.hooks.done.tap("wsi-test", (stats) => { 18 | expect( 19 | stats.compilation.warnings.filter( 20 | (warning) => 21 | !warning.message.match( 22 | /Use \[contenthash\] and ensure realContentHash/ 23 | ) 24 | ) 25 | ).toEqual([]); 26 | }); 27 | }, 28 | }, 29 | ], 30 | }; 31 | -------------------------------------------------------------------------------- /examples/non-web-build/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const expect = require("expect"); 4 | 5 | module.exports = { 6 | mode: "production", 7 | entry: { 8 | index: "./index.js", 9 | }, 10 | target: "node", 11 | output: { 12 | crossOriginLoading: "anonymous", 13 | }, 14 | plugins: [ 15 | new SubresourceIntegrityPlugin({ 16 | hashFuncNames: ["sha256", "sha384"], 17 | enabled: true, 18 | }), 19 | new HtmlWebpackPlugin(), 20 | { 21 | apply: (compiler) => { 22 | compiler.hooks.done.tap("wsi-test", (stats) => { 23 | expect(stats.compilation.errors).toEqual([]); 24 | expect(stats.compilation.warnings.length).toEqual(1); 25 | expect(stats.compilation.warnings[0].message).toMatch( 26 | /This plugin is not useful for non-web targets/ 27 | ); 28 | }); 29 | }, 30 | }, 31 | ], 32 | }; 33 | -------------------------------------------------------------------------------- /examples/webpack-assets-manifest/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 2 | const WebpackAssetsManifest = require("webpack-assets-manifest"); 3 | const expect = require("expect"); 4 | const { readFileSync } = require("fs"); 5 | const { join } = require("path"); 6 | 7 | module.exports = { 8 | entry: { 9 | index: "./index.js", 10 | }, 11 | output: { 12 | crossOriginLoading: "anonymous", 13 | }, 14 | plugins: [ 15 | new SubresourceIntegrityPlugin({ 16 | hashFuncNames: ["sha384", "sha512"], 17 | enabled: true, 18 | }), 19 | new WebpackAssetsManifest({ integrity: true }), 20 | { 21 | apply: (compiler) => { 22 | compiler.hooks.done.tap("wsi-test", () => { 23 | const manifest = JSON.parse( 24 | readFileSync(join(__dirname, "dist/manifest.json"), "utf-8") 25 | ); 26 | expect(manifest["index.js"].integrity).toMatch(/sha384-.* sha512-.*/); 27 | }); 28 | }, 29 | }, 30 | ], 31 | }; 32 | -------------------------------------------------------------------------------- /examples/issue-147/webpack.config.js: -------------------------------------------------------------------------------- 1 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 2 | const path = require("path"); 3 | const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin"); 4 | const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); 5 | 6 | module.exports = () => ({ 7 | entry: { 8 | app: path.resolve(__dirname, "index"), 9 | }, 10 | output: { 11 | path: path.resolve(__dirname, "dist", "inline"), 12 | crossOriginLoading: "anonymous", 13 | }, 14 | optimization: { 15 | runtimeChunk: { 16 | // Put webpack runtime code in a single separate chunk called "runtime.js" 17 | name: "runtime", 18 | }, 19 | }, 20 | plugins: [ 21 | new HtmlWebpackPlugin({ 22 | inject: "body", 23 | }), 24 | new ScriptExtHtmlWebpackPlugin({ 25 | inline: { 26 | // Inline "runtime.js" as a