Skip to content

Commit c51c5e2

Browse files
authored
Fix a few deploy issues (microsoft#2194)
1 parent a0a37cf commit c51c5e2

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

deploy/deployChangedPackages.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
// ones which have changed.
77

88
import * as fs from "fs";
9+
import * as path from "path";
910
import { spawnSync } from "child_process";
1011
import { Octokit } from "@octokit/rest";
1112
import { printUnifiedDiff } from "print-diff";
1213
import { generateChangelogFrom } from "../lib/changelog.js";
1314
import { packages } from "./createTypesPackages.js";
1415
import { fileURLToPath } from "node:url";
1516
import fetch from "node-fetch";
17+
import pRetry from "p-retry";
1618

1719
verify();
1820

@@ -41,9 +43,9 @@ for (const dirName of fs.readdirSync(generatedDir)) {
4143
throw new Error(`Couldn't find ${pkgJSON.name}`);
4244
}
4345

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+
);
4749

4850
const releaseNotes = [];
4951

@@ -164,6 +166,35 @@ function verify() {
164166
}
165167

166168
/** @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;
169200
}

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"jsonc-parser": "^3.3.1",
6161
"kdljs": "^0.3.0",
6262
"node-fetch": "^3.3.2",
63+
"p-retry": "^7.1.0",
6364
"prettier": "^3.6.2",
6465
"print-diff": "^2.0.0",
6566
"typescript": "^5.9.2",

0 commit comments

Comments
 (0)