From 3a25e3c129ba3a331fd6585a60604dbe29293432 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sat, 4 Jul 2020 20:30:30 +0100 Subject: [PATCH 1/2] Update all packages to their latest versions puppeteer, commander, and chalk all went up a MAJOR version, but the main breaking change was updating to Node v10, which we need anyway. --- package-lock.json | 357 +++++++++++++++++++++++++++++++++------------- package.json | 15 +- 2 files changed, 262 insertions(+), 110 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91887ad..ce84906 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1303,6 +1303,22 @@ "webpackbar": "^4.0.0" }, "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true + }, "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -1617,6 +1633,14 @@ "@types/webpack": "^4.41.0", "commander": "^4.0.1", "querystring": "0.2.0" + }, + "dependencies": { + "commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true + } } }, "@docusaurus/utils": { @@ -2097,6 +2121,18 @@ "@types/istanbul-reports": "^1.1.1", "@types/yargs": "^15.0.0", "chalk": "^3.0.0" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@mdx-js/mdx": { @@ -2459,9 +2495,9 @@ "dev": true }, "@types/express": { - "version": "4.17.5", - "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.5.tgz", - "integrity": "sha512-u4Si7vYAjy5/UyRFa8EoqLHh6r82xOZPbWRQHlSf6alob0rlyza7EkU0RbR8kOZqgWp6R5+aRcHMYYby7w12Bg==", + "version": "4.17.6", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.6.tgz", + "integrity": "sha512-n/mr9tZI83kd4azlPG5y997C/M4DNABK9yErhFM6hKdym4kkmd9j0vtsJyjFIwfRBxtrxZtAfGZCNRIBMFLK5w==", "dev": true, "requires": { "@types/body-parser": "*", @@ -2471,12 +2507,13 @@ } }, "@types/express-serve-static-core": { - "version": "4.17.4", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.4.tgz", - "integrity": "sha512-dPs6CaRWxsfHbYDVU51VjEJaUJEcli4UI0fFMT4oWmgCvHj+j7oIxz5MLHVL0Rv++N004c21ylJNdWQvPkkb5w==", + "version": "4.17.8", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.8.tgz", + "integrity": "sha512-1SJZ+R3Q/7mLkOD9ewCBDYD2k0WyZQtWYqF/2VvoNN2/uhI49J9CDN4OAm+wGMA0DbArA4ef27xl4+JwMtGggw==", "dev": true, "requires": { "@types/node": "*", + "@types/qs": "*", "@types/range-parser": "*" } }, @@ -2556,16 +2593,11 @@ } }, "@types/mime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", - "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.2.tgz", + "integrity": "sha512-4kPlzbljFcsttWEq6aBW0OZe6BDajAmyvr2xknBG92tejQnvdGtT9+kXSZ580DqpxY9qG2xeQVF9Dq0ymUTo5Q==", "dev": true }, - "@types/mime-types": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", - "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=" - }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -2575,8 +2607,7 @@ "@types/node": { "version": "13.9.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.0.tgz", - "integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==", - "dev": true + "integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -2597,9 +2628,9 @@ "dev": true }, "@types/puppeteer": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/puppeteer/-/puppeteer-2.0.1.tgz", - "integrity": "sha512-G8vEyU83Bios+dzs+DZGpAirDmMqRhfFBJCkFrg+A5+6n5EPPHxwBLImJto3qjh0mrBXbLBCyuahhhtTrAfR5g==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/puppeteer/-/puppeteer-3.0.1.tgz", + "integrity": "sha512-t03eNKCvWJXhQ8wkc5C6GYuSqMEdKLOX0GLMGtks25YZr38wKZlKTwGM/BoAPVtdysX7Bb9tdwrDS1+NrW3RRA==", "dev": true, "requires": { "@types/node": "*" @@ -2612,9 +2643,9 @@ "dev": true }, "@types/qs": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.1.tgz", - "integrity": "sha512-lhbQXx9HKZAPgBkISrBcmAcMpZsmpe/Cd/hY7LGZS5OfkySUBItnPZHgQPssWYUET8elF+yCFBbP1Q0RZPTdaw==", + "version": "6.9.3", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.3.tgz", + "integrity": "sha512-7s9EQWupR1fTc2pSMtXRQ9w9gLOcrJn+h7HOXw4evxyvVqMi4f+q7d2tnFe3ng3SNHjtK+0EzGMGFUQX4/AQRA==", "dev": true }, "@types/range-parser": { @@ -2624,9 +2655,9 @@ "dev": true }, "@types/serve-static": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", - "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.4.tgz", + "integrity": "sha512-jTDt0o/YbpNwZbQmE/+2e+lfjJEJJR0I3OFaKQKPWkASkCoW3i6fsUnqudSMcNAfbtmADGu8f4MV4q+GqULmug==", "dev": true, "requires": { "@types/express-serve-static-core": "*", @@ -2714,6 +2745,15 @@ "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==", "dev": true }, + "@types/yauzl": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", + "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "optional": true, + "requires": { + "@types/node": "*" + } + }, "@typescript-eslint/eslint-plugin": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.5.0.tgz", @@ -3385,7 +3425,8 @@ "async-limiter": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", + "dev": true }, "asynckit": { "version": "0.4.0", @@ -3741,8 +3782,7 @@ "base64-js": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", - "dev": true + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" }, "batch": { "version": "0.6.1", @@ -3783,6 +3823,37 @@ "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", "dev": true }, + "bl": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz", + "integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -4034,7 +4105,8 @@ "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true }, "buffer-indexof": { "version": "1.1.1", @@ -4252,9 +4324,9 @@ "dev": true }, "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -4339,8 +4411,7 @@ "chownr": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "dev": true + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" }, "chrome-trace-event": { "version": "1.0.2", @@ -4671,9 +4742,9 @@ "dev": true }, "commander": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", - "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz", + "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==" }, "commondir": { "version": "1.0.1", @@ -4749,6 +4820,7 @@ "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, "requires": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", @@ -4965,7 +5037,8 @@ "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true }, "cosmiconfig": { "version": "6.0.0", @@ -5423,7 +5496,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, "requires": { "ms": "^2.1.1" } @@ -5941,7 +6013,6 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -6762,28 +6833,23 @@ } }, "extract-zip": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", - "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", + "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", "requires": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", + "@types/yauzl": "^2.9.1", + "debug": "^4.1.1", + "get-stream": "^5.1.0", "yauzl": "^2.10.0" }, "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "get-stream": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", + "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", "requires": { - "ms": "2.0.0" + "pump": "^3.0.0" } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } }, @@ -7013,7 +7079,6 @@ "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" @@ -7316,6 +7381,11 @@ "readable-stream": "^2.0.0" } }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -7978,6 +8048,14 @@ "param-case": "^3.0.3", "relateurl": "^0.2.7", "terser": "^4.6.3" + }, + "dependencies": { + "commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true + } } }, "html-tags": { @@ -8245,16 +8323,6 @@ "requires": { "agent-base": "5", "debug": "4" - }, - "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "requires": { - "ms": "^2.1.1" - } - } } }, "human-signals": { @@ -8313,8 +8381,7 @@ "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", - "dev": true + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "iferr": { "version": "0.1.5", @@ -8932,7 +8999,8 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true }, "isexe": { "version": "2.0.0", @@ -9252,6 +9320,18 @@ "diff-sequences": "^25.2.6", "jest-get-type": "^25.2.6", "pretty-format": "^25.5.0" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-docblock": { @@ -10522,7 +10602,6 @@ "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" } @@ -11122,7 +11201,8 @@ "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true }, "minipass": { "version": "3.1.3", @@ -11186,6 +11266,11 @@ "through2": "^2.0.0" } }, + "mitt": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-2.0.1.tgz", + "integrity": "sha512-FhuJY+tYHLnPcBHQhbUFzscD5512HumCPE4URXZUgPi3IvOJi4Xva5IIgy3xX56GqCmw++MAm5UURG6kDBYTdg==" + }, "mixin-deep": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", @@ -11229,10 +11314,16 @@ "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, "requires": { "minimist": "^1.2.5" } }, + "mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -11800,7 +11891,6 @@ "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" } @@ -11809,7 +11899,6 @@ "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" } @@ -11835,8 +11924,7 @@ "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==", - "dev": true + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" }, "pako": { "version": "1.0.11", @@ -11961,8 +12049,7 @@ "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==", - "dev": true + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" }, "path-is-absolute": { "version": "1.0.1", @@ -12012,9 +12099,9 @@ } }, "pdf-lib": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.7.0.tgz", - "integrity": "sha512-JauBSWwR5hCsdqxCsm1vJUJ4R1MSikzxWzi+E4zFFMU0zZHX71u18oyW0ZaELXJW13L11I/2LKrUJEhTISUzzg==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.9.0.tgz", + "integrity": "sha512-CO0vkvnkqLGY9vC4cosHcoOR7PMsFC4Dkf29sQm5J894sphy9ZxO/vbccZfQcBqTROAp+aY7TD9bh1T1EY/52Q==", "requires": { "@pdf-lib/standard-fonts": "^0.0.4", "@pdf-lib/upng": "^1.0.1", @@ -12073,7 +12160,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", - "dev": true, "requires": { "find-up": "^4.0.0" } @@ -13345,7 +13431,8 @@ "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true }, "progress": { "version": "2.0.3", @@ -13440,7 +13527,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -13476,29 +13562,36 @@ "dev": true }, "puppeteer": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-2.1.1.tgz", - "integrity": "sha512-LWzaDVQkk1EPiuYeTOj+CZRIjda4k2s5w4MK4xoH2+kgWV/SDlkYHmxatDdtYrciHUKSXTsGgPgPP8ILVdBsxg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-5.0.0.tgz", + "integrity": "sha512-JnZcgRQnfowRSJoSHteKU7G9fP/YYGB/juPn8m4jNqtzvR0h8GOoFmdjTBesJFfzhYkPU1FosHXnBVUB++xgaA==", "requires": { - "@types/mime-types": "^2.1.0", "debug": "^4.1.0", - "extract-zip": "^1.6.6", + "extract-zip": "^2.0.0", "https-proxy-agent": "^4.0.0", "mime": "^2.0.3", - "mime-types": "^2.1.25", + "mitt": "^2.0.1", + "pkg-dir": "^4.2.0", "progress": "^2.0.1", "proxy-from-env": "^1.0.0", - "rimraf": "^2.6.1", - "ws": "^6.1.0" + "rimraf": "^3.0.2", + "tar-fs": "^2.0.0", + "unbzip2-stream": "^1.3.3", + "ws": "^7.2.3" }, "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "requires": { - "ms": "^2.1.1" + "glob": "^7.1.3" } + }, + "ws": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", + "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" } } }, @@ -14120,6 +14213,7 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -14681,6 +14775,7 @@ "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" } @@ -16158,6 +16253,41 @@ "integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==", "dev": true }, + "tar-fs": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.0.tgz", + "integrity": "sha512-9uW5iDvrIMCVpvasdFHW0wJPez0K4JnMZtsuIeDI7HyMGJNxmDZDOCQROr7lXyS+iL/QMpj07qcjGYTSdRFXUg==", + "requires": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.0.0" + } + }, + "tar-stream": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz", + "integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==", + "requires": { + "bl": "^4.0.1", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "terminal-link": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/terminal-link/-/terminal-link-2.1.1.tgz", @@ -16298,8 +16428,7 @@ "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "through2": { "version": "2.0.5", @@ -16586,7 +16715,8 @@ "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true }, "typedarray-to-buffer": { "version": "3.1.5", @@ -16598,11 +16728,31 @@ } }, "typescript": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", - "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.6.tgz", + "integrity": "sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==", "dev": true }, + "unbzip2-stream": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz", + "integrity": "sha512-mlExGW4w71ebDJviH16lQLtZS32VKqsSfk80GCfUlwT/4/hNRFsoscrF/c++9xinkMzECL1uL9DDwXqFWkruPg==", + "requires": { + "buffer": "^5.2.1", + "through": "^2.3.8" + }, + "dependencies": { + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + } + } + }, "unherit": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.3.tgz", @@ -18469,6 +18619,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "dev": true, "requires": { "async-limiter": "~1.0.0" } diff --git a/package.json b/package.json index 959d919..fb58e8e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "engines": { "node": "^10.17.0 || >=11.14.0" }, + "repository": "github:KohheePeace/docusaurus-pdf", "bin": { "docusaurus-pdf": "bin/index.js" }, @@ -24,9 +25,9 @@ "devDependencies": { "@docusaurus/core": "^2.0.0-alpha.58", "@docusaurus/preset-classic": "^2.0.0-alpha.58", - "@types/express": "^4.17.5", + "@types/express": "^4.17.6", "@types/jest": "^26.0.3", - "@types/puppeteer": "^2.0.1", + "@types/puppeteer": "^3.0.0", "@typescript-eslint/eslint-plugin": "^3.5.0", "@typescript-eslint/parser": "^3.5.0", "clsx": "^1.1.1", @@ -42,14 +43,14 @@ "react": "^16.8.4", "react-dom": "^16.8.4", "ts-jest": "^26.1.1", - "typescript": "^3.8.3" + "typescript": "^3.9.6" }, "dependencies": { - "chalk": "^3.0.0", - "commander": "^4.1.1", + "chalk": "^4.1.0", + "commander": "^5.1.0", "express": "^4.17.1", - "pdf-lib": "^1.7.0", - "puppeteer": "^2.1.1" + "pdf-lib": "^1.9.0", + "puppeteer": "^5.0.0" }, "files": [ "lib/**/*", From 04cdcf1bb192fcd7f247bf531259ca0b976075ba Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sun, 5 Jul 2020 00:08:45 +0100 Subject: [PATCH 2/2] feat: Allow setting the margin and format of PDF Adds the --format and --margin field to specify the formatting of the PDF file, and adds tests to make sure we don't break anything. Additionally, allows setting --no-sandbox on all commands, including the default docusaurus command. Fixes #18. --- README.md | 2 + bin/index.js | 113 ++++++++++++++++++++++++++--------------- src/index.ts | 31 +++++++---- tests/cli-test.spec.ts | 60 ++++++++++++++++++++++ 4 files changed, 153 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index bf00c4a..25c7e0f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ npx docusaurus-pdf from-build-config - Mandatory: `dirPath` which points to the build directory created with `docusaurus build`. - Mandatory: `firstDocPagePath` is the URL path segment (without `baseUrl`) of your first docs page you whish to have included in the PDF. - Optional: If you have a `baseUrl` configured in your `docusaurus.config.js` then pass this value as `baseUrl`. +- Optional: You can specify larger/smaller margins, e.g. `--margin "1cm 1.5cm 1cm 2cm"` (order top right bottom left, like the css margin field). +- Optional: You can change the size of the paper by using `--format`, e.g. `--format A3` - Note: There is a optional parameter to set a custom filename. You can see further details using `npx docusaurus-pdf from-build --help`. ## Docker usage diff --git a/bin/index.js b/bin/index.js index ce3c2c5..ce3bdea 100755 --- a/bin/index.js +++ b/bin/index.js @@ -10,22 +10,55 @@ const { generatePdfFromBuildWithConfig, } = require("../lib"); +function generatePdfOptions({ sandbox, margin, format, printBackground }) { + return { + puppeteerArgs: sandbox ? [] : ["--no-sandbox"], + puppeteerPdfOpts: { margin, format, printBackground }, + }; +} + +function parseMargin(marginString) { + const matches = [...marginString.match(/\d+\w{0,2}/g)]; + if (matches.length !== 4) { + throw Error( + `Was expecting exactly 4 margin specifiers, instead got ${matches.length}. Margin specifier was "${marginString}".` + ); + } + const [top, right, bottom, left] = matches; + return { top, right, bottom, left }; +} + program .version(require("../package.json").version) .name("docusaurus-pdf") .usage(" [filename]") - .description("Generate PDF from initial docs url") - .arguments(" [filename]") - .action((initialDocsUrl, filename) => { - generatePdf(initialDocsUrl, filename) - .then(() => { - console.log(chalk.green("Finish generating PDF!")); - process.exit(0); - }) - .catch((err) => { - console.error(chalk.red(err.stack)); - process.exit(1); - }); + .description("Generate a PDF from a docusaurus website") + .option("--no-sandbox", "Start puppeteer with --no-sandbox flag") + .option( + "--margin ", + "Set margins of the pdf document with units in order top, right, bottom, left (units px,in,mm,cm)", + parseMargin, + "25px 35px 25px 35px" + ) + .option( + "--format ", + "Set the size of the page, e.g. (A4, Letter)", + "A4" + ) + .option("--no-print-background", "Disable printing the page background"); + +program + .command("from-website [filename]", { + isDefault: true, + }) + .description("Generate PDF from an already hosted website") + .action(async (initialDocsUrl, filename = "docusaurus.pdf") => { + await generatePdf( + initialDocsUrl, + filename, + generatePdfOptions(program.opts()) + ); + console.log(chalk.green("Finish generating PDF!")); }); program @@ -36,34 +69,25 @@ program "Specify your file name.", "docusaurus.pdf" ) - .option("--no-sandbox", "Start puppeteer with --no-sandbox flag") - .action((dirPath, firstDocPagePath, baseUrl, options) => { - const puppeteerArgs = options.sandbox ? [] : ["--no-sandbox"]; - generatePdfFromBuildSources( + .action(async (dirPath, firstDocPagePath, baseUrl, { outputFile }) => { + await generatePdfFromBuildSources( dirPath, firstDocPagePath, baseUrl, - options.outputFile, - puppeteerArgs - ) - .then(() => { - console.log(chalk.green("Finish generating PDF!")); - process.exit(0); - }) - .catch((err) => { - console.error(chalk.red(err.stack)); - process.exit(1); - }); + outputFile, + generatePdfOptions(program.opts()) + ); + console.log(chalk.green("Finish generating PDF!")); }); program .command("from-build-config [dirPath]") .description( - "Generate PDF from a docusaurs build artifact, loading from a docusaurus.config.js file" + "Generate PDF from a docusaurus build artifact, loading from a docusaurus.config.js file" ) .option( "--site-dir ", - "The full path for the docusuarus site directory, relative to the current workspace." + + "The full path for the docusaurus site directory, relative to the current workspace." + " Equivalent to the siteDir in `npx docusaurus build`", "./" ) @@ -72,21 +96,26 @@ program "Specify your file name", "docusaurus.pdf" ) - .option("--no-sandbox", "Start puppeteer with --no-sandbox flag") - .action((dirPath = "build", { siteDir, outputFile, sandbox }) => { - const puppeteerArgs = sandbox ? [] : ["--no-sandbox"]; - generatePdfFromBuildWithConfig(siteDir, dirPath, outputFile, puppeteerArgs) - .then(() => { - console.log(chalk.green("Finish generating PDF!")); - process.exit(0); - }) - .catch((err) => { - console.error(chalk.red(err.stack)); - process.exit(1); - }); + .action(async (dirPath = "build", { siteDir, outputFile }) => { + await generatePdfFromBuildWithConfig( + siteDir, + dirPath, + outputFile, + generatePdfOptions(program.opts()) + ); + console.log(chalk.green("Finish generating PDF!")); }); -program.parse(process.argv); +async function main() { + try { + await program.parseAsync(process.argv); + } catch (error) { + console.error(chalk.red(error.stack)); + process.exit(1); + } +} + +main(); if (!process.argv.slice(2).length) { program.outputHelp(); diff --git a/src/index.ts b/src/index.ts index c0d34cd..48ed254 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,11 @@ import * as path from "path"; const generatedPdfBuffers: Array = []; +interface GeneratePdfOptions { + puppeteerArgs: Array; + puppeteerPdfOpts: puppeteer.PDFOptions; +} + async function mergePdfBuffers(pdfBuffers: Array) { const outDoc = await PDFDocument.create(); for (const pdfBuffer of pdfBuffers) { @@ -100,9 +105,11 @@ export function getPathSegment(path: string, endSlash = true): string { export async function generatePdf( initialDocsUrl: string, filename = "docusaurus.pdf", - puppeteerArgs: Array -): Promise { - const browser = await puppeteer.launch({ args: puppeteerArgs }); + generatePdfOptions: GeneratePdfOptions +): Promise { + const browser = await puppeteer.launch({ + args: generatePdfOptions.puppeteerArgs, + }); const page = await browser.newPage(); const url = new URL(initialDocsUrl); @@ -150,9 +157,7 @@ export async function generatePdf( await page.addScriptTag({ url: scriptPath }); const pdfBuffer = await page.pdf({ path: "", - format: "A4", - printBackground: true, - margin: { top: 25, right: 35, left: 35, bottom: 25 }, + ...generatePdfOptions.puppeteerPdfOpts, }); generatedPdfBuffers.push(pdfBuffer); @@ -162,7 +167,11 @@ export async function generatePdf( await browser.close(); const mergedPdfBuffer = await mergePdfBuffers(generatedPdfBuffers); - fs.writeFileSync(`${filename}`, mergedPdfBuffer); + + if (filename) { + await fs.promises.writeFile(`${filename}`, mergedPdfBuffer); + } + return Buffer.from(mergedPdfBuffer); } interface LoadedConfig { @@ -219,7 +228,7 @@ export async function generatePdfFromBuildWithConfig( siteDir: string, buildDirPath: string, filename: string, - puppeteerArgs: Array + generatePdfOptions: GeneratePdfOptions ): Promise { const { firstDocPath, baseUrl } = await loadConfig(siteDir); await generatePdfFromBuildSources( @@ -227,7 +236,7 @@ export async function generatePdfFromBuildWithConfig( firstDocPath, baseUrl, filename, - puppeteerArgs + generatePdfOptions ); } @@ -236,7 +245,7 @@ export async function generatePdfFromBuildSources( firstDocPath: string, baseUrl: string, filename: string, - puppeteerArgs: Array + generatePdfOptions: GeneratePdfOptions ): Promise { const app = express(); @@ -269,7 +278,7 @@ export async function generatePdfFromBuildSources( await generatePdf( `http://127.0.0.1:${address.port}${baseUrl}${firstDocPath}`, filename, - puppeteerArgs + generatePdfOptions ); } finally { httpServer.close(); diff --git a/tests/cli-test.spec.ts b/tests/cli-test.spec.ts index 95c9fcd..17985a0 100644 --- a/tests/cli-test.spec.ts +++ b/tests/cli-test.spec.ts @@ -12,6 +12,13 @@ const TEST_SITE_DIR = "./tests/test-website"; // third-to-last docs path so should be faster const DOCUSAURUS_TEST_LINK = "https://v2.docusaurus.io/docs/2.0.0-alpha.56/docusaurus.config.js"; +const PUPPETEER_SETTINGS = [ + "--margin", + "2cm 2cm 2cm 2cm", + "--format", + "A3", + "--no-sandbox", +]; async function runDocusaurusPdf( args: Array, @@ -72,6 +79,30 @@ describe("testing cli", () => { ).rejects.toThrow(); expect(await isFile(outputPath)).toBe(false); }); + test("should use puppeteer settings", async () => { + const outputPath = pathJoin(TEST_OUTPUT, "docusaurus-a3.pdf"); + await runDocusaurusPdf([ + DOCUSAURUS_TEST_LINK, + outputPath, + ...PUPPETEER_SETTINGS, + ]); + expect(await isFile(outputPath)).toBe(true); + }); + test("should fail with invalid margins", async () => { + const outputPath = pathJoin( + TEST_OUTPUT, + "should-fail-invalid-margins.pdf" + ); + await expect( + runDocusaurusPdf([ + DOCUSAURUS_TEST_LINK, + outputPath, + "--margin", + "2cm 2cm 2cm", + ]) + ).rejects.toThrow(); + expect(await isFile(outputPath)).toBe(false); + }); }); describe("from-build", () => { @@ -112,6 +143,22 @@ describe("testing cli", () => { ]); expect(await isFile(outputPath)).toBe(true); }); + test("should use puppeteer settings", async () => { + const outputPath = pathJoin(TEST_OUTPUT, "from-build-a3.pdf"); + const buildDir = pathJoin(TEST_SITE_DIR, "build"); + const docsPath = "/docs-path"; + const baseUrl = "/base-url/"; + await runDocusaurusPdf([ + "from-build", + buildDir, + docsPath, + baseUrl, + "--output-file", + outputPath, + ...PUPPETEER_SETTINGS, + ]); + expect(await isFile(outputPath)).toBe(true); + }); }); describe("from-build-config", () => { @@ -130,5 +177,18 @@ describe("testing cli", () => { ); expect(await isFile(outputPath)).toBe(true); }); + test("should use puppeteer settings", async () => { + const outputPath = pathJoin(TEST_OUTPUT, "from-build-config-a3.pdf"); + await runDocusaurusPdf( + [ + "from-build-config", + "--output-file", + pathResolve(outputPath), + ...PUPPETEER_SETTINGS, + ], + { cwd: TEST_SITE_DIR } + ); + expect(await isFile(outputPath)).toBe(true); + }); }); });