From dea96237bb341ea9278c19531fb890ed88123f49 Mon Sep 17 00:00:00 2001 From: theothirteen Date: Sat, 6 May 2023 16:26:56 +0530 Subject: [PATCH] Removed node-fetch package and used native fetch --- package-lock.json | 241 ++++++++++++++++++++------------------- package.json | 4 +- src/cli.ts | 6 +- src/goods.ts | 19 ++- src/util.ts | 3 + test/cli.test.js | 7 ++ test/goods.test.js | 5 + test/utils/test-utils.js | 18 +++ tsconfig.json | 2 +- 9 files changed, 175 insertions(+), 130 deletions(-) create mode 100644 test/utils/test-utils.js diff --git a/package-lock.json b/package-lock.json index 73799b4159..8cd516d1d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,6 @@ "fx": "*", "globby": "^13.1.4", "minimist": "^1.2.8", - "node-fetch": "3.3.1", "ps-tree": "^1.2.0", "webpod": "^0", "which": "^3.0.0", @@ -30,6 +29,7 @@ }, "devDependencies": { "@stryker-mutator/core": "^6.4.2", + "@types/node-fetch": "^2.6.3", "c8": "^7.13.0", "madge": "^6.0.0", "prettier": "^2.8.8", @@ -982,6 +982,16 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.3.tgz", "integrity": "sha512-OPs5WnnT1xkCBiuQrZA4+YAV4HEJejmHneyraIaxsbev5yCEr6KMwINNFP9wQeFIw8FWcoTqF3vQsa5CDaI+8Q==" }, + "node_modules/@types/node-fetch": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.3.tgz", + "integrity": "sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^3.0.0" + } + }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", @@ -1190,6 +1200,12 @@ "node": ">=6.0" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1563,6 +1579,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", @@ -1622,14 +1650,6 @@ "node": ">= 8" } }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", - "engines": { - "node": ">= 12" - } - }, "node_modules/date-format": { "version": "4.0.14", "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", @@ -1711,6 +1731,15 @@ "clone": "^1.0.2" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dependency-tree": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/dependency-tree/-/dependency-tree-9.0.0.tgz", @@ -2381,28 +2410,6 @@ "reusify": "^1.0.4" } }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/figures": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-5.0.0.tgz", @@ -2530,15 +2537,18 @@ "node": ">=8.0.0" } }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "node_modules/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, "dependencies": { - "fetch-blob": "^3.1.2" + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" }, "engines": { - "node": ">=12.20.0" + "node": ">= 6" } }, "node_modules/from": { @@ -3718,6 +3728,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-fn": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", @@ -3934,41 +3965,6 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, - "node_modules/node-fetch": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", - "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, "node_modules/node-releases": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", @@ -6021,14 +6017,6 @@ "integrity": "sha512-V8X6hPIzY1juvrSVREmtRhK9AHn/8c2z8XxaibESU+jyG/RinZ9x9x6aw8qEuFAi7R6Kl/EWGbU2Yq/9u6TTjw==", "dev": true }, - "node_modules/web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", - "engines": { - "node": ">= 8" - } - }, "node_modules/webpod": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/webpod/-/webpod-0.0.2.tgz", @@ -6916,6 +6904,16 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.3.tgz", "integrity": "sha512-OPs5WnnT1xkCBiuQrZA4+YAV4HEJejmHneyraIaxsbev5yCEr6KMwINNFP9wQeFIw8FWcoTqF3vQsa5CDaI+8Q==" }, + "@types/node-fetch": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.3.tgz", + "integrity": "sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^3.0.0" + } + }, "@types/normalize-package-data": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", @@ -7057,6 +7055,12 @@ "integrity": "sha512-CMxMCOCS+4D+DkOQfuZf+vLrSEmY/7xtORwdxs4wtcC1wVgvk2MqFFTwQCFhvWsI4KPU9lcWXPI8DgRiz+xetQ==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -7307,6 +7311,15 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", @@ -7356,11 +7369,6 @@ } } }, - "data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" - }, "date-format": { "version": "4.0.14", "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", @@ -7421,6 +7429,12 @@ "clone": "^1.0.2" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "dependency-tree": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/dependency-tree/-/dependency-tree-9.0.0.tgz", @@ -7917,15 +7931,6 @@ "reusify": "^1.0.4" } }, - "fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "requires": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - } - }, "figures": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-5.0.0.tgz", @@ -8017,12 +8022,15 @@ "signal-exit": "^3.0.2" } }, - "formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, "requires": { - "fetch-blob": "^3.1.2" + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" } }, "from": { @@ -8859,6 +8867,21 @@ "picomatch": "^2.3.1" } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "mimic-fn": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", @@ -9022,21 +9045,6 @@ "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", "dev": true }, - "node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" - }, - "node-fetch": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", - "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", - "requires": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - } - }, "node-releases": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", @@ -10510,11 +10518,6 @@ "integrity": "sha512-V8X6hPIzY1juvrSVREmtRhK9AHn/8c2z8XxaibESU+jyG/RinZ9x9x6aw8qEuFAi7R6Kl/EWGbU2Yq/9u6TTjw==", "dev": true }, - "web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" - }, "webpod": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/webpod/-/webpod-0.0.2.tgz", diff --git a/package.json b/package.json index 2a3a72e610..80edc39743 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "fx": "*", "globby": "^13.1.4", "minimist": "^1.2.8", - "node-fetch": "3.3.1", "ps-tree": "^1.2.0", "webpod": "^0", "which": "^3.0.0", @@ -74,7 +73,8 @@ "prettier": "^2.8.8", "tsd": "^0.28.1", "typescript": "^5.0.4", - "uvu": "^0.5.6" + "uvu": "^0.5.6", + "@types/node-fetch":"^2.6.3" }, "publishConfig": { "registry": "https://wombat-dressing-room.appspot.com" diff --git a/src/cli.ts b/src/cli.ts index 54041a1922..065feb68bc 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,7 +20,7 @@ import { createRequire } from 'node:module' import { basename, dirname, extname, join, resolve } from 'node:path' import url from 'node:url' import { updateArgv } from './goods.js' -import { $, chalk, fetch, ProcessOutput } from './index.js' +import { $, chalk, globalFetch, ProcessOutput } from './index.js' import { startRepl } from './repl.js' import { randomId } from './util.js' import { installDeps, parseDeps } from './deps.js' @@ -125,8 +125,8 @@ async function scriptFromStdin() { } async function scriptFromHttp(remote: string) { - const res = await fetch(remote) - if (!res.ok) { + const res = await globalFetch(remote) + if (!res?.ok) { console.error(`Error: Can't get ${remote}`) process.exit(1) } diff --git a/src/goods.ts b/src/goods.ts index 922b8bb2d5..e63f23e11d 100644 --- a/src/goods.ts +++ b/src/goods.ts @@ -15,10 +15,15 @@ import assert from 'node:assert' import * as globbyModule from 'globby' import minimist from 'minimist' -import nodeFetch, { RequestInfo, RequestInit } from 'node-fetch' +import { RequestInfo, RequestInit } from 'node-fetch' import { createInterface } from 'node:readline' import { $, within, ProcessOutput } from './core.js' -import { Duration, isString, parseDuration } from './util.js' +import { + Duration, + isNodeEighteenOrGreaterThanEighteen, + isString, + parseDuration, +} from './util.js' import chalk from 'chalk' export { default as chalk } from 'chalk' @@ -50,9 +55,13 @@ export function sleep(duration: Duration) { }) } -export async function fetch(url: RequestInfo, init?: RequestInit) { - $.log({ kind: 'fetch', url, init }) - return nodeFetch(url, init) +export async function globalFetch(url: RequestInfo, init?: RequestInit) { + if (isNodeEighteenOrGreaterThanEighteen) { + $.log({ kind: 'fetch', url, init }) + return (globalThis as any).fetch(url, init) + } + console.error('Fetch is not supported') + return } export function echo(...args: any[]): void diff --git a/src/util.ts b/src/util.ts index 0e08971271..ade0a7caf0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -341,6 +341,9 @@ export function formatCmd(cmd?: string): string { return out + '\n' } +export const isNodeEighteenOrGreaterThanEighteen = + process.versions && Number(process.versions.node.split('.')[0]) >= 18 + const reservedWords = [ 'if', 'then', diff --git a/test/cli.test.js b/test/cli.test.js index d3502b836f..300b5610d0 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -15,6 +15,7 @@ import { suite } from 'uvu' import * as assert from 'uvu/assert' import '../build/globals.js' +import { isNodeEighteenOrGreaterThanEighteen } from './utils/test-utils.js' const test = suite('cli') @@ -97,12 +98,18 @@ test('supports `--prefix` flag ', async () => { }) test('scripts from https', async () => { + if (!isNodeEighteenOrGreaterThanEighteen) { + return true; + } $`cat ${path.resolve('test/fixtures/echo.http')} | nc -l 8080` let out = await $`node build/cli.js http://127.0.0.1:8080/echo.mjs` assert.match(out.stderr, 'test') }) test('scripts from https not ok', async () => { + if (!isNodeEighteenOrGreaterThanEighteen) { + return true; + } $`echo $'HTTP/1.1 500\n\n' | nc -l 8081` let out = await $`node build/cli.js http://127.0.0.1:8081`.nothrow() assert.match(out.stderr, "Error: Can't get") diff --git a/test/goods.test.js b/test/goods.test.js index 0bd89a169c..77ebbffe08 100644 --- a/test/goods.test.js +++ b/test/goods.test.js @@ -15,6 +15,8 @@ import chalk from 'chalk' import { suite } from 'uvu' import * as assert from 'uvu/assert' + +import { isNodeEighteenOrGreaterThanEighteen } from './utils/test-utils.js' import '../build/globals.js' const test = suite('goods') @@ -48,6 +50,9 @@ test('globby available', async () => { }) test('fetch() works', async () => { + if(!isNodeEighteenOrGreaterThanEighteen){ + return true; + } assert.match( await fetch('https://medv.io').then((res) => res.text()), /Anton Medvedev/ diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js new file mode 100644 index 0000000000..7e2a864e22 --- /dev/null +++ b/test/utils/test-utils.js @@ -0,0 +1,18 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const isNodeEighteenOrGreaterThanEighteen = + process.versions && Number(process.versions.node.split('.')[0]) >= 18 + +export { isNodeEighteenOrGreaterThanEighteen } diff --git a/tsconfig.json b/tsconfig.json index 0c213b6502..5b271aff2b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ES2021", - "lib": ["ES2021", "DOM"], + "lib": ["ES2021"], "moduleResolution": "NodeNext", "module": "NodeNext", "strict": true,