|
2 | 2 | // @ts-check |
3 | 3 |
|
4 | 4 | import * as fs from "node:fs"; |
5 | | -import * as https from "node:https"; |
6 | 5 |
|
7 | 6 | const dependenciesGradle = "android/dependencies.gradle"; |
8 | 7 | const groupId = "com.google.devtools.ksp"; |
9 | 8 | const artifactId = "com.google.devtools.ksp.gradle.plugin"; |
10 | 9 | const rows = 50; |
11 | 10 | const searchUrl = `https://search.maven.org/solrsearch/select?q=g:%22${groupId}%22+AND+a:%22${artifactId}%22&core=gav&rows=${rows}&wt=json`; |
| 11 | +const userAgent = |
| 12 | + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51"; |
12 | 13 |
|
13 | 14 | /** |
14 | 15 | * @param {{ docs?: { id: string; g: string; a: string; v: string; }[]; }} response |
@@ -54,32 +55,13 @@ function update(output, versions) { |
54 | 55 | } |
55 | 56 |
|
56 | 57 | function main() { |
57 | | - const options = { |
58 | | - headers: { |
59 | | - "User-Agent": |
60 | | - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51", |
61 | | - }, |
62 | | - }; |
63 | | - |
64 | | - https |
65 | | - .get(searchUrl, options, (res) => { |
66 | | - if (res.statusCode !== 200) { |
67 | | - const { statusCode, statusMessage } = res; |
68 | | - console.error(`${searchUrl} -> ${statusCode}: ${statusMessage}`); |
69 | | - process.exitCode = 1; |
70 | | - return; |
71 | | - } |
72 | | - |
73 | | - /** @type {Buffer[]} */ |
74 | | - const data = []; |
75 | | - res.on("data", (chunk) => data.push(chunk)); |
76 | | - res.on("end", () => { |
77 | | - const { response } = JSON.parse(Buffer.concat(data).toString()); |
78 | | - const versions = extractVersions(response); |
79 | | - update(dependenciesGradle, versions); |
80 | | - }); |
| 58 | + fetch(searchUrl, { headers: { "User-Agent": userAgent } }) |
| 59 | + .then((res) => res.json()) |
| 60 | + .then(({ response }) => { |
| 61 | + const versions = extractVersions(response); |
| 62 | + update(dependenciesGradle, versions); |
81 | 63 | }) |
82 | | - .on("error", (e) => { |
| 64 | + .catch((e) => { |
83 | 65 | console.error(e); |
84 | 66 | process.exitCode = 1; |
85 | 67 | }); |
|
0 commit comments