Skip to content

Commit e37e56f

Browse files
authored
build(docs/dev-deps): use JS-native fetch to get supporters data instead of external needle (#5643)
* build(docs/dev-deps): use JS-native `fetch` to get supporters data instead of external `needle` Signed-off-by: hainenber <dotronghai96@gmail.com> * chore: fix Prettier lint issue Signed-off-by: hainenber <dotronghai96@gmail.com> --------- Signed-off-by: hainenber <dotronghai96@gmail.com>
1 parent 8ff0209 commit e37e56f

File tree

5 files changed

+14
-84
lines changed

5 files changed

+14
-84
lines changed

docs-next/package-lock.json

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs-next/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"astro": "^5.16.6",
1818
"astro-og-canvas": "^0.7.2",
1919
"debug": "^4.4.3",
20-
"needle": "^3.3.1",
2120
"sharp": "^0.34.5",
2221
"starlight-package-managers": "^0.11.1",
2322
"typescript": "^5.9.3",

docs/_data/supporters.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
const { writeFile, mkdir, rm } = require("node:fs").promises;
1919
const { resolve } = require("node:path");
2020
const debug = require("debug")("mocha:docs:data:supporters");
21-
const needle = require("needle");
2221
const blocklist = new Set(require("./blocklist.json"));
2322

2423
/**
@@ -105,14 +104,15 @@ const fetchImage = process.env.MOCHA_DOCS_SKIP_IMAGE_DOWNLOAD
105104
: async (supporter) => {
106105
try {
107106
const { avatar: url } = supporter;
108-
const { body: imageBuf, headers } = await needle("get", url, {
109-
open_timeout: 30000,
107+
const response = await fetch(url, {
108+
signal: AbortSignal.timeout(30000),
110109
});
111-
if (headers["content-type"].startsWith("text/html")) {
110+
if (response.headers.get("content-type")?.startsWith("text/html")) {
112111
throw new TypeError(
113112
"received html and expected a png; outage likely",
114113
);
115114
}
115+
const imageBuf = Buffer.from(await response.arrayBuffer());
116116
debug("fetched %s", url);
117117
const filePath = resolve(SUPPORTER_IMAGE_PATH, supporter.id + ".png");
118118
await writeFile(filePath, imageBuf);
@@ -139,13 +139,16 @@ const getAllOrders = async (slug = "mochajs") => {
139139

140140
// Handling pagination if necessary (2 pages for ~1400 results in May 2019)
141141
while (true) {
142-
const result = await needle(
143-
"post",
144-
API_ENDPOINT,
145-
{ query: SUPPORTER_QUERY, variables },
146-
{ json: true },
147-
);
148-
const orders = result.body.data.account.orders.nodes;
142+
const response = await fetch(API_ENDPOINT, {
143+
method: "POST",
144+
headers: { "Content-Type": "application/json" },
145+
body: JSON.stringify({
146+
query: SUPPORTER_QUERY,
147+
variables: variables,
148+
}),
149+
});
150+
const result = await response.json();
151+
const orders = result.data.account.orders.nodes;
149152
allOrders = [...allOrders, ...orders];
150153
variables.offset += GRAPHQL_PAGE_SIZE;
151154
if (orders.length < GRAPHQL_PAGE_SIZE) {

package-lock.json

Lines changed: 0 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@
146146
"karma-mocha-reporter": "^2.2.5",
147147
"karma-sauce-launcher": "^4.3.6",
148148
"knip": "^5.61.3",
149-
"needle": "^2.5.0",
150149
"npm-run-all2": "^6.2.0",
151150
"nyc": "^17.1.0",
152151
"prettier": "3.6.2",

0 commit comments

Comments
 (0)