|
6 | 6 | // ones which have changed. |
7 | 7 |
|
8 | 8 | import * as fs from "fs"; |
| 9 | +import * as path from "path"; |
9 | 10 | import { spawnSync } from "child_process"; |
10 | 11 | import { Octokit } from "@octokit/rest"; |
11 | 12 | import { printUnifiedDiff } from "print-diff"; |
12 | 13 | import { generateChangelogFrom } from "../lib/changelog.js"; |
13 | 14 | import { packages } from "./createTypesPackages.js"; |
14 | 15 | import { fileURLToPath } from "node:url"; |
15 | 16 | import fetch from "node-fetch"; |
| 17 | +import pRetry from "p-retry"; |
16 | 18 |
|
17 | 19 | verify(); |
18 | 20 |
|
@@ -41,9 +43,9 @@ for (const dirName of fs.readdirSync(generatedDir)) { |
41 | 43 | throw new Error(`Couldn't find ${pkgJSON.name}`); |
42 | 44 | } |
43 | 45 |
|
44 | | - const dtsFiles = fs |
45 | | - .readdirSync(packageDir) |
46 | | - .filter((f) => f.endsWith(".d.ts")); |
| 46 | + const dtsFiles = readdirRecursive(fileURLToPath(packageDir)).filter((f) => |
| 47 | + f.endsWith(".d.ts"), |
| 48 | + ); |
47 | 49 |
|
48 | 50 | const releaseNotes = []; |
49 | 51 |
|
@@ -164,6 +166,35 @@ function verify() { |
164 | 166 | } |
165 | 167 |
|
166 | 168 | /** @param {string} filepath */ |
167 | | -function getFileFromUnpkg(filepath) { |
168 | | - return fetch(`https://unpkg.com/${filepath}`).then((r) => r.text()); |
| 169 | +async function getFileFromUnpkg(filepath) { |
| 170 | + return pRetry(async () => { |
| 171 | + const resp = await fetch(`https://unpkg.com/${filepath}`); |
| 172 | + if (resp.ok) { |
| 173 | + return resp.text(); |
| 174 | + } |
| 175 | + if (resp.status === 404) { |
| 176 | + return ""; |
| 177 | + } |
| 178 | + console.error(`Unexpected response status: ${resp.status}`); |
| 179 | + throw new Error(resp.statusText); |
| 180 | + }); |
| 181 | +} |
| 182 | + |
| 183 | +/** @param {string} dir */ |
| 184 | +function readdirRecursive(dir) { |
| 185 | + /** @type {string[]} */ |
| 186 | + let results = []; |
| 187 | + /** @param {string} currentDir */ |
| 188 | + function readDir(currentDir) { |
| 189 | + const entries = fs.readdirSync(currentDir, { withFileTypes: true }); |
| 190 | + for (const entry of entries) { |
| 191 | + const fullPath = path.join(currentDir, entry.name); |
| 192 | + results.push(path.relative(dir, fullPath)); |
| 193 | + if (entry.isDirectory()) { |
| 194 | + readDir(fullPath); |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + readDir(dir); |
| 199 | + return results; |
169 | 200 | } |
0 commit comments