Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native fetch instead of node-fetch where possible #703

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"devDependencies": {
"@jest/globals": "^27.4.6",
"@types/lodash": "^4.14.185",
"@types/node": "^16.18.23",
"chai": "^4.3.4",
"globby": "^10.0.2",
"ts-node": "^8.10.2",
Expand Down
3 changes: 0 additions & 3 deletions lib/wait-for-ok/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"author": "FT.com Platforms Team <[email protected]>",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.8",
"tslib": "^2.3.1"
},
"repository": {
Expand All @@ -21,8 +20,6 @@
"bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/lib/wait-for-ok",
"devDependencies": {
"@types/node": "^16.18.23",
"@types/node-fetch": "^2.5.10",
"winston": "^3.5.1"
},
"files": [
Expand Down
5 changes: 2 additions & 3 deletions lib/wait-for-ok/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch, { FetchError } from 'node-fetch'
import type { Logger } from 'winston'

const TWO_MINUTES = 2 * 60 * 1000
Expand All @@ -9,7 +8,7 @@ function waitForOk(logger: Logger, url: string): Promise<void> {
logger.info(`⏳ polling: ${url}`)

try {
const response = await fetch(url, { timeout: 2000, follow: 0 })
const response = await fetch(url, { signal: AbortSignal.timeout(2000), redirect: 'error' })

if (response.ok) {
logger.info(`✅ ${url} ok!`)
Expand All @@ -21,7 +20,7 @@ function waitForOk(logger: Logger, url: string): Promise<void> {
`❌ ${url} not ok, it's responding with status of ${response.status}, response.ok: ${response.ok}`
)
} catch (err) {
if (err instanceof FetchError && err.type && err.type === 'request-timeout') {
if (err instanceof DOMException && err.name === 'TimeoutError') {
logger.warn(`👋 Hey, ${url} doesn't seem to be responding yet, so there's that.`)
logger.warn("You're amazing, by the way. I don't say that often enough. But you really are.")
} else {
Expand Down
162 changes: 83 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"@commitlint/config-conventional": "^16.0.0",
"@dotcom-reliability-kit/eslint-config": "^2.0.0",
"@financial-times/eslint-config-next": "^6.0.0",
"@tsconfig/node16": "^1.0.3",
"@tsconfig/node18": "^18.2.4",
"@types/jest": "^27.4.0",
"@types/node": "^16.18.23",
"@types/node": "^18.19.55",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"check-engines": "^1.5.0",
Expand Down
4 changes: 2 additions & 2 deletions plugins/heroku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@dotcom-tool-kit/package-json-hook": "^5.0.2",
"@dotcom-tool-kit/state": "^4.0.0",
"@dotcom-tool-kit/wait-for-ok": "^4.0.0",
"@octokit/request": "^5.6.0",
"@octokit/request-error": "^2.1.0",
"@octokit/request": "^8.4.0",
"@octokit/request-error": "^5.1.0",
"heroku-client": "^3.1.0",
"p-retry": "^4.5.0",
"superagent": "^6.1.0",
Expand Down