Skip to content

Commit 4b2e311

Browse files
committed
Switch to using git tags to compare the dts files
1 parent 292e4a2 commit 4b2e311

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

deploy/createTypesPackages.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// node deploy/createTypesPackages.mjs
44

55
// prettier-ignore
6-
const packages = [
6+
export const packages = [
77
{
88
name: "@types/web",
99
description: "Types for the DOM, and other web technologies in browsers",
@@ -71,8 +71,6 @@ const go = async () => {
7171
}
7272
};
7373

74-
go();
75-
7674
async function updatePackageJSON(packagePath, pkg, gitSha) {
7775
const pkgJSONPath = join(packagePath, "package.json");
7876
const packageText = fs.readFileSync(pkgJSONPath, "utf8");
@@ -131,3 +129,7 @@ function copyREADME(pkg, pkgJSON, writePath) {
131129

132130
fs.writeFileSync(writePath, readme);
133131
}
132+
133+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
134+
go();
135+
}

deploy/deployChangedPackages.mjs

Lines changed: 29 additions & 11 deletions
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 { join, dirname } from "path";
9+
import { join, dirname, basename } from "path";
1010
import { fileURLToPath } from "url";
11-
import fetch from "node-fetch";
12-
import { spawnSync } from "child_process";
11+
import { spawnSync, execSync } from "child_process";
1312
import { Octokit } from "@octokit/core";
1413
import printDiff from "print-diff";
1514
import { generateChangelogFrom } from "../lib/changelog.js";
15+
import { packages } from "./createTypesPackages.mjs";
1616

1717
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1818
// @ts-ignore
@@ -27,6 +27,9 @@ const verify = () => {
2727
);
2828
};
2929

30+
const gitShowFile = (commitish, path) =>
31+
execSync(`git show "${commitish}":${path}`, { encoding: "utf-8" });
32+
3033
const go = async () => {
3134
verify();
3235

@@ -41,6 +44,10 @@ const go = async () => {
4144
const newTSConfig = fs.readFileSync(localPackageJSONPath, "utf-8");
4245
const pkgJSON = JSON.parse(newTSConfig);
4346

47+
// We'll need to map back from the filename in the npm package to the
48+
// generated file in baselines inside the git tag
49+
const thisPackageMeta = packages.find((p) => p.name === pkgJSON.name);
50+
4451
const dtsFiles = fs
4552
.readdirSync(join(generatedDir, dirName))
4653
.filter((f) => f.endsWith(".d.ts"));
@@ -52,25 +59,36 @@ const go = async () => {
5259
// determine if anything has changed
5360
let upload = false;
5461
for (const file of dtsFiles) {
62+
const originalFilename = basename(
63+
thisPackageMeta.files.find((f) => f.to === file).from
64+
);
65+
5566
const generatedDTSPath = join(generatedDir, dirName, file);
5667
const generatedDTSContent = fs.readFileSync(generatedDTSPath, "utf8");
57-
const unpkgURL = `https://unpkg.com/${pkgJSON.name}/${file}`;
68+
69+
// This assumes we'll only _ever_ ship patches, which may change in the
70+
// future someday.
71+
const [maj, min, patch] = pkgJSON.version.split(".");
72+
const olderVersion = `${maj}.${min}.${patch - 1}`;
73+
5874
try {
59-
const npmDTSReq = await fetch(unpkgURL);
60-
const npmDTSText = await npmDTSReq.text();
61-
console.log(`Comparing ${file} from unpkg, to generated version:`);
62-
printDiff(npmDTSText, generatedDTSContent);
75+
const oldFile = gitShowFile(
76+
`${pkgJSON.name}@${olderVersion}`,
77+
`baselines/${originalFilename}`
78+
);
79+
console.log(`Comparing ${file} from ${olderVersion}, to now:`);
80+
printDiff(oldFile, generatedDTSContent);
6381

6482
const title = `\n## \`${file}\`\n`;
65-
const notes = generateChangelogFrom(npmDTSText, generatedDTSContent);
83+
const notes = generateChangelogFrom(oldFile, generatedDTSContent);
6684
releaseNotes.push(title);
6785
releaseNotes.push(notes.trim() === "" ? "No changes" : notes);
6886

69-
upload = upload || npmDTSText !== generatedDTSContent;
87+
upload = upload || oldFile !== generatedDTSContent;
7088
} catch (error) {
7189
// Could not find a previous build
7290
console.log(`
73-
Could not get the file ${file} inside the npm package ${pkgJSON.name} from unpkg at ${unpkgURL}
91+
Could not get the file ${file} inside the npm package ${pkgJSON.name} from tag ${olderVersion}.
7492
Assuming that this means we need to upload this package.`);
7593
upload = true;
7694
}

src/changelog.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ export function generateDefaultFromRecentTag(): string {
141141
const [base = gitLatestTag(), head = "HEAD"] = process.argv.slice(2);
142142
const previous = gitShowFile(base, dom);
143143
const current = gitShowFile(head, dom);
144-
return generateChangelogFrom(previous, current);
144+
const changelog = generateChangelogFrom(previous, current);
145+
if (!changelog.length) {
146+
throw new Error(`No change reported between ${base} and ${head}.`);
147+
}
148+
return changelog;
145149
}
146150

147151
export function generateChangelogFrom(

0 commit comments

Comments
 (0)