Skip to content

Commit e5ba413

Browse files
committed
refactor: replace p-limit with inline concurrency limiter
Remove the `p-limit` (and `@types/p-limit`) dependency by inlining a lightweight concurrency limiter directly in GitHubAPI.ts. The inline implementation (~30 lines) provides the same semantics — a queue-based promise throttle capped at 25 concurrent requests — without pulling in an external ESM-only package.
1 parent 04f312d commit e5ba413

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
"@types/micromatch": "^3.1.0",
113113
"@types/node": "18.19.18",
114114
"@types/node-fetch": "^2.5.12",
115-
"@types/p-limit": "^2.0.0",
116115
"@types/parse-github-url": "^1.0.3",
117116
"@types/prettier": "^1.16.1",
118117
"@types/readline-sync": "^1.4.3",
@@ -168,7 +167,6 @@
168167
"node-cleanup": "^2.1.2",
169168
"node-fetch": "^2.6.7",
170169
"override-require": "^1.1.1",
171-
"p-limit": "^2.1.0",
172170
"parse-diff": "^0.7.0",
173171
"parse-github-url": "^1.0.2",
174172
"parse-link-header": "^2.0.0",

source/platforms/github/GitHubAPI.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Octokit as GitHubNodeAPI } from "@octokit/rest"
22
import { debug } from "../../debug"
33
import * as node_fetch from "node-fetch"
44
import parse from "parse-link-header"
5-
import pLimit from "p-limit"
6-
75
import { GitHubPRDSL, GitHubIssueComment, GitHubUser } from "../../dsl/GitHubDSL"
86

97
import { dangerIDToString } from "../../runner/templates/githubIssueTemplate"
@@ -15,6 +13,46 @@ import { CheckOptions } from "./comms/checks/resultsToCheck"
1513

1614
export type APIToken = string
1715

16+
/**
17+
* Inline concurrency limiter — replaces the `p-limit` package.
18+
* Restricts the number of promises running at once to `concurrency`.
19+
*/
20+
function pLimit(concurrency: number) {
21+
const queue: Array<() => void> = []
22+
let active = 0
23+
24+
const next = () => {
25+
if (queue.length > 0 && active < concurrency) {
26+
active++
27+
queue.shift()!()
28+
}
29+
}
30+
31+
return <T>(fn: () => Promise<T>): Promise<T> =>
32+
new Promise<T>((resolve, reject) => {
33+
const run = () => {
34+
fn().then(
35+
(val) => {
36+
resolve(val)
37+
active--
38+
next()
39+
},
40+
(err) => {
41+
reject(err)
42+
active--
43+
next()
44+
}
45+
)
46+
}
47+
if (active < concurrency) {
48+
active++
49+
run()
50+
} else {
51+
queue.push(run)
52+
}
53+
})
54+
}
55+
1856
const limit = pLimit(25)
1957

2058
// Structure of files returned by the 'List pull request files' API

yarn.lock

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,13 +1918,6 @@
19181918
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.126.tgz#27875faa2926c0f475b39a8bb1e546c0176f8d4b"
19191919
integrity sha512-OTcgaiwfGFBKacvfwuHzzn1KLxH/er8mluiy8/uM3sGXHaRe73RrSIj01jow9t4kJEW633Ov+cOexXeiApTyAw==
19201920

1921-
"@types/p-limit@^2.0.0":
1922-
version "2.2.0"
1923-
resolved "https://registry.yarnpkg.com/@types/p-limit/-/p-limit-2.2.0.tgz#94a608e9b258a6c6156a13d1a14fd720dba70b97"
1924-
integrity sha512-fGFbybl1r0oE9mqgfc2EHHUin9ZL5rbQIexWI6jYRU1ADVn4I3LHzT+g/kpPpZsfp8PB94CQ655pfAjNF8LP6A==
1925-
dependencies:
1926-
p-limit "*"
1927-
19281921
"@types/parse-github-url@^1.0.3":
19291922
version "1.0.3"
19301923
resolved "https://registry.yarnpkg.com/@types/parse-github-url/-/parse-github-url-1.0.3.tgz#a097f26ae1993f1963d4031126dc7965707804aa"
@@ -5645,14 +5638,7 @@ p-is-promise@^3.0.0:
56455638
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-3.0.0.tgz#58e78c7dfe2e163cf2a04ff869e7c1dba64a5971"
56465639
integrity sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ==
56475640

5648-
p-limit@*:
5649-
version "6.2.0"
5650-
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-6.2.0.tgz#c254d22ba6aeef441a3564c5e6c2f2da59268a0f"
5651-
integrity sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==
5652-
dependencies:
5653-
yocto-queue "^1.1.1"
5654-
5655-
p-limit@^2.0.0, p-limit@^2.1.0, p-limit@^2.2.0:
5641+
p-limit@^2.0.0, p-limit@^2.2.0:
56565642
version "2.3.0"
56575643
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
56585644
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
@@ -7593,11 +7579,6 @@ yocto-queue@^0.1.0:
75937579
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
75947580
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
75957581

7596-
yocto-queue@^1.1.1:
7597-
version "1.2.0"
7598-
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.2.0.tgz#4a29a93e7591328fa31768701e6ea66962401f79"
7599-
integrity sha512-KHBC7z61OJeaMGnF3wqNZj+GGNXOyypZviiKpQeiHirG5Ib1ImwcLBH70rbMSkKfSmUNBsdf2PwaEJtKvgmkNw==
7600-
76017582
yoctocolors-cjs@^2.1.2:
76027583
version "2.1.2"
76037584
resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242"

0 commit comments

Comments
 (0)