Skip to content

Commit 16ae065

Browse files
author
Orta Therox
authored
Merge pull request #1120 from microsoft/use_unpkg
Uses unpkg to compare files before deploying
2 parents 8202c28 + 3b0b89a commit 16ae065

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

deploy/deployChangedPackages.js

+26-18
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
// ones which have changed.
77

88
import * as fs from "fs";
9-
import { basename } from "path";
109
import { spawnSync } from "child_process";
1110
import { Octokit } from "@octokit/rest";
1211
import printDiff from "print-diff";
13-
import { gitShowFile, generateChangelogFrom } from "../lib/changelog.js";
12+
import { generateChangelogFrom } from "../lib/changelog.js";
1413
import { packages } from "./createTypesPackages.js";
1514
import { fileURLToPath } from "node:url";
15+
import fetch from "node-fetch";
1616

1717
verify();
1818

@@ -22,12 +22,18 @@ const uploaded = [];
2222
// .d.ts files from the version available on npm.
2323
const generatedDir = new URL("generated/", import.meta.url);
2424
for (const dirName of fs.readdirSync(generatedDir)) {
25-
console.log(`Looking at ${dirName}`);
2625
const packageDir = new URL(`${dirName}/`, generatedDir);
2726
const localPackageJSONPath = new URL("package.json", packageDir);
2827
const newTSConfig = fs.readFileSync(localPackageJSONPath, "utf-8");
2928
const pkgJSON = JSON.parse(newTSConfig);
3029

30+
// This assumes we'll only _ever_ ship patches, which may change in the
31+
// future someday.
32+
const [maj, min, patch] = pkgJSON.version.split(".");
33+
const olderVersion = `${maj}.${min}.${patch - 1}`;
34+
35+
console.log(`\nLooking at ${dirName} vs ${olderVersion}`);
36+
3137
// We'll need to map back from the filename in the npm package to the
3238
// generated file in baselines inside the git tag
3339
const thisPackageMeta = packages.find((p) => p.name === pkgJSON.name);
@@ -49,23 +55,17 @@ for (const dirName of fs.readdirSync(generatedDir)) {
4955
if (!filemap) {
5056
throw new Error(`Couldn't find ${file} from ${pkgJSON.name}`);
5157
}
52-
const originalFilename = basename(filemap.from);
5358

5459
const generatedDTSPath = new URL(file, packageDir);
5560
const generatedDTSContent = fs.readFileSync(generatedDTSPath, "utf8");
5661

57-
// This assumes we'll only _ever_ ship patches, which may change in the
58-
// future someday.
59-
const [maj, min, patch] = pkgJSON.version.split(".");
60-
const olderVersion = `${maj}.${min}.${patch - 1}`;
61-
6262
try {
63-
const oldFile = gitShowFile(
64-
`${pkgJSON.name}@${olderVersion}`,
65-
`baselines/${originalFilename}`
63+
const oldFile = await getFileFromUnpkg(
64+
`${pkgJSON.name}@${olderVersion}/${filemap.to}`
6665
);
67-
console.log(`Comparing ${file} from ${olderVersion}, to now:`);
68-
printDiff(oldFile, generatedDTSContent);
66+
console.log(` - ${file}`);
67+
if (oldFile !== generatedDTSContent)
68+
printDiff(oldFile, generatedDTSContent);
6969

7070
const title = `\n## \`${file}\`\n\n`;
7171
const notes = generateChangelogFrom(oldFile, generatedDTSContent);
@@ -78,6 +78,7 @@ for (const dirName of fs.readdirSync(generatedDir)) {
7878
console.log(`
7979
Could not get the file ${file} inside the npm package ${pkgJSON.name} from tag ${olderVersion}.
8080
Assuming that this means we need to upload this package.`);
81+
console.error(error);
8182
upload = true;
8283
}
8384
}
@@ -107,11 +108,13 @@ Assuming that this means we need to upload this package.`);
107108
}
108109

109110
uploaded.push(dirName);
110-
}
111111

112-
console.log("\n# Release notes:");
113-
console.log(releaseNotes, "\n\n");
112+
console.log("\n# Release notes:");
113+
console.log(releaseNotes, "\n\n");
114+
}
114115
}
116+
console.log("");
117+
115118
// Warn if we did a dry run.
116119
if (!process.env.NODE_AUTH_TOKEN) {
117120
console.log("Did a dry run because process.env.NODE_AUTH_TOKEN is not set.");
@@ -120,7 +123,7 @@ if (!process.env.NODE_AUTH_TOKEN) {
120123
if (uploaded.length) {
121124
console.log("Uploaded: ", uploaded.join(", "));
122125
} else {
123-
console.log("No uploads");
126+
console.log("Nothing to upload");
124127
}
125128

126129
/**
@@ -154,3 +157,8 @@ function verify() {
154157
"There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN."
155158
);
156159
}
160+
161+
/** @param {string} filepath */
162+
function getFileFromUnpkg(filepath) {
163+
return fetch(`https://unpkg.com/${filepath}`).then((r) => r.text());
164+
}

0 commit comments

Comments
 (0)