diff --git a/deploy/deployChangedPackages.js b/deploy/deployChangedPackages.js index 851cd59a2..9d5348fca 100644 --- a/deploy/deployChangedPackages.js +++ b/deploy/deployChangedPackages.js @@ -6,6 +6,7 @@ // ones which have changed. import * as fs from "fs"; +import * as path from "path"; import { spawnSync } from "child_process"; import { Octokit } from "@octokit/rest"; import { printUnifiedDiff } from "print-diff"; @@ -13,6 +14,7 @@ import { generateChangelogFrom } from "../lib/changelog.js"; import { packages } from "./createTypesPackages.js"; import { fileURLToPath } from "node:url"; import fetch from "node-fetch"; +import pRetry from "p-retry"; verify(); @@ -41,9 +43,9 @@ for (const dirName of fs.readdirSync(generatedDir)) { throw new Error(`Couldn't find ${pkgJSON.name}`); } - const dtsFiles = fs - .readdirSync(packageDir) - .filter((f) => f.endsWith(".d.ts")); + const dtsFiles = readdirRecursive(fileURLToPath(packageDir)).filter((f) => + f.endsWith(".d.ts"), + ); const releaseNotes = []; @@ -164,6 +166,35 @@ function verify() { } /** @param {string} filepath */ -function getFileFromUnpkg(filepath) { - return fetch(`https://unpkg.com/${filepath}`).then((r) => r.text()); +async function getFileFromUnpkg(filepath) { + return pRetry(async () => { + const resp = await fetch(`https://unpkg.com/${filepath}`); + if (resp.ok) { + return resp.text(); + } + if (resp.status === 404) { + return ""; + } + console.error(`Unexpected response status: ${resp.status}`); + throw new Error(resp.statusText); + }); +} + +/** @param {string} dir */ +function readdirRecursive(dir) { + /** @type {string[]} */ + let results = []; + /** @param {string} currentDir */ + function readDir(currentDir) { + const entries = fs.readdirSync(currentDir, { withFileTypes: true }); + for (const entry of entries) { + const fullPath = path.join(currentDir, entry.name); + results.push(path.relative(dir, fullPath)); + if (entry.isDirectory()) { + readDir(fullPath); + } + } + } + readDir(dir); + return results; } diff --git a/package-lock.json b/package-lock.json index 9a1203c84..846bc70c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "jsonc-parser": "^3.3.1", "kdljs": "^0.3.0", "node-fetch": "^3.3.2", + "p-retry": "^7.1.0", "prettier": "^3.6.2", "print-diff": "^2.0.0", "typescript": "^5.9.2", @@ -2647,6 +2648,19 @@ "node": ">=0.10.0" } }, + "node_modules/is-network-error": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/is-network-error/-/is-network-error-1.3.0.tgz", + "integrity": "sha512-6oIwpsgRfnDiyEDLMay/GqCl3HoAtH5+RUKW29gYkL0QA+ipzpDLA16yQs7/RHCSu+BwgbJaOUqa4A99qNVQVw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -3132,6 +3146,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-retry": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-7.1.0.tgz", + "integrity": "sha512-xL4PiFRQa/f9L9ZvR4/gUCRNus4N8YX80ku8kv9Jqz+ZokkiZLM0bcvX0gm1F3PDi9SPRsww1BDsTWgE6Y1GLQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-network-error": "^1.1.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", diff --git a/package.json b/package.json index f51aab7bd..d8f6ff620 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "jsonc-parser": "^3.3.1", "kdljs": "^0.3.0", "node-fetch": "^3.3.2", + "p-retry": "^7.1.0", "prettier": "^3.6.2", "print-diff": "^2.0.0", "typescript": "^5.9.2",