Skip to content

Commit

Permalink
Merge pull request #703 from Financial-Times/no-fetch
Browse files Browse the repository at this point in the history
Use native fetch instead of node-fetch where possible
  • Loading branch information
ivomurrell authored Jan 2, 2025
2 parents 95c1c45 + 3e94af9 commit 64fa6a6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 77 deletions.
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",
"@types/pluralize": "^0.0.33",
"chai": "^4.3.4",
"globby": "^10.0.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
140 changes: 73 additions & 67 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@financial-times/eslint-config-next": "^6.0.0",
"@tsconfig/node16": "^1.0.3",
"@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 @@ -18,8 +18,8 @@
"@dotcom-tool-kit/package-json-hook": "^5.0.4",
"@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

0 comments on commit 64fa6a6

Please sign in to comment.