From 551bee843ebe7be582eda8c81213142edd4d91d6 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 4 Feb 2020 09:42:27 +0000 Subject: [PATCH 1/4] feat: update got --- packages/goto/package.json | 2 +- packages/goto/scripts/postinstall.js | 14 ++++++-------- packages/screenshot/package.json | 2 +- packages/screenshot/src/index.js | 5 +---- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/goto/package.json b/packages/goto/package.json index 3d2fd41f48..423abef1a8 100644 --- a/packages/goto/package.json +++ b/packages/goto/package.json @@ -31,7 +31,7 @@ "@browserless/devices": "^5.18.5", "@cliqz/adblocker-puppeteer": "~1.5.0", "debug-logfmt": "~1.0.4", - "got": "~9.6.0", + "got": "~10.4.0", "p-reflect": "~2.1.0", "p-timeout": "~3.2.0", "tldts": "~5.6.3" diff --git a/packages/goto/scripts/postinstall.js b/packages/goto/scripts/postinstall.js index bc9364f955..246fd883f5 100644 --- a/packages/goto/scripts/postinstall.js +++ b/packages/goto/scripts/postinstall.js @@ -9,17 +9,15 @@ const writeFile = promisify(fs.writeFile) const OUTPUT_FILENAME = 'src/engine.bin' -// Small helpers to allow fetching different types of data with `got` -const fetchBuffer = async url => (await got(url, { encoding: null })).body -const fetchText = async url => Buffer.from(await fetchBuffer(url), 'ascii') -const fetchJson = async url => JSON.parse(await fetchText(url)) - // Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker const fetch = url => Promise.resolve({ - text: () => fetchText(url), - arrayBuffer: () => fetchBuffer(url), - json: () => fetchJson(url) + text: () => + got(url) + .text() + .then(str => Buffer.from(str, 'ascii')), + arrayBuffer: () => got(url).buffer(), + json: () => got(url).json() }) const main = async () => { diff --git a/packages/screenshot/package.json b/packages/screenshot/package.json index 1f6e0b2388..60c9940c5a 100644 --- a/packages/screenshot/package.json +++ b/packages/screenshot/package.json @@ -28,7 +28,7 @@ ], "dependencies": { "@browserless/goto": "^5.22.0", - "got": "~9.6.0", + "got": "~10.4.0", "is-url-http": "~1.2.4", "p-reflect": "~2.1.0", "sharp": "~0.24.0", diff --git a/packages/screenshot/src/index.js b/packages/screenshot/src/index.js index ac672f5e4e..961d3fbc41 100644 --- a/packages/screenshot/src/index.js +++ b/packages/screenshot/src/index.js @@ -14,10 +14,7 @@ const BROWSER_THEMES = { } const getBackground = async (bg = 'transparent') => { - if (isHttpUrl(bg)) { - const { body } = await got(bg, { encoding: null }) - return body - } + if (isHttpUrl(bg)) return got(bg).buffer() if (!bg.includes('gradient')) { bg = `linear-gradient(45deg, ${bg} 0%, ${bg} 100%)` From dd6035b18ba28e954b45a91eab51a68c61d43391 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 4 Feb 2020 10:50:05 +0100 Subject: [PATCH 2/4] refactor: remove unnecessary code --- packages/goto/scripts/postinstall.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/goto/scripts/postinstall.js b/packages/goto/scripts/postinstall.js index 246fd883f5..657e7528e8 100644 --- a/packages/goto/scripts/postinstall.js +++ b/packages/goto/scripts/postinstall.js @@ -12,10 +12,7 @@ const OUTPUT_FILENAME = 'src/engine.bin' // Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker const fetch = url => Promise.resolve({ - text: () => - got(url) - .text() - .then(str => Buffer.from(str, 'ascii')), + text: () => got(url), arrayBuffer: () => got(url).buffer(), json: () => got(url).json() }) From f27ebaa57067e35117631803fd671b4b52c9d381 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 4 Feb 2020 10:59:08 +0100 Subject: [PATCH 3/4] refactor: remove text --- packages/goto/scripts/postinstall.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/goto/scripts/postinstall.js b/packages/goto/scripts/postinstall.js index 657e7528e8..c9a9c44abc 100644 --- a/packages/goto/scripts/postinstall.js +++ b/packages/goto/scripts/postinstall.js @@ -12,7 +12,6 @@ const OUTPUT_FILENAME = 'src/engine.bin' // Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker const fetch = url => Promise.resolve({ - text: () => got(url), arrayBuffer: () => got(url).buffer(), json: () => got(url).json() }) From 447829763cdf0c4412dcc47a373ad9f0c878ee6d Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 4 Feb 2020 11:04:22 +0100 Subject: [PATCH 4/4] build: keep .text just to be 1:1 with fetch interface --- packages/goto/scripts/postinstall.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/goto/scripts/postinstall.js b/packages/goto/scripts/postinstall.js index c9a9c44abc..657e7528e8 100644 --- a/packages/goto/scripts/postinstall.js +++ b/packages/goto/scripts/postinstall.js @@ -12,6 +12,7 @@ const OUTPUT_FILENAME = 'src/engine.bin' // Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker const fetch = url => Promise.resolve({ + text: () => got(url), arrayBuffer: () => got(url).buffer(), json: () => got(url).json() })