From ccebf9c58c95951e318671661560849f5c51cb57 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 8 Sep 2020 19:15:56 -0400 Subject: [PATCH 1/5] feat: automatically enable allowHTTP1 by default with http2 & hmr --- .gitignore | 3 + README.md | 4 +- lib/server.js | 9 +- package-lock.json | 272 ++++++++++++++++++++++++++ package.json | 4 +- test/fixtures/http2/app.js | 19 ++ test/fixtures/http2/component.js | 2 + test/fixtures/http2/index.html | 10 + test/fixtures/http2/webpack.config.js | 34 ++++ test/snapshots/plugin.test.js.md | 67 +++---- test/snapshots/plugin.test.js.snap | Bin 1085 -> 1093 bytes 11 files changed, 384 insertions(+), 40 deletions(-) create mode 100644 test/fixtures/http2/app.js create mode 100644 test/fixtures/http2/component.js create mode 100644 test/fixtures/http2/index.html create mode 100644 test/fixtures/http2/webpack.config.js diff --git a/.gitignore b/.gitignore index 05104ca..a524d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ wps-hmr.* coverage.lcov dist + +*.pem +*.key diff --git a/README.md b/README.md index 1282f7e..5492af2 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ If `true`, will enable [`Hot Module Replacement`](https://webpack.js.org/concept _Note: If the build process generates errors, the client (browser) will not be notified of new changes and no HMR will be performed. Errors must be resolved before HMR can proceed._ -_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` must be enabled for the HMR WS connection to work._ +_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` will enabled by default for the HMR WS connection to work._ ### `host` Type: `String | Promise`
@@ -153,7 +153,7 @@ Type: `boolean` | [`http2` options](https://nodejs.org/api/http2.html#http2_http If set, this option will instruct the server to enable HTTP2. Properties for this option should correspond to [HTTP2 options][http2] or [HTTP2 SSL options][http2tls]. -_Note: If using in combination with `hmr`, the option `allowHTTP1` must be enabled for the HMR WS connection to work._ +_Note: If using in combination with `hmr`, the option `allowHTTP1` will be enabled by default for the HMR WS connection to work._ ### `https` Type: `Object`
diff --git a/lib/server.js b/lib/server.js index 1905713..97220c7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -24,18 +24,19 @@ const select = (options, callback) => { http2: require('http2').createServer, http2Secure: require('http2').createSecureServer }; - const { http2, https } = options; + const { http2, https, hmr } = options; let server; let secure = false; if (http2) { + const defaultOptions = hmr === true ? { allowHTTP1: true } : {}; if (http2 === true) { - server = types.http2({}, callback); + server = types.http2(defaultOptions, callback); } else if (http2.cert) { secure = true; - server = types.http2Secure(http2, callback); + server = types.http2Secure({ ...defaultOptions, ...http2 }, callback); } else { - server = types.http2(http2, callback); + server = types.http2({ ...defaultOptions, ...http2 }, callback); } } else if (https) { secure = true; diff --git a/package-lock.json b/package-lock.json index 372cdb6..3da93df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1705,6 +1705,15 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "dev": true, + "requires": { + "safer-buffer": "~2.1.0" + } + }, "asn1.js": { "version": "4.10.1", "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz", @@ -1743,6 +1752,12 @@ } } }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "dev": true + }, "assign-symbols": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", @@ -2478,6 +2493,15 @@ "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==", "dev": true }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "dev": true, + "requires": { + "tweetnacl": "^0.14.3" + } + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -3046,6 +3070,29 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "child-process-promise": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/child-process-promise/-/child-process-promise-2.2.1.tgz", + "integrity": "sha1-RzChHvYQ+tRQuPIjx50x172tgHQ=", + "dev": true, + "requires": { + "cross-spawn": "^4.0.2", + "node-version": "^1.0.0", + "promise-polyfill": "^6.0.1" + }, + "dependencies": { + "cross-spawn": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", + "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "which": "^1.2.9" + } + } + } + }, "chokidar": { "version": "2.1.8", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", @@ -3357,6 +3404,12 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", + "dev": true + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -3893,6 +3946,15 @@ "number-is-nan": "^1.0.0" } }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, "date-time": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/date-time/-/date-time-2.1.0.tgz", @@ -4481,6 +4543,16 @@ "stream-shift": "^1.0.0" } }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "dev": true, + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -6328,6 +6400,15 @@ "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=", "dev": true }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, "git-raw-commits": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-1.3.6.tgz", @@ -7890,6 +7971,12 @@ "esprima": "^4.0.0" } }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "dev": true + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -9349,6 +9436,29 @@ } } }, + "node-powershell": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-powershell/-/node-powershell-3.3.1.tgz", + "integrity": "sha1-u/drKfCR7YPq4WrZ56GAoT820RM=", + "dev": true, + "requires": { + "bluebird": "^3.5.1", + "chalk": "^2.1.0" + }, + "dependencies": { + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + } + } + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -9358,6 +9468,12 @@ "process-on-spawn": "^1.0.0" } }, + "node-version": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/node-version/-/node-version-1.2.0.tgz", + "integrity": "sha512-ma6oU4Sk0qOoKEAymVoTvk8EdXEobdS7m/mAGhDJ8Rouugho48crHBORAmy5BoOcv8wraPM6xumapQp5hl4iIQ==", + "dev": true + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -9722,6 +9838,12 @@ } } }, + "openssl.exe": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/openssl.exe/-/openssl.exe-0.0.2.tgz", + "integrity": "sha512-8d6bpC7XaplFujm4K2H1ATbGeiHgdVjFEk14ZIgZE0vz1z7jLOHzzorcfuNTFJRDqRe4tbj0lJAsGiJQ1I3fEA==", + "dev": true + }, "optionator": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", @@ -9784,6 +9906,12 @@ "integrity": "sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc=", "dev": true }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, "os-shim": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz", @@ -10347,6 +10475,12 @@ "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=", "dev": true }, + "promise-polyfill": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", + "integrity": "sha1-36lpQ+qcEh/KTem1hoyznTRy4Fc=", + "dev": true + }, "proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -11112,6 +11246,12 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, + "shell-escape": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/shell-escape/-/shell-escape-0.2.0.tgz", + "integrity": "sha1-aP0CXrBJC09WegJ/C/IkgLX4QTM=", + "dev": true + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -11391,6 +11531,23 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "dev": true, + "requires": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + } + }, "ssri": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", @@ -11698,6 +11855,43 @@ } } }, + "temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=", + "dev": true + }, + "temp-write": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/temp-write/-/temp-write-3.4.0.tgz", + "integrity": "sha1-jP9jD7fp2gXwR8dM5M5NaFRX1JI=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "is-stream": "^1.1.0", + "make-dir": "^1.0.0", + "pify": "^3.0.0", + "temp-dir": "^1.0.0", + "uuid": "^3.0.1" + }, + "dependencies": { + "make-dir": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", + "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", + "dev": true, + "requires": { + "pify": "^3.0.0" + } + }, + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + } + } + }, "term-size": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/term-size/-/term-size-1.2.0.tgz", @@ -11838,6 +12032,39 @@ "setimmediate": "^1.0.4" } }, + "tls-keygen": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/tls-keygen/-/tls-keygen-3.7.0.tgz", + "integrity": "sha512-yMHaz/oMw9rkTGojlCJvhBVYiKTcvjvyLTpKSJGFoUryrf5GXwRrwk+tPJsWR6pl7NXE7TM+nVqWc6sBt2WLGA==", + "dev": true, + "requires": { + "chalk": "^2.4.1", + "child-process-promise": "^2.2.1", + "command-exists": "^1.2.7", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "node-powershell": "^3.3.1", + "openssl.exe": "^0.0.2", + "shell-escape": "^0.2.0", + "sshpk": "^1.14.2", + "temp-write": "^3.4.0", + "tmp-promise": "^1.0.4", + "user-home": "^2.0.0" + }, + "dependencies": { + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + } + } + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -11847,6 +12074,36 @@ "os-tmpdir": "~1.0.2" } }, + "tmp-promise": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-1.1.0.tgz", + "integrity": "sha512-8+Ah9aB1IRXCnIOxXZ0uFozV1nMU5xiu7hhFVUSxZ3bYu+psD4TzagCzVbexUCgNNGJnsmNDQlS4nG3mTyoNkw==", + "dev": true, + "requires": { + "bluebird": "^3.5.0", + "tmp": "0.1.0" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "tmp": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", + "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", + "dev": true, + "requires": { + "rimraf": "^2.6.3" + } + } + } + }, "to-arraybuffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", @@ -11942,6 +12199,12 @@ "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", "dev": true }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "dev": true + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -12220,6 +12483,15 @@ "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "dev": true }, + "user-home": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/user-home/-/user-home-2.0.0.tgz", + "integrity": "sha1-nHC/2Babwdy/SGBODwS4tJzenp8=", + "dev": true, + "requires": { + "os-homedir": "^1.0.0" + } + }, "util": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", diff --git a/package.json b/package.json index ac4f487..cb1227e 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,9 @@ "commitlint": "commitlint", "commitmsg": "commitlint -e $GIT_PARAMS", "dev": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/simple/webpack.config.js", - "dev:clean": "del test/fixtures/multi/output/* test/fixtures/simple/output/*", + "dev:clean": "del test/fixtures/multi/output/* test/fixtures/simple/output/* test/fixtures/http2/output/*", "dev:multi": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/multi/webpack.config.js", + "dev:http2": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/http2/webpack.config.js", "faq:toc": "echo 'temporarily disabled' # markdown-toc -i .github/FAQ.md", "lint": "eslint --fix --cache lib test", "lint-staged": "lint-staged", @@ -77,6 +78,7 @@ "nyc": "^15.0.1", "pre-commit": "^1.2.2", "puppeteer": "^3.0.2", + "tls-keygen": "^3.7.0", "webpack": "^4.43.0", "webpack-nano": "^1.0.0" }, diff --git a/test/fixtures/http2/app.js b/test/fixtures/http2/app.js new file mode 100644 index 0000000..4bf1ff7 --- /dev/null +++ b/test/fixtures/http2/app.js @@ -0,0 +1,19 @@ +require('./component'); + +if (module.hot) { + module.hot.accept((err) => { + if (err) { + console.error('HMR', err); + } + }); +} + +// uncomment to produce a build error +// if (!window) { +// require('tests'); +// } + +// uncomment to produce a build warning +// console.log(require); + +// console.log(require); diff --git a/test/fixtures/http2/component.js b/test/fixtures/http2/component.js new file mode 100644 index 0000000..9262226 --- /dev/null +++ b/test/fixtures/http2/component.js @@ -0,0 +1,2 @@ +const main = document.querySelector('main'); +main.innerHTML = 'main'; diff --git a/test/fixtures/http2/index.html b/test/fixtures/http2/index.html new file mode 100644 index 0000000..44d9990 --- /dev/null +++ b/test/fixtures/http2/index.html @@ -0,0 +1,10 @@ + + + + fixture: http2 + + +
+ + + diff --git a/test/fixtures/http2/webpack.config.js b/test/fixtures/http2/webpack.config.js new file mode 100644 index 0000000..34e4259 --- /dev/null +++ b/test/fixtures/http2/webpack.config.js @@ -0,0 +1,34 @@ +const { resolve } = require('path'); + +const { ephemeral } = require('tls-keygen'); + +const getPort = require('get-port'); + +const { WebpackPluginServe: Serve } = require('../../../lib/'); + +module.exports = async () => { + const { cert, key } = await ephemeral({ entrust: false }); + return { + context: __dirname, + entry: ['./app.js', 'webpack-plugin-serve/client'], + mode: 'development', + output: { + filename: './output.js', + path: resolve(__dirname, './output'), + publicPath: 'output/' + }, + plugins: [ + new Serve({ + host: 'localhost', + port: getPort({ port: 55555 }), + http2: { cert, key } + }) + ], + resolve: { + alias: { + 'webpack-plugin-serve/client': resolve(__dirname, '../../../client') + } + }, + watch: true + }; +}; diff --git a/test/snapshots/plugin.test.js.md b/test/snapshots/plugin.test.js.md index 583a369..d745a31 100644 --- a/test/snapshots/plugin.test.js.md +++ b/test/snapshots/plugin.test.js.md @@ -4,6 +4,39 @@ The actual snapshot is saved in `plugin.test.js.snap`. Generated by [AVA](https://ava.li). +## allow https null + +> Snapshot 1 + + { + allowMany: true, + compress: null, + headers: null, + historyFallback: false, + hmr: true, + host: null, + https: null, + liveReload: false, + log: { + level: 'info', + name: 'webpack-plugin-serve', + prefix: { + level: Function level {}, + template: '{{level}}', + }, + }, + middleware: Function middleware {}, + open: false, + port: { + then: Function then {}, + }, + progress: true, + ramdisk: false, + secure: false, + static: [], + status: true, + } + ## defaults > Snapshot 1 @@ -80,6 +113,7 @@ Generated by [AVA](https://ava.li). > Snapshot 1 [ + 'test/fixtures/http2', 'test/fixtures/multi', 'test/fixtures/proxy', 'test/fixtures/ramdisk', @@ -93,36 +127,3 @@ Generated by [AVA](https://ava.li). > Snapshot 1 'test/fixtures' - -## allow https null - -> Snapshot 1 - - { - allowMany: true, - compress: null, - headers: null, - historyFallback: false, - hmr: true, - host: null, - https: null, - liveReload: false, - log: { - level: 'info', - name: 'webpack-plugin-serve', - prefix: { - level: Function level {}, - template: '{{level}}', - }, - }, - middleware: Function middleware {}, - open: false, - port: { - then: Function then {}, - }, - progress: true, - ramdisk: false, - secure: false, - static: [], - status: true, - } diff --git a/test/snapshots/plugin.test.js.snap b/test/snapshots/plugin.test.js.snap index 641dadbfa4e2e7cbd9dfd4b753afb957a1966e59..7701c8466ef6c7b1d755af2b39b525280ee4b4aa 100644 GIT binary patch literal 1093 zcmV-L1iJe{RzVkh!5@nV00000000Bk zmS1QbMI6UxcK7Z!vFY9QYOo+Jd8jDu5pAi|mRc-Yi=ei(DE7(C-6XehZ+G3D%O%zd z5ur+6ihn>XZB>F$ANnFnZAAVwii#Xk{!2-LQ;^?Q@-x;weOvw;hG+=spU z&F|07%x}KT2ZWF`nLKgFQoO-P)Q}Gvhx!cyZn3 z3>DTFbwW12cVjg3Qf_tjOMCOwuJ6C5!ustpLiQDA_H^}s@xb=i-oAVGNZ&hDSbqc0 z9^Ur*$tm~G-CKIE-?sZWrNX+khmgKkKI`LuJva3E9~Z8_y5rJQR9KHMCqyL~@itVa zxj{TFFab`03*Z-^;f2?NE#PVJ0yqRd1n0m-a0L`-I#1J24h*vrr!@ST%jF2|AvD|g z7O1k4s)VNUR4+MI*JHjf3~G-woT)IQ%)ErrY{m4sX9(b zbv!OFjq5o>;nFO4`HW{&%ch?&>9o&EHIGH>9gEaU``qAWX+aRIwSVgAR6C8JvtSw& zRB3ya`1Y=9=HK}TTCkWBO-LFtV7cKrwLl*LAv6)vr54?6N**hZBFe^%DnfQ#-ax>jw-w2MCTMwnQ!N7cxRp-TtNQBjbJ zQ7Nne#cM_sAwP_#3l4*i!1;MaP;uHhvdY1E1l_HGMzcvQfJOL)tOmXuY$ZL%_;S-b*3v( zXSQmc(wTIk&aANUYo}kb^+oPutYV$aM;_I{l5)zG2>n(gde!&EjU@q$D`uV2+LjPHNzE zd)#UMcm{4-;I^izTYsruE;7$^ydWSI_Gdi6H?hMk@Ja_>cgDTyhRKVAj#nJ0nO6C4 L^pCn8K@R``Kyn}P literal 1085 zcmV-D1j744RzV%xb!V^ycv;7;zo#2+am2BR z?Tdc#+y0TWzg)il`p&s$sI=ahA>@G%Zj7g2$!*Af>1>_Z_02^ptz&Bl(MVdp4K-+P z7*88affL{|_z~!M;Z0y0cow__4uOxs*WfDn9TaFPPg741jk1!UH2j&%lN1*%|mBwYmDt>wriHdsB0+gOAr#qwcQbEd^}>zRIPH^W_6P@HJR%%CmO3B>85)w z7iwud?v8||S@!a2ZdS{d-(t`ypOtEyMe`kx=AWI5#J#5&X(#vvN&o z$}o~P8)J4@TFV)B)wyuYDhvLstFs{wtEcGMwGqoH`ize;S+OUyNX4*9hplm$kjhpb zY1KuAIgRmX$6=iYXVfuiO^YQvDrHKmWkSk?OgR@xxj0I7%?MWYY*U1T>p5^h`W-wN zrd;f(?Hj-jun%}(3VaC8gKxo~4Mj+FR0VbQ_FzN1 z^(RedB3z3Y{k@R|9O_0V!9c&KBK=g!=%QBG&9vg^%CzFrDr?2U&1*$lX)xOE1?UV` z9O(mFfu(L8{U&v0*#?5nOd{wZHL%f6XELj%GsoKM%!Q^pvjFQKAg?Q9O8#q|>1nAm z59{61nN$m%Ns>J670ed{7`(u0^dl0K*n;Q%gv6$Y#-=ADt95H5bNJ>h;z%`IZ>9&Af zzyhy=_rPah2K)pJsLCd=z4M8X?|dTsFYb}aiV$9lv@On!7n+?LZ?5dzIJ3&<#_US& zm^aW#hm_p~p6kXP(?!tQfAo$y)mHmYHP!xESbqS2b>ohCPuH|xxnuqfsRU%l7!Lpd DR^}dJ From 0b82a7ea6977ff860d1835fa147f0d9fa8b37a1d Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 9 Sep 2020 17:16:07 -0400 Subject: [PATCH 2/5] chore: add note to README about unencrypted HTTP2 connections --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5492af2..197f3c7 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ _Note: The default URI is `http://[::]:{port}`. For more info, please read [the ### `http2` Type: `boolean` | [`http2` options](https://nodejs.org/api/http2.html#http2_http2_createserver_options_onrequesthandler) | [secure `http2` options](https://nodejs.org/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler) -If set, this option will instruct the server to enable HTTP2. Properties for this option should correspond to [HTTP2 options][http2] or [HTTP2 SSL options][http2tls]. +If set, this option will instruct the server to enable HTTP2. Properties for this option should correspond to [HTTP2 options][http2] or [HTTP2 SSL options][http2tls]. Browsers currently do not support unencrypted HTTP2 connections, so you will need to enable SSL for this to work properly. _Note: If using in combination with `hmr`, the option `allowHTTP1` will be enabled by default for the HMR WS connection to work._ From 3a8b73bced31a82f7a96b122d506523bc76df93f Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 11 Sep 2020 14:30:57 -0400 Subject: [PATCH 3/5] chore: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 197f3c7..23a84dc 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ If `true`, will enable [`Hot Module Replacement`](https://webpack.js.org/concept _Note: If the build process generates errors, the client (browser) will not be notified of new changes and no HMR will be performed. Errors must be resolved before HMR can proceed._ -_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` will enabled by default for the HMR WS connection to work._ +_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` will be enabled by default for the HMR WS connection to work._ ### `host` Type: `String | Promise`
From 66ca45c9a00e82b4abef865e6e4588185f24e77e Mon Sep 17 00:00:00 2001 From: rob Date: Sun, 13 Sep 2020 11:13:09 -0400 Subject: [PATCH 4/5] feat: add http2 test --- test/fixtures/http2/index.html | 2 +- test/helpers/puppeteer.js | 6 +++++- test/integration/http2-hmr.test.js | 34 ++++++++++++++++++++++++++++++ test/snapshots/plugin.test.js.md | 6 ++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/integration/http2-hmr.test.js diff --git a/test/fixtures/http2/index.html b/test/fixtures/http2/index.html index 44d9990..d77d6d3 100644 --- a/test/fixtures/http2/index.html +++ b/test/fixtures/http2/index.html @@ -1,7 +1,7 @@ - fixture: http2 + fixture: http2 - hmr
diff --git a/test/helpers/puppeteer.js b/test/helpers/puppeteer.js index 0780195..a0d266f 100644 --- a/test/helpers/puppeteer.js +++ b/test/helpers/puppeteer.js @@ -54,7 +54,11 @@ const waitForBuild = (stderr) => { }; const browser = async (t, run) => { - const instance = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }); + const instance = await puppeteer.launch({ + args: ['--no-sandbox', '--disable-setuid-sandbox', '--ignore-certificate-errors'], + acceptInsecureCerts: true, + ignoreHTTPSErrors: true + }); const page = await instance.newPage(); const util = { getPort, diff --git a/test/integration/http2-hmr.test.js b/test/integration/http2-hmr.test.js new file mode 100644 index 0000000..00e4607 --- /dev/null +++ b/test/integration/http2-hmr.test.js @@ -0,0 +1,34 @@ +const { join } = require('path'); + +const test = require('ava'); +const del = require('del'); +const execa = require('execa'); + +const { browser } = require('../helpers/puppeteer'); + +test('http2 with hmr - single compiler', browser, async (t, page, util) => { + const { getPort, replace, setup, waitForBuild } = util; + const fixturePath = await setup('http2', 'http2-hmr'); + const proc = execa('wp', [], { cwd: fixturePath }); + const { stdout, stderr } = proc; + const port = await getPort(stdout); + const url = `https://localhost:${port}`; + + await waitForBuild(stderr); + await page.goto(url, { + waitUntil: 'networkidle0' + }); + + const componentPath = join(fixturePath, 'component.js'); + const content = `const main = document.querySelector('main'); main.innerHTML = 'test';`; + + await replace(componentPath, content); + + const value = await page.evaluate(() => document.querySelector('main').innerHTML); + + proc.kill('SIGTERM'); + + t.is(value, 'test'); + + await del(fixturePath); +}); diff --git a/test/snapshots/plugin.test.js.md b/test/snapshots/plugin.test.js.md index d745a31..ed27bd7 100644 --- a/test/snapshots/plugin.test.js.md +++ b/test/snapshots/plugin.test.js.md @@ -127,3 +127,9 @@ Generated by [AVA](https://ava.li). > Snapshot 1 'test/fixtures' + +## enables allowHTTP1 when http2 is present + +> Snapshot 1 + + undefined From cad68f0c423ad6e93785b899d6b2c8b21c19fcf6 Mon Sep 17 00:00:00 2001 From: rob Date: Sun, 13 Sep 2020 11:15:30 -0400 Subject: [PATCH 5/5] fix: remove old output --- test/snapshots/plugin.test.js.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/snapshots/plugin.test.js.md b/test/snapshots/plugin.test.js.md index ed27bd7..d745a31 100644 --- a/test/snapshots/plugin.test.js.md +++ b/test/snapshots/plugin.test.js.md @@ -127,9 +127,3 @@ Generated by [AVA](https://ava.li). > Snapshot 1 'test/fixtures' - -## enables allowHTTP1 when http2 is present - -> Snapshot 1 - - undefined