From 3b0b89acc3ca14db4f72df084ab264df74dc9da4 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 25 Aug 2021 18:22:17 +0100 Subject: [PATCH] Uses unpkg to compare files --- deploy/deployChangedPackages.js | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/deploy/deployChangedPackages.js b/deploy/deployChangedPackages.js index 4191e0f47..7855411a2 100644 --- a/deploy/deployChangedPackages.js +++ b/deploy/deployChangedPackages.js @@ -6,13 +6,13 @@ // ones which have changed. import * as fs from "fs"; -import { basename } from "path"; import { spawnSync } from "child_process"; import { Octokit } from "@octokit/rest"; import printDiff from "print-diff"; -import { gitShowFile, generateChangelogFrom } from "../lib/changelog.js"; +import { generateChangelogFrom } from "../lib/changelog.js"; import { packages } from "./createTypesPackages.js"; import { fileURLToPath } from "node:url"; +import fetch from "node-fetch"; verify(); @@ -22,12 +22,18 @@ const uploaded = []; // .d.ts files from the version available on npm. const generatedDir = new URL("generated/", import.meta.url); for (const dirName of fs.readdirSync(generatedDir)) { - console.log(`Looking at ${dirName}`); const packageDir = new URL(`${dirName}/`, generatedDir); const localPackageJSONPath = new URL("package.json", packageDir); const newTSConfig = fs.readFileSync(localPackageJSONPath, "utf-8"); const pkgJSON = JSON.parse(newTSConfig); + // This assumes we'll only _ever_ ship patches, which may change in the + // future someday. + const [maj, min, patch] = pkgJSON.version.split("."); + const olderVersion = `${maj}.${min}.${patch - 1}`; + + console.log(`\nLooking at ${dirName} vs ${olderVersion}`); + // We'll need to map back from the filename in the npm package to the // generated file in baselines inside the git tag const thisPackageMeta = packages.find((p) => p.name === pkgJSON.name); @@ -49,23 +55,17 @@ for (const dirName of fs.readdirSync(generatedDir)) { if (!filemap) { throw new Error(`Couldn't find ${file} from ${pkgJSON.name}`); } - const originalFilename = basename(filemap.from); const generatedDTSPath = new URL(file, packageDir); const generatedDTSContent = fs.readFileSync(generatedDTSPath, "utf8"); - // This assumes we'll only _ever_ ship patches, which may change in the - // future someday. - const [maj, min, patch] = pkgJSON.version.split("."); - const olderVersion = `${maj}.${min}.${patch - 1}`; - try { - const oldFile = gitShowFile( - `${pkgJSON.name}@${olderVersion}`, - `baselines/${originalFilename}` + const oldFile = await getFileFromUnpkg( + `${pkgJSON.name}@${olderVersion}/${filemap.to}` ); - console.log(`Comparing ${file} from ${olderVersion}, to now:`); - printDiff(oldFile, generatedDTSContent); + console.log(` - ${file}`); + if (oldFile !== generatedDTSContent) + printDiff(oldFile, generatedDTSContent); const title = `\n## \`${file}\`\n\n`; const notes = generateChangelogFrom(oldFile, generatedDTSContent); @@ -78,6 +78,7 @@ for (const dirName of fs.readdirSync(generatedDir)) { console.log(` Could not get the file ${file} inside the npm package ${pkgJSON.name} from tag ${olderVersion}. Assuming that this means we need to upload this package.`); + console.error(error); upload = true; } } @@ -107,11 +108,13 @@ Assuming that this means we need to upload this package.`); } uploaded.push(dirName); - } - console.log("\n# Release notes:"); - console.log(releaseNotes, "\n\n"); + console.log("\n# Release notes:"); + console.log(releaseNotes, "\n\n"); + } } +console.log(""); + // Warn if we did a dry run. if (!process.env.NODE_AUTH_TOKEN) { 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) { if (uploaded.length) { console.log("Uploaded: ", uploaded.join(", ")); } else { - console.log("No uploads"); + console.log("Nothing to upload"); } /** @@ -154,3 +157,8 @@ function verify() { "There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN." ); } + +/** @param {string} filepath */ +function getFileFromUnpkg(filepath) { + return fetch(`https://unpkg.com/${filepath}`).then((r) => r.text()); +}