From a673c8cb2c54eb8513926b2907411d4d5fb6a0db Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 27 Sep 2020 17:05:27 +0300 Subject: [PATCH] refactor: replace read-pkg-up with escalade Ref https://packagephobia.com/result?p=read-pkg-up read-pkg-up is quite big package with many dependencies. It solves cases not necessary for this project like pretty json errors and normalisation of package.json data. In this diff I replaced it with dependency-free escalade and parsed json with native JSON.parse. This will let users to have faster installation and less bloated node_modules. --- lib/plugins/ramdisk.js | 32 +++++++-- package-lock.json | 66 +++++++++++++---- package.json | 2 +- test/fixtures/ramdisk-empty-pkg/app.js | 2 + test/fixtures/ramdisk-empty-pkg/package.json | 1 + .../ramdisk-empty-pkg/webpack.config.js | 29 ++++++++ test/ramdisk.test.js | 22 +++++- test/snapshots/plugin.test.js.md | 67 +++++++++--------- test/snapshots/plugin.test.js.snap | Bin 1085 -> 1097 bytes 9 files changed, 164 insertions(+), 57 deletions(-) create mode 100644 test/fixtures/ramdisk-empty-pkg/app.js create mode 100644 test/fixtures/ramdisk-empty-pkg/package.json create mode 100644 test/fixtures/ramdisk-empty-pkg/webpack.config.js diff --git a/lib/plugins/ramdisk.js b/lib/plugins/ramdisk.js index 9bd4472..dcd0e2f 100644 --- a/lib/plugins/ramdisk.js +++ b/lib/plugins/ramdisk.js @@ -10,16 +10,36 @@ */ /* eslint-disable no-param-reassign */ const crypto = require('crypto'); -const { symlinkSync } = require('fs'); +const { symlinkSync, readFileSync } = require('fs'); const { basename, join, resolve } = require('path'); const isCwd = require('is-path-cwd'); -const readPkgUp = require('read-pkg-up'); +const escalade = require('escalade/sync'); const rm = require('rimraf'); const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk'); const { PluginExistsError, RamdiskPathError } = require('../errors'); +const readPkgName = () => { + const pkgPath = escalade(process.cwd(), (dir, names) => { + if (names.includes('package.json')) { + return 'package.json'; + } + return false; + }); + // istanbul ignore if + if (pkgPath == null) { + return null; + } + try { + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')); + return pkg.name; + } catch (error) { + // istanbul ignore next + return null; + } +}; + module.exports = { init(compiler, options) { const hasPlugin = compiler.options.plugins.some( @@ -34,7 +54,7 @@ module.exports = { throw new PluginExistsError('WebpackRamdiskPlugin exists in the specified configuration.'); } - const pkg = readPkgUp.sync() || {}; + let pkgName = readPkgName(); const { path } = compiler.options.output; const lastSegment = basename(path); const errorInfo = `The ramdisk option creates a symlink from \`output.path\`, to the ramdisk build output path, and must remove any existing \`output.path\` to do so.`; @@ -61,14 +81,14 @@ module.exports = { ); } - if (!pkg.name) { + if (!pkgName) { // use md5 for a short hash that'll be consistent between wps starts const md5 = crypto.createHash('md5'); md5.update(path); - pkg.name = md5.digest('hex'); + pkgName = md5.digest('hex'); } - const newPath = join(pkg.name, lastSegment); + const newPath = join(pkgName, lastSegment); // clean up the output path in prep for the ramdisk plugin compiler.options.output.path = newPath; diff --git a/package-lock.json b/package-lock.json index 58b5252..d99471f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "dev": true, "requires": { "@babel/highlight": "^7.0.0" } @@ -466,6 +467,7 @@ "version": "7.5.0", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", + "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", @@ -476,6 +478,7 @@ "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", @@ -1251,7 +1254,8 @@ "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==" + "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", + "dev": true }, "@types/parse-json": { "version": "4.0.0", @@ -4697,6 +4701,7 @@ "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, "requires": { "is-arrayish": "^0.2.1" } @@ -4737,6 +4742,11 @@ "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", "dev": true }, + "escalade": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.0.tgz", + "integrity": "sha512-mAk+hPSO8fLDkhV7V0dXazH5pDc6MrjBTPyD3VeKzxnVFjH1MIxbCdqGZB9O8+EwWakZs3ZCbDS4IpRt79V1ig==" + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -5154,7 +5164,8 @@ "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true }, "eventemitter3": { "version": "4.0.0", @@ -6865,7 +6876,8 @@ "hosted-git-info": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", - "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==" + "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "dev": true }, "html-escaper": { "version": "2.0.2", @@ -7330,7 +7342,8 @@ "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true }, "is-binary-path": { "version": "1.0.1", @@ -8074,7 +8087,8 @@ "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true }, "js-yaml": { "version": "3.13.1", @@ -8101,7 +8115,8 @@ "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==" + "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", + "dev": true }, "json-parse-even-better-errors": { "version": "2.3.1", @@ -8356,7 +8371,8 @@ "lines-and-columns": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", - "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=" + "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", + "dev": true }, "lint-staged": { "version": "10.2.2", @@ -9574,6 +9590,7 @@ "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, "requires": { "hosted-git-info": "^2.1.4", "resolve": "^1.10.0", @@ -9584,7 +9601,8 @@ "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==" + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "dev": true } } }, @@ -10231,7 +10249,8 @@ "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true }, "path-to-regexp": { "version": "1.7.0", @@ -10751,6 +10770,7 @@ "version": "7.0.1", "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", + "dev": true, "requires": { "find-up": "^4.1.0", "read-pkg": "^5.2.0", @@ -10761,6 +10781,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, "requires": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" @@ -10770,6 +10791,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, "requires": { "p-locate": "^4.1.0" } @@ -10778,6 +10800,7 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, "requires": { "p-try": "^2.0.0" } @@ -10786,6 +10809,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, "requires": { "p-limit": "^2.2.0" } @@ -10793,12 +10817,14 @@ "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true }, "parse-json": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz", "integrity": "sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw==", + "dev": true, "requires": { "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", @@ -10809,12 +10835,14 @@ "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true }, "read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", + "dev": true, "requires": { "@types/normalize-package-data": "^2.4.0", "normalize-package-data": "^2.5.0", @@ -10825,14 +10853,16 @@ "type-fest": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", - "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==" + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", + "dev": true } } }, "type-fest": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", - "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==" + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true } } }, @@ -11027,6 +11057,7 @@ "version": "1.11.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "dev": true, "requires": { "path-parse": "^1.0.6" } @@ -11543,6 +11574,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", + "dev": true, "requires": { "spdx-expression-parse": "^3.0.0", "spdx-license-ids": "^3.0.0" @@ -11551,12 +11583,14 @@ "spdx-exceptions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", - "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==" + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "dev": true }, "spdx-expression-parse": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, "requires": { "spdx-exceptions": "^2.1.0", "spdx-license-ids": "^3.0.0" @@ -11565,7 +11599,8 @@ "spdx-license-ids": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz", - "integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==" + "integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==", + "dev": true }, "split-string": { "version": "3.1.0", @@ -12479,6 +12514,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, "requires": { "spdx-correct": "^3.0.0", "spdx-expression-parse": "^3.0.0" diff --git a/package.json b/package.json index 25e8ac0..49bac3c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "dependencies": { "chalk": "^4.0.0", "connect-history-api-fallback": "^1.5.0", + "escalade": "^3.1.0", "globby": "^11.0.0", "http-proxy-middleware": "^1.0.3", "is-path-cwd": "^2.2.0", @@ -54,7 +55,6 @@ "onetime": "^5.1.0", "open": "^7.0.3", "p-defer": "^3.0.0", - "read-pkg-up": "^7.0.1", "rimraf": "^3.0.2", "strip-ansi": "^6.0.0", "superstruct": "^0.10.12", diff --git a/test/fixtures/ramdisk-empty-pkg/app.js b/test/fixtures/ramdisk-empty-pkg/app.js new file mode 100644 index 0000000..9262226 --- /dev/null +++ b/test/fixtures/ramdisk-empty-pkg/app.js @@ -0,0 +1,2 @@ +const main = document.querySelector('main'); +main.innerHTML = 'main'; diff --git a/test/fixtures/ramdisk-empty-pkg/package.json b/test/fixtures/ramdisk-empty-pkg/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/test/fixtures/ramdisk-empty-pkg/package.json @@ -0,0 +1 @@ +{} diff --git a/test/fixtures/ramdisk-empty-pkg/webpack.config.js b/test/fixtures/ramdisk-empty-pkg/webpack.config.js new file mode 100644 index 0000000..3a4d0bb --- /dev/null +++ b/test/fixtures/ramdisk-empty-pkg/webpack.config.js @@ -0,0 +1,29 @@ +const { resolve } = require('path'); + +const getPort = require('get-port'); + +const { WebpackPluginServe: Serve } = require('../../../lib/'); + +module.exports = { + 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 }), + ramdisk: true + }) + ], + resolve: { + alias: { + 'webpack-plugin-serve/client': resolve(__dirname, '../../../client') + } + }, + watch: true +}; diff --git a/test/ramdisk.test.js b/test/ramdisk.test.js index 8bfd5eb..ec8457d 100644 --- a/test/ramdisk.test.js +++ b/test/ramdisk.test.js @@ -30,7 +30,7 @@ test('ramdisk', async (t) => { const path = await waitFor(pathTest, stdout); - t.regex(path, /(volumes|mnt)\/wps\/[a-f0-9]{32}\/output/i); + t.regex(path, /(volumes|mnt)\/wps\/webpack-plugin-serve\/output/i); await waitFor(doneTest, stderr); @@ -51,7 +51,7 @@ test('ramdisk with options', async (t) => { const path = await waitFor(pathTest, stdout); - t.regex(path, /(volumes|mnt)\/wps\/[a-f0-9]{32}\/output/i); + t.regex(path, /(volumes|mnt)\/wps\/webpack-plugin-serve\/output/i); await waitFor(doneTest, stderr); @@ -87,3 +87,21 @@ test('cwd error', async (t) => { } t.fail(); }); + +test('ramdisk with empty package.json', async (t) => { + const fixturePath = join(__dirname, 'fixtures/ramdisk-empty-pkg'); + const proc = execa('wp', [], { cwd: fixturePath }); + const { stderr, stdout } = proc; + const pathTest = 'Build being written to '; + const doneTest = '[emitted]'; + + const path = await waitFor(pathTest, stdout); + + t.regex(path, /(volumes|mnt)\/wps\/[a-f0-9]{32}\/output/i); + + await waitFor(doneTest, stderr); + + const exists = existsSync(join(fixturePath, 'output/output.js')); + + t.truthy(exists); +}); diff --git a/test/snapshots/plugin.test.js.md b/test/snapshots/plugin.test.js.md index 583a369..2855290 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 @@ -83,6 +116,7 @@ Generated by [AVA](https://ava.li). 'test/fixtures/multi', 'test/fixtures/proxy', 'test/fixtures/ramdisk', + 'test/fixtures/ramdisk-empty-pkg', 'test/fixtures/ramdisk/cwd-error', 'test/fixtures/simple', 'test/fixtures/wait-for-build', @@ -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..30f664343503ca1264d3cb019047b406cee60479 100644 GIT binary patch literal 1097 zcmV-P1h)G@RzV@`VK4-2K`9x6&3&OZpXr4|pZMNr#X6#L{}GMDUiv%Bt2E*EQs z6QRnz6#sx&TK{keRp?7m^eS4g50yh|U;7~RprZCf9}emtTK#73cHN!JCiWnQhJ4uM zH@`nSGr##V?-N2&Wa{K?Q+p@+htjVd-*@V((K$+*pEW8WpHAPGb7~vc%}sp&z~#-? z(o|TV*9f`y-5cZS7qS~NUs_vdc3=9M3hTG42-%;X+uJkv#r->9dGn6>V*_tdVZ92T zIlANLQ!~!5d$#pozh%!mlnU$iK0*dw`fPyz_H6m{UoKpKdFaZMR9HV+O^8C$;%%r# zvm7|#S3o&+rU%cIdBAg0M3ES;CGOxsT@r`F+9qOoYLTDHk&21kI+o> zo2QAjR3S8(qgv6fIxh1(VNm*{;dF)RCFaJAW-5lqZMU&YH_c(acu?3AS;EKXuW5|2eay7=Qjm2urTqy)g1n|(7RHA|#@?z?Dw(XVyG$--JIo5_s)xc< z$9B2AG>&VRgQZ#W@@ZGEmJBau(kYJ>Yc31dI}xgv^0>~8;*ua(YyZ^Ks5*_HvtSnF z6={1D(d}K=%oSMz;jQheSw(KxmY9_PM?`2eu^CD4mJ_Fl?S%49O4 zrxa-#Nt2B+Ggw-~8nNZQu=FbP|E#UEVF%q)aLiiSunHb?$Cy~LN0iWtp-V@MaZ!+p zQ8zTI@(Qz>^HEN~It9+ib5dF^mI#!VDJ?G(N+v|fE1{ALvy^*=v#Mk2JeXY1p+my& z@Zq53LZDPrjn)h)LT(gK2OI?-g7b@tpy0G`06W2c;DAZ+9yklW1AjIZA<(1tusBb zIPNb!Lr)CkJnU)8Hbw26E7lEnqh=z>DB*@G+PHKLHK>x(V#)tTnmLTJyiS zp(HDuJ27Qr6zM=KMS694igad$6=`-kx0f3TQgKLb2Tyn7_F^Mx?LT^ZnQW^npR`n! zSy+Dne|6*ba%b06CGPf;gn0CE=J7#Ho};6@kl-Y?;CT-rk?o<8?dcV(wW?V;c=OnN z+Cz9g3YtRpI+zAm!FmYP5baPWE!W9M>I_zECN~y+D2;K#nHz8TPQkL?8g*JcdA^(C zyKQXgR=}3%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