From 16581b7983b98da780445ef7f5561e74523c2989 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Tue, 10 Sep 2024 19:17:56 +0200 Subject: [PATCH 1/3] remove got, replace with undici --- package-lock.json | 305 +----------------- package.json | 3 +- src/cli/domain/registry.ts | 18 +- .../routes/helpers/is-url-discoverable.ts | 7 +- src/utils/put.ts | 8 +- test/acceptance/registry-ui.js | 10 +- test/acceptance/registry.js | 227 ++++++++----- .../registry/registry-with-fallback.js | 14 +- test/unit/cli-domain-registry.js | 34 +- test/unit/registry-routes-dependencies.js | 10 +- ...stry-routes-helpers-is-url-discoverable.js | 28 +- 11 files changed, 222 insertions(+), 442 deletions(-) diff --git a/package-lock.json b/package-lock.json index bdea6b867..4fc2ace9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,6 @@ "form-data": "^4.0.0", "fs-extra": "^11.2.0", "getport": "^0.1.0", - "got": "^11.8.5", "livereload": "^0.9.3", "lodash.isequal": "^4.5.0", "minimal-request": "^3.0.0", @@ -53,6 +52,7 @@ "serialize-error": "^8.1.0", "targz": "^1.0.1", "try-require": "^1.2.1", + "undici": "^6.19.8", "universalify": "^2.0.0", "yargs": "^17.7.2" }, @@ -67,7 +67,6 @@ "@types/errorhandler": "^1.5.3", "@types/express": "^4.17.21", "@types/fs-extra": "^11.0.4", - "@types/got": "^9.6.12", "@types/livereload": "^0.9.5", "@types/morgan": "^1.9.9", "@types/multer": "^1.4.12", @@ -2638,17 +2637,6 @@ "win32" ] }, - "node_modules/@sindresorhus/is": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", - "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/is?sponsor=1" - } - }, "node_modules/@sinonjs/commons": { "version": "1.8.6", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", @@ -2684,17 +2672,6 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, - "node_modules/@szmarczak/http-timer": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", - "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==", - "dependencies": { - "defer-to-connect": "^2.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@types/accept-language-parser": { "version": "1.5.6", "resolved": "https://registry.npmjs.org/@types/accept-language-parser/-/accept-language-parser-1.5.6.tgz", @@ -2730,17 +2707,6 @@ "@types/node": "*" } }, - "node_modules/@types/cacheable-request": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", - "integrity": "sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==", - "dependencies": { - "@types/http-cache-semantics": "*", - "@types/keyv": "^3.1.4", - "@types/node": "*", - "@types/responselike": "^1.0.0" - } - }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -2825,36 +2791,6 @@ "@types/node": "*" } }, - "node_modules/@types/got": { - "version": "9.6.12", - "resolved": "https://registry.npmjs.org/@types/got/-/got-9.6.12.tgz", - "integrity": "sha512-X4pj/HGHbXVLqTpKjA2ahI4rV/nNBc9mGO2I/0CgAra+F2dKgMXnENv2SRpemScBzBAI4vMelIVYViQxlSE6xA==", - "dev": true, - "dependencies": { - "@types/node": "*", - "@types/tough-cookie": "*", - "form-data": "^2.5.0" - } - }, - "node_modules/@types/got/node_modules/form-data": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", - "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, - "node_modules/@types/http-cache-semantics": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", - "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==" - }, "node_modules/@types/http-errors": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz", @@ -2875,14 +2811,6 @@ "@types/node": "*" } }, - "node_modules/@types/keyv": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", - "integrity": "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/livereload": { "version": "0.9.5", "resolved": "https://registry.npmjs.org/@types/livereload/-/livereload-0.9.5.tgz", @@ -2975,14 +2903,6 @@ "@types/node": "*" } }, - "node_modules/@types/responselike": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.3.tgz", - "integrity": "sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/semver": { "version": "7.5.8", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", @@ -3038,12 +2958,6 @@ "@types/tar-fs": "*" } }, - "node_modules/@types/tough-cookie": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", - "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", - "dev": true - }, "node_modules/@types/ws": { "version": "8.5.9", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.9.tgz", @@ -4325,31 +4239,6 @@ "node": ">= 0.8" } }, - "node_modules/cacheable-lookup": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", - "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==", - "engines": { - "node": ">=10.6.0" - } - }, - "node_modules/cacheable-request": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.4.tgz", - "integrity": "sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg==", - "dependencies": { - "clone-response": "^1.0.2", - "get-stream": "^5.1.0", - "http-cache-semantics": "^4.0.0", - "keyv": "^4.0.0", - "lowercase-keys": "^2.0.0", - "normalize-url": "^6.0.1", - "responselike": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -4532,17 +4421,6 @@ "node": ">=12" } }, - "node_modules/clone-response": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz", - "integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==", - "dependencies": { - "mimic-response": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -4760,31 +4638,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/decompress-response": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", - "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", - "dependencies": { - "mimic-response": "^3.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/decompress-response/node_modules/mimic-response": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", - "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/deep-eql": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", @@ -4797,14 +4650,6 @@ "node": ">=6" } }, - "node_modules/defer-to-connect": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", - "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", - "engines": { - "node": ">=10" - } - }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -5436,20 +5281,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "dependencies": { - "pump": "^3.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/getport": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/getport/-/getport-0.1.0.tgz", @@ -5503,30 +5334,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/got": { - "version": "11.8.5", - "resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz", - "integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==", - "dependencies": { - "@sindresorhus/is": "^4.0.0", - "@szmarczak/http-timer": "^4.0.5", - "@types/cacheable-request": "^6.0.1", - "@types/responselike": "^1.0.0", - "cacheable-lookup": "^5.0.3", - "cacheable-request": "^7.0.2", - "decompress-response": "^6.0.0", - "http2-wrapper": "^1.0.0-beta.5.2", - "lowercase-keys": "^2.0.0", - "p-cancelable": "^2.0.0", - "responselike": "^2.0.0" - }, - "engines": { - "node": ">=10.19.0" - }, - "funding": { - "url": "https://github.com/sindresorhus/got?sponsor=1" - } - }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -5661,11 +5468,6 @@ "node": ">=0.10.0" } }, - "node_modules/http-cache-semantics": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", - "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" - }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -5682,18 +5484,6 @@ "node": ">= 0.8" } }, - "node_modules/http2-wrapper": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz", - "integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==", - "dependencies": { - "quick-lru": "^5.1.1", - "resolve-alpn": "^1.0.0" - }, - "engines": { - "node": ">=10.19.0" - } - }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -5930,11 +5720,6 @@ "jsesc": "bin/jsesc" } }, - "node_modules/json-buffer": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", - "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==" - }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", @@ -6086,14 +5871,6 @@ "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", "dev": true }, - "node_modules/keyv": { - "version": "4.5.4", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", - "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", - "dependencies": { - "json-buffer": "3.0.1" - } - }, "node_modules/kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -6406,14 +6183,6 @@ "get-func-name": "^2.0.1" } }, - "node_modules/lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", - "engines": { - "node": ">=8" - } - }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -6563,14 +6332,6 @@ "node": ">= 0.6" } }, - "node_modules/mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "engines": { - "node": ">=4" - } - }, "node_modules/minimal-request": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/minimal-request/-/minimal-request-3.0.0.tgz", @@ -6916,17 +6677,6 @@ "node": ">=0.10.0" } }, - "node_modules/normalize-url": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", - "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -7819,14 +7569,6 @@ "node": ">=0.10.0" } }, - "node_modules/p-cancelable": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", - "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", - "engines": { - "node": ">=8" - } - }, "node_modules/p-locate": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", @@ -8095,15 +7837,6 @@ "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", "integrity": "sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==" }, - "node_modules/pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -8127,17 +7860,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/quick-lru": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", - "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -8294,11 +8016,6 @@ "resolved": "https://registry.npmjs.org/require-package-name/-/require-package-name-2.0.1.tgz", "integrity": "sha512-uuoJ1hU/k6M0779t3VMVIYpb2VMJk05cehCaABFhXaibcbvfgR8wKiozLjVFSzJPmQMRqIcO0HMyTFqfV09V6Q==" }, - "node_modules/resolve-alpn": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", - "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==" - }, "node_modules/response-time": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/response-time/-/response-time-2.3.2.tgz", @@ -8319,17 +8036,6 @@ "node": ">= 0.6" } }, - "node_modules/responselike": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz", - "integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==", - "dependencies": { - "lowercase-keys": "^2.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/right-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", @@ -9107,6 +8813,15 @@ "integrity": "sha512-vb2s1lYx2xBtUgy+ta+b2J/GLVUR+wmpINwHePmPRhOsIVCG2wDzKJ0n14GslH1BifsqVzSOwQhRaCAsZ/nI4Q==", "optional": true }, + "node_modules/undici": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", + "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, "node_modules/undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", diff --git a/package.json b/package.json index 8413cdede..f2878898f 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "@types/errorhandler": "^1.5.3", "@types/express": "^4.17.21", "@types/fs-extra": "^11.0.4", - "@types/got": "^9.6.12", "@types/livereload": "^0.9.5", "@types/morgan": "^1.9.9", "@types/multer": "^1.4.12", @@ -90,7 +89,6 @@ "form-data": "^4.0.0", "fs-extra": "^11.2.0", "getport": "^0.1.0", - "got": "^11.8.5", "livereload": "^0.9.3", "lodash.isequal": "^4.5.0", "minimal-request": "^3.0.0", @@ -119,6 +117,7 @@ "serialize-error": "^8.1.0", "targz": "^1.0.1", "try-require": "^1.2.1", + "undici": "^6.19.8", "universalify": "^2.0.0", "yargs": "^17.7.2" } diff --git a/src/cli/domain/registry.ts b/src/cli/domain/registry.ts index 676f7fe0c..9c49c830e 100644 --- a/src/cli/domain/registry.ts +++ b/src/cli/domain/registry.ts @@ -1,6 +1,6 @@ import path from 'node:path'; import fs from 'fs-extra'; -import got from 'got'; +import { request } from 'undici'; import * as urlBuilder from '../../registry/domain/url-builder'; import settings from '../../resources/settings'; @@ -32,9 +32,11 @@ export default function registry(opts: RegistryOptions = {}) { registry += '/'; } try { - const apiResponse: { type: string } = await got(registry, { - headers: requestsHeaders - }).json(); + const apiResponse: { type: string } = (await ( + await request(registry, { + headers: requestsHeaders + }) + ).body.json()) as any; if (!apiResponse) throw 'oc registry not available'; if (apiResponse.type !== 'oc-registry') throw 'not a valid oc registry'; @@ -73,15 +75,15 @@ export default function registry(opts: RegistryOptions = {}) { } }, getApiComponentByHref(href: string): Promise { - return got(href + settings.registry.componentInfoPath, { + return request(href + settings.registry.componentInfoPath, { headers: requestsHeaders - }).json(); + }).then((x) => x.body.json() as any); }, async getComponentPreviewUrlByUrl(componentHref: string): Promise { - const res: { requestVersion: string; href: string } = await got( + const res: { requestVersion: string; href: string } = await request( componentHref, { headers: requestsHeaders } - ).json(); + ).then((x) => x.body.json() as any); const parsed = urlParser.parse(res); diff --git a/src/registry/routes/helpers/is-url-discoverable.ts b/src/registry/routes/helpers/is-url-discoverable.ts index fe4e13b40..8e11d361e 100644 --- a/src/registry/routes/helpers/is-url-discoverable.ts +++ b/src/registry/routes/helpers/is-url-discoverable.ts @@ -1,12 +1,11 @@ -import got from 'got'; +import { request } from 'undici'; export default async function isUrlDiscoverable( url: string ): Promise<{ isDiscoverable: boolean }> { try { - const res = await got(url, { - headers: { accept: 'text/html' } - }); + const res = await request(url, { headers: { accept: 'text/html' } }); + const isHtml = !!res.headers['content-type']?.includes('text/html'); return { diff --git a/src/utils/put.ts b/src/utils/put.ts index 49fc19539..4c2e4d11b 100644 --- a/src/utils/put.ts +++ b/src/utils/put.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import FormData from 'form-data'; import fs from 'fs-extra'; -import got from 'got'; +import { request } from 'undici'; async function put( urlPath: string, @@ -19,17 +19,17 @@ async function put( form.append(fileName, fs.createReadStream(file)); } - const res = await got(urlPath, { + const res = await request(urlPath, { headers: { ...headers, ...form.getHeaders() }, method: 'PUT', body: form }); if (res.statusCode !== 200) { - throw res.body; + throw res.body.text(); } - return res.body; + return res.body.text(); } export default put; diff --git a/test/acceptance/registry-ui.js b/test/acceptance/registry-ui.js index e8b79339a..b621ce069 100644 --- a/test/acceptance/registry-ui.js +++ b/test/acceptance/registry-ui.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const oc = require('../../dist/index'); const path = require('node:path'); -const got = require('got'); +const { request } = require('undici'); describe('registry (ui interface)', () => { let registry; @@ -11,9 +11,9 @@ describe('registry (ui interface)', () => { const next = (promise, done) => { promise - .then((r) => { + .then(async (r) => { headers = r.headers; - result = r.body; + result = await r.body.text(); }) .catch((e) => { error = e; @@ -44,7 +44,7 @@ describe('registry (ui interface)', () => { describe('GET / with Accept: text/html', () => { before((done) => { next( - got('http://localhost:3030', { + request('http://localhost:3030', { headers: { accept: 'text/html' } }), done @@ -64,7 +64,7 @@ describe('registry (ui interface)', () => { describe('GET /oc-client/~info with Accept: text/html', () => { before((done) => { next( - got('http://localhost:3030/oc-client/~info', { + request('http://localhost:3030/oc-client/~info', { headers: { accept: 'text/html' } }), done diff --git a/test/acceptance/registry.js b/test/acceptance/registry.js index ce9653772..e1772b533 100644 --- a/test/acceptance/registry.js +++ b/test/acceptance/registry.js @@ -1,7 +1,7 @@ const expect = require('chai').expect; const emptyResponseHandler = require('oc-empty-response-handler'); const path = require('node:path'); -const got = require('got'); +const { request } = require('undici'); describe('registry', () => { let registry; @@ -13,10 +13,10 @@ describe('registry', () => { const next = (promise, done) => { promise - .then((r) => { + .then(async (r) => { headers = r.headers; status = r.statusCode; - result = JSON.parse(r.body); + result = await r.body.json(); }) .finally(done); }; @@ -58,7 +58,7 @@ describe('registry', () => { describe('with the default configuration (no customHeadersToSkipOnWeakVersion defined) and strong version 1.0.0', () => { before((done) => { next( - got('http://localhost:3030/hello-world-custom-headers/1.0.0'), + request('http://localhost:3030/hello-world-custom-headers/1.0.0'), done ); }); @@ -78,7 +78,7 @@ describe('registry', () => { describe('with the default configuration (no customHeadersToSkipOnWeakVersion defined) and weak version 1.x.x', () => { before((done) => { next( - got('http://localhost:3030/hello-world-custom-headers/1.x.x'), + request('http://localhost:3030/hello-world-custom-headers/1.x.x'), done ); }); @@ -116,7 +116,7 @@ describe('registry', () => { describe('when strong version is requested 1.0.0', () => { before((done) => { next( - got('http://localhost:3030/hello-world-custom-headers/1.0.0'), + request('http://localhost:3030/hello-world-custom-headers/1.0.0'), done ); }); @@ -136,7 +136,7 @@ describe('registry', () => { describe('when weak version is requested 1.x.x', () => { before((done) => { next( - got('http://localhost:3030/hello-world-custom-headers/1.x.x'), + request('http://localhost:3030/hello-world-custom-headers/1.x.x'), done ); }); @@ -156,16 +156,19 @@ describe('registry', () => { describe('with the default configuration (no customHeadersToSkipOnWeakVersion defined) and strong version 1.0.0', () => { before((done) => { next( - got('http://localhost:3030', { - method: 'post', - json: { + request('http://localhost:3030', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'hello-world-custom-headers', version: '1.0.0' } ] - } + }) }), done ); @@ -189,9 +192,12 @@ describe('registry', () => { describe('request with two components', () => { before((done) => { next( - got('http://localhost:3030', { - method: 'post', - json: { + request('http://localhost:3030', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'hello-world-custom-headers', @@ -202,7 +208,7 @@ describe('registry', () => { version: '1.0.0' } ] - } + }) }), done ); @@ -216,16 +222,19 @@ describe('registry', () => { describe('with the default configuration (no customHeadersToSkipOnWeakVersion defined) and weak version 1.x.x', () => { before((done) => { next( - got('http://localhost:3030', { - method: 'post', - json: { + request('http://localhost:3030', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'hello-world-custom-headers', version: '1.x.x' } ] - } + }) }), done ); @@ -267,16 +276,19 @@ describe('registry', () => { describe('when strong version is requested 1.0.0', () => { before((done) => { next( - got('http://localhost:3030', { - method: 'post', - json: { + request('http://localhost:3030', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'hello-world-custom-headers', version: '1.0.0' } ] - } + }) }), done ); @@ -302,16 +314,19 @@ describe('registry', () => { describe('when weak version is requested 1.x.x', () => { before((done) => { next( - got('http://localhost:3030', { - method: 'post', - json: { + request('http://localhost:3030', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'hello-world-custom-headers', version: '1.x.x' } ] - } + }) }), done ); @@ -336,7 +351,7 @@ describe('registry', () => { describe('GET /', () => { before((done) => { - next(got('http://localhost:3030'), done); + next(request('http://localhost:3030'), done); }); it('should respond with the correct href', () => { @@ -366,10 +381,15 @@ describe('registry', () => { describe('POST / (with circular-json)', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - headers: { accept: 'application/vnd.oc.unrendered+json' }, - json: { components: [{ name: 'circular-json-error' }] }, + request('http://localhost:3030/', { + method: 'POST', + headers: { + accept: 'application/vnd.oc.unrendered+json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + components: [{ name: 'circular-json-error' }] + }), throwHttpErrors: false }), done @@ -390,7 +410,7 @@ describe('registry', () => { describe('GET /circular-json-error', () => { before((done) => { next( - got('http://localhost:3030/circular-json-error', { + request('http://localhost:3030/circular-json-error', { headers: { accept: 'application/vnd.oc.unrendered+json' }, throwHttpErrors: false }), @@ -412,7 +432,7 @@ describe('registry', () => { describe('GET /handlebars3-component', () => { before((done) => { next( - got('http://localhost:3030/handlebars3-component', { + request('http://localhost:3030/handlebars3-component', { throwHttpErrors: false }), done @@ -432,7 +452,7 @@ describe('registry', () => { describe('GET /jade-filters', () => { before((done) => { - next(got('http://localhost:3030/jade-filters'), done); + next(request('http://localhost:3030/jade-filters'), done); }); it('should respond with 200 status code', () => { @@ -443,7 +463,7 @@ describe('registry', () => { describe('GET /hello-world', () => { describe('when Accept header not specified', () => { before((done) => { - next(got('http://localhost:3030/hello-world'), done); + next(request('http://localhost:3030/hello-world'), done); }); it('should respond with the correct href', () => { @@ -477,7 +497,7 @@ describe('registry', () => { describe('when Accept header set to application/vnd.oc.unrendered+json', () => { before((done) => { next( - got('http://localhost:3030/hello-world', { + request('http://localhost:3030/hello-world', { headers: { Accept: 'application/vnd.oc.unrendered+json' } }), done @@ -512,7 +532,7 @@ describe('registry', () => { describe('GET /container-with-nested', () => { before((done) => { - next(got('http://localhost:3030/container-with-nested'), done); + next(request('http://localhost:3030/container-with-nested'), done); }); it('should respond with the correct href', () => { @@ -532,7 +552,10 @@ describe('registry', () => { describe('GET /container-with-multiple-nested', () => { before((done) => { - next(got('http://localhost:3030/container-with-multiple-nested'), done); + next( + request('http://localhost:3030/container-with-multiple-nested'), + done + ); }); it('should respond with the correct href', () => { @@ -555,7 +578,7 @@ describe('registry', () => { describe('GET /no-containers', () => { describe('when Accept header not specified', () => { before((done) => { - next(got('http://localhost:3030/no-containers'), done); + next(request('http://localhost:3030/no-containers'), done); }); it('should respond with the correct href', () => { @@ -577,7 +600,7 @@ describe('registry', () => { describe('when Accept-Language: en-US', () => { before((done) => { next( - got('http://localhost:3030/language', { + request('http://localhost:3030/language', { headers: { 'accept-language': 'en-US' } }), done @@ -596,7 +619,7 @@ describe('registry', () => { describe('when Accept-Language: ja-JP', () => { before((done) => { next( - got('http://localhost:3030/language', { + request('http://localhost:3030/language', { headers: { 'accept-language': 'ja-JP' } }), done @@ -615,7 +638,7 @@ describe('registry', () => { describe('when Accept-Language: ja-JP but __ocAcceptLanguage overrides with en-US (client-side failover)', () => { before((done) => { next( - got('http://localhost:3030/language/?__ocAcceptLanguage=en-US', { + request('http://localhost:3030/language/?__ocAcceptLanguage=en-US', { headers: { 'accept-language': 'ja-JP' } }), done @@ -634,7 +657,7 @@ describe('registry', () => { describe('GET /lodash-component', () => { before((done) => { - next(got('http://localhost:3030/lodash-component'), done); + next(request('http://localhost:3030/lodash-component'), done); }); it('should respond with the correct href', () => { @@ -649,7 +672,7 @@ describe('registry', () => { describe('GET /empty', () => { describe('rendered', () => { before((done) => { - next(got('http://localhost:3030/empty'), done); + next(request('http://localhost:3030/empty'), done); }); it('should respond with the correct href', () => { @@ -664,7 +687,7 @@ describe('registry', () => { describe('unrendered', () => { before((done) => { next( - got('http://localhost:3030/empty', { + request('http://localhost:3030/empty', { headers: { Accept: 'application/vnd.oc.unrendered+json' } }), done @@ -687,9 +710,12 @@ describe('registry', () => { describe('when body is malformed', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: {}, + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: '{}', throwHttpErrors: false }), done @@ -711,11 +737,14 @@ describe('registry', () => { describe('when Accept header not specified', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [{ name: 'hello-world' }, { name: 'no-containers' }] - } + }) }), done ); @@ -740,15 +769,18 @@ describe('registry', () => { describe('when getting rendered components', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ omitHref: true, components: [ { name: 'hello-world' }, { name: 'no-containers' } ] - } + }) }), done ); @@ -763,16 +795,19 @@ describe('registry', () => { describe('when getting unrendered components', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - headers: { Accept: 'application/vnd.oc.unrendered+json' }, - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + Accept: 'application/vnd.oc.unrendered+json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ omitHref: true, components: [ { name: 'hello-world' }, { name: 'no-containers' } ] - } + }) }), done ); @@ -788,12 +823,15 @@ describe('registry', () => { describe('when Accept header set to application/vnd.oc.unrendered+json', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - headers: { Accept: 'application/vnd.oc.unrendered+json' }, - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + Accept: 'application/vnd.oc.unrendered+json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [{ name: 'hello-world' }, { name: 'no-containers' }] - } + }) }), done ); @@ -811,9 +849,12 @@ describe('registry', () => { describe('when each component requires different params', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ components: [ { name: 'welcome', @@ -824,7 +865,7 @@ describe('registry', () => { parameters: { firstName: 'Donald', lastName: 'Duck' } } ] - } + }) }), done ); @@ -843,12 +884,15 @@ describe('registry', () => { describe('when components require same parameters', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ parameters: { firstName: 'Donald', lastName: 'Duck' }, components: [{ name: 'welcome' }, { name: 'welcome' }] - } + }) }), done ); @@ -867,15 +911,18 @@ describe('registry', () => { describe('when components have some common parameters and some different', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ parameters: { firstName: 'Donald' }, components: [ { name: 'welcome', parameters: { lastName: 'Mouse' } }, { name: 'welcome', parameters: { lastName: 'Duck' } } ] - } + }) }), done ); @@ -894,15 +941,18 @@ describe('registry', () => { describe('when components have global parameters with local overrides', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ parameters: { firstName: 'Donald', lastName: 'Duck' }, components: [ { name: 'welcome', parameters: { lastName: 'Mouse' } }, { name: 'welcome' } ] - } + }) }), done ); @@ -921,9 +971,12 @@ describe('registry', () => { describe('when components accept optional parameters', () => { before((done) => { next( - got('http://localhost:3030/', { - method: 'post', - json: { + request('http://localhost:3030/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ parameters: { firstName: 'John' }, components: [ { @@ -943,7 +996,7 @@ describe('registry', () => { parameters: { nick: 'smithy' } } ] - } + }) }), done ); diff --git a/test/acceptance/registry/registry-with-fallback.js b/test/acceptance/registry/registry-with-fallback.js index 9e37a334e..bc40252b1 100644 --- a/test/acceptance/registry/registry-with-fallback.js +++ b/test/acceptance/registry/registry-with-fallback.js @@ -1,6 +1,6 @@ const expect = require('chai').expect; const path = require('node:path'); -const got = require('got'); +const { request } = require('undici'); describe('registry', () => { describe('when fallbackRegistryUrl is specified', () => { @@ -28,8 +28,8 @@ describe('registry', () => { const next = (promise, done) => { promise - .then((r) => { - result = JSON.parse(r.body); + .then(async (r) => { + result = await r.body.json(); }) .finally(done); }; @@ -61,7 +61,7 @@ describe('registry', () => { describe('GET /welcome', () => { before((done) => { - next(got('http://localhost:3030/welcome'), done); + next(request('http://localhost:3030/welcome'), done); }); it('should respond with the local registry url', () => { @@ -75,7 +75,7 @@ describe('registry', () => { describe('GET /fallback-hello-world', () => { before((done) => { - next(got('http://localhost:3030/fallback-hello-world'), done); + next(request('http://localhost:3030/fallback-hello-world'), done); }); it('should respond with the fallback registry url', () => { @@ -92,7 +92,7 @@ describe('registry', () => { describe('GET /fallback-hello-world/~info', () => { before((done) => { next( - got( + request( 'http://localhost:3030/fallback-welcome-with-optional-parameters/~info' ), done @@ -111,7 +111,7 @@ describe('registry', () => { describe('GET /fallback-hello-world/~preview', () => { before((done) => { next( - got( + request( 'http://localhost:3030/fallback-welcome-with-optional-parameters/~preview' ), done diff --git a/test/unit/cli-domain-registry.js b/test/unit/cli-domain-registry.js index 4439ed409..e0cae7b06 100644 --- a/test/unit/cli-domain-registry.js +++ b/test/unit/cli-domain-registry.js @@ -8,7 +8,7 @@ const getRegistry = (dependencies, opts) => { const Registry = injectr( '../../dist/cli/domain/registry.js', { - got: dependencies.got, + undici: dependencies.undici, 'fs-extra': dependencies.fs, '../../utils/put': dependencies.put, '../domain/url-parser': dependencies.urlParser, @@ -47,19 +47,23 @@ describe('cli : domain : registry', () => { describe('when adding registry', () => { describe('when registry does not end with "/"', () => { it('should append the slash when doing the request', (done) => { - const gotStub = sinon.stub().rejects(new Error('err')); - const registry = getRegistry({ got: gotStub }); + const undiciStub = { request: sinon.stub().rejects(new Error('err')) }; + const registry = getRegistry({ undici: undiciStub }); registry.add('http://some-api.com/asd').finally(() => { - expect(gotStub.getCall(0).args[0]).to.eql('http://some-api.com/asd/'); + expect(undiciStub.request.getCall(0).args[0]).to.eql( + 'http://some-api.com/asd/' + ); done(); }); }); it('should save the file with slashed url', (done) => { - const gotStub = sinon.stub().returns({ - json: sinon.stub().resolves({ type: 'oc-registry' }) - }); + const undiciStub = { + request: sinon.stub().resolves({ + body: { json: sinon.stub().resolves({ type: 'oc-registry' }) } + }) + }; const fsStub = { readJson: sinon.stub(), writeJson: sinon.spy() @@ -68,7 +72,7 @@ describe('cli : domain : registry', () => { fsStub.readJson.resolves({}); const registry = getRegistry({ - got: gotStub, + undici: undiciStub, fs: fsStub }); @@ -154,11 +158,15 @@ describe('cli : domain : registry', () => { const execute = (href, error, parsed, done) => { const registry = getRegistry({ request: sinon.stub().yields(error, parsed), - got: sinon.stub().returns({ - json: error - ? sinon.stub().rejects(error) - : sinon.stub().resolves(parsed) - }), + undici: { + request: sinon.stub().resolves({ + body: { + json: error + ? sinon.stub().rejects(error) + : sinon.stub().resolves(parsed) + } + }) + }, urlParser: { parse: sinon.stub().returns(parsed) } diff --git a/test/unit/registry-routes-dependencies.js b/test/unit/registry-routes-dependencies.js index 9c93cb3bf..95ee68c8f 100644 --- a/test/unit/registry-routes-dependencies.js +++ b/test/unit/registry-routes-dependencies.js @@ -9,8 +9,8 @@ describe('registry : routes : plugins', () => { name: 'fs', link: 'http://link1.com' }, - got: { - name: 'got', + undici: { + name: 'undici', version: '1.2.3', core: false, link: 'http://link2.com' @@ -37,7 +37,7 @@ describe('registry : routes : plugins', () => { before(() => { initialise(); const conf = { - dependencies: ['fs', 'got'], + dependencies: ['fs', 'undici'], discovery: false }; dependenciesRoute = DependenciesRoute(conf); @@ -54,7 +54,7 @@ describe('registry : routes : plugins', () => { before(() => { initialise(); const conf = { - dependencies: ['fs', 'got'], + dependencies: ['fs', 'undici'], discovery: true }; dependenciesRoute = DependenciesRoute(conf); @@ -65,7 +65,7 @@ describe('registry : routes : plugins', () => { it('should return the list of dependencies', () => { expect(resJsonStub.args[0][0]).to.eql([ { name: 'fs', core: true }, - { name: 'got', core: false, versions: ['1.2.3'] } + { name: 'undici', core: false, versions: ['1.2.3'] } ]); }); }); diff --git a/test/unit/registry-routes-helpers-is-url-discoverable.js b/test/unit/registry-routes-helpers-is-url-discoverable.js index 0b5825b3e..083bd3745 100644 --- a/test/unit/registry-routes-helpers-is-url-discoverable.js +++ b/test/unit/registry-routes-helpers-is-url-discoverable.js @@ -8,12 +8,14 @@ describe('registry : routes : helpers : is-url-discoverable', () => { const isDiscoverable = injectr( '../../dist/registry/routes/helpers/is-url-discoverable.js', { - got: () => - Promise.resolve({ - headers: { - 'content-type': 'application/json; charset=utf-8' - } - }) + undici: { + request: () => + Promise.resolve({ + headers: { + 'content-type': 'application/json; charset=utf-8' + } + }) + } } ).default; @@ -35,12 +37,14 @@ describe('registry : routes : helpers : is-url-discoverable', () => { const isDiscoverable = injectr( '../../dist/registry/routes/helpers/is-url-discoverable.js', { - got: () => - Promise.resolve({ - headers: { - 'content-type': 'text/html; charset=utf-8' - } - }) + undici: { + request: () => + Promise.resolve({ + headers: { + 'content-type': 'text/html; charset=utf-8' + } + }) + } } ).default; From 90b0e063c3b9b8fe74dfe364282d42308e60bbdf Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Tue, 10 Sep 2024 22:11:46 +0200 Subject: [PATCH 2/3] remove minimal-request pkg in favour of undici too --- package-lock.json | 1 - package.json | 3 +- src/globals.d.ts | 25 ----- .../routes/helpers/get-component-fallback.ts | 98 +++++++++++-------- 4 files changed, 59 insertions(+), 68 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4fc2ace9b..6423c1a84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,6 @@ "getport": "^0.1.0", "livereload": "^0.9.3", "lodash.isequal": "^4.5.0", - "minimal-request": "^3.0.0", "morgan": "^1.10.0", "multer": "^1.4.3", "nice-cache": "^0.0.5", diff --git a/package.json b/package.json index f2878898f..664c74447 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,6 @@ "getport": "^0.1.0", "livereload": "^0.9.3", "lodash.isequal": "^4.5.0", - "minimal-request": "^3.0.0", "morgan": "^1.10.0", "multer": "^1.4.3", "nice-cache": "^0.0.5", @@ -121,4 +120,4 @@ "universalify": "^2.0.0", "yargs": "^17.7.2" } -} \ No newline at end of file +} diff --git a/src/globals.d.ts b/src/globals.d.ts index 79f4f8be4..e148f8ead 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -76,28 +76,3 @@ declare module 'nice-cache' { export = Cache; } - -declare module 'minimal-request' { - function request( - opts: { - method?: string; - body?: unknown; - url: string; - headers?: Record; - json?: boolean; - }, - cb: ( - err: Error | number | null, - body: T, - details: { - response: { - headers: Record; - }; - } - ) => void - ): void; - - const req: Request; - - export = request; -} diff --git a/src/registry/routes/helpers/get-component-fallback.ts b/src/registry/routes/helpers/get-component-fallback.ts index 4272a53da..8f46d174b 100644 --- a/src/registry/routes/helpers/get-component-fallback.ts +++ b/src/registry/routes/helpers/get-component-fallback.ts @@ -1,7 +1,6 @@ import type { IncomingHttpHeaders } from 'node:http'; -import url from 'node:url'; import type { Request, Response } from 'express'; -import request from 'minimal-request'; +import { type Dispatcher, request } from 'undici'; import type { Component, Config } from '../../../types'; import * as urlBuilder from '../../domain/url-builder'; import type { GetComponentResult } from './get-component'; @@ -34,31 +33,21 @@ function getComponentFallbackForViewType( conf.fallbackRegistryUrl ); - return request( - { - method: 'get', - url: path, - headers: { - ...req.headers, - host: url.parse(conf.fallbackRegistryUrl).host, - accept: 'application/json' - } - }, - (fallbackErr, fallbackResponse: string) => { - if (fallbackErr === 304) { - return res.status(304).send(''); - } - - if (fallbackErr) { - return callback( - { - registryError: registryError, - fallbackError: fallbackErr - }, - undefined as any - ); + return request(path, { + method: 'GET', + headers: { + ...req.headers, + host: new URL(conf.fallbackRegistryUrl).host, + accept: 'application/json' + } + }) + .then((response) => { + if (response.statusCode !== 200) { + throw response; } - + return response.body.text(); + }) + .then((fallbackResponse) => { try { return callback(null, JSON.parse(fallbackResponse)); } catch (parseError) { @@ -70,8 +59,22 @@ function getComponentFallbackForViewType( undefined as any ); } - } - ); + }) + .catch(async (response: Dispatcher.ResponseData) => { + if (response.statusCode === 304) { + return res.status(304).send(''); + } + + return callback( + { + registryError: registryError, + fallbackError: await response.body + .text() + .catch(() => response.statusCode) + }, + undefined as any + ); + }); } export function getComponent( @@ -80,28 +83,43 @@ export function getComponent( component: { name: string; version: string; parameters: IncomingHttpHeaders }, callback: (result: GetComponentResult) => void ): void { - request( - { - method: 'post', - url: fallbackRegistryUrl, - headers: { ...headers, host: url.parse(fallbackRegistryUrl).host }, - json: true, - body: { components: [component] } + request(fallbackRegistryUrl, { + method: 'POST', + headers: { + ...headers, + host: new URL(fallbackRegistryUrl).host, + 'Content-Type': 'application/json' }, - (err, res: GetComponentResult[]) => { - if (err || !res || res.length === 0) { + body: JSON.stringify({ components: [component] }) + }) + .then((response) => { + if (response.statusCode !== 200) { + throw response; + } + return response.body.json() as any; + }) + .then((res: GetComponentResult[]) => { + if (!res || res.length === 0) { return callback({ status: 404, response: { code: 'NOT_FOUND', - error: err as any + error: 'Component not found' } }); } return callback(res[0]); - } - ); + }) + .catch(async (err: Dispatcher.ResponseData) => { + return callback({ + status: 404, + response: { + code: 'NOT_FOUND', + error: await err.body.text().catch(() => err.statusCode) + } + }); + }); } export function getComponentPreview( From 2604eefc4d3914ca50e3888af3c65954cfddbbfe Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Tue, 10 Sep 2024 23:48:34 +0200 Subject: [PATCH 3/3] fix tests for node 18 --- test/acceptance/registry.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/test/acceptance/registry.js b/test/acceptance/registry.js index e1772b533..65b236944 100644 --- a/test/acceptance/registry.js +++ b/test/acceptance/registry.js @@ -97,14 +97,15 @@ describe('registry', () => { describe('with a custom configuration with customHeadersToSkipOnWeakVersion defined', () => { before((done) => { - registry.close(); - initializeRegistry( - { - ...getDefaultTestConfiguration(), - customHeadersToSkipOnWeakVersion: ['Cache-Control'] - }, - done - ); + registry.close(() => { + initializeRegistry( + { + ...getDefaultTestConfiguration(), + customHeadersToSkipOnWeakVersion: ['Cache-Control'] + }, + done + ); + }); }); after((done) => { @@ -257,14 +258,15 @@ describe('registry', () => { describe('with a custom configuration with customHeadersToSkipOnWeakVersion defined', () => { before((done) => { - registry.close(); - initializeRegistry( - { - ...getDefaultTestConfiguration(), - customHeadersToSkipOnWeakVersion: ['Cache-Control'] - }, - done - ); + registry.close(() => { + initializeRegistry( + { + ...getDefaultTestConfiguration(), + customHeadersToSkipOnWeakVersion: ['Cache-Control'] + }, + done + ); + }); }); after((done) => {