From 7a020bdb404744b57c49b91dda2cc2ce90e2640e Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 28 Nov 2025 22:58:44 +0800 Subject: [PATCH] Fix release script (#18363) --- scripts/release/steps/post-publish-steps.js | 4 +- .../release/steps/update-dependents-count.js | 89 +++++++++++++------ website/src/pages/index.jsx | 4 +- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/scripts/release/steps/post-publish-steps.js b/scripts/release/steps/post-publish-steps.js index 9ff840c54..dfba9401d 100644 --- a/scripts/release/steps/post-publish-steps.js +++ b/scripts/release/steps/post-publish-steps.js @@ -27,9 +27,7 @@ async function checkSchema() { ); return outdent` - ${styleText.bold.underline( - "The schema in {yellow SchemaStore", - )} needs an update.} + The schema in ${styleText.bold.yellow("SchemaStore")} needs an update. - Open ${styleText.cyan.underline(EDIT_URL)} - Open ${styleText.cyan.underline("/.tmp/schema/prettierrc.json")} file and copy the content - Paste it on GitHub interface diff --git a/scripts/release/steps/update-dependents-count.js b/scripts/release/steps/update-dependents-count.js index 318ae8efe..d2b054fe9 100644 --- a/scripts/release/steps/update-dependents-count.js +++ b/scripts/release/steps/update-dependents-count.js @@ -1,13 +1,14 @@ import styleText from "node-style-text"; import { fetchText, logPromise, processFile, runGit } from "../utils.js"; -async function update({ repo }) { +async function getNpmDependentsCount() { const npmPage = await logPromise( "Fetching npm dependents count", fetchText("https://www.npmjs.com/package/prettier"), ); const dependentsCountNpm = Number( - npmPage.match(/"dependentsCount":(\d+),/u)[1], + npmPage.match(/"dependentsCount":"(?\d+)",/u).groups + .dependentsCount, ); if (Number.isNaN(dependentsCountNpm)) { throw new TypeError( @@ -15,6 +16,10 @@ async function update({ repo }) { ); } + return dependentsCountNpm; +} + +async function getGithubDependentsCount() { const githubPage = await logPromise( "Fetching github dependents count", fetchText("https://github.com/prettier/prettier/network/dependents"), @@ -23,41 +28,69 @@ async function update({ repo }) { githubPage .replaceAll("\n", "") .match( - /.*?<\/svg>\s*([\d,]+)\s*Repositories\s*<\/a>/u, - )[1] - .replaceAll(",", ""), + /.*?<\/svg>\s*(?[\d,]+)\s*Repositories\s*<\/a>/u, + ) + .groups.dependentsCount.replaceAll(",", ""), ); - if (Number.isNaN(dependentsCountNpm)) { + if (Number.isNaN(dependentsCountGithub)) { throw new TypeError( "Invalid data from https://github.com/prettier/prettier/network/dependents", ); } - processFile("website/src/pages/index.jsx", (content) => - content - .replace( - /()(.*?)(<\/strong>)/u, - `$1${formatNumber(dependentsCountNpm)}$3`, - ) - .replace( - /()(.*?)(<\/strong>)/u, - `$1${formatNumber(dependentsCountGithub)}$3`, - ), - ); + return dependentsCountGithub; +} - const isUpdated = await logPromise( - "Checking if dependents count has been updated", - async () => - (await runGit(["diff", "--name-only"])).stdout === - "website/src/pages/index.jsx", - ); +async function update({ repo }) { + const [ + { value: dependentsCountNpm, reason: dependentsNpmError }, + { value: dependentsCountGithub, reason: dependentsGithubError }, + ] = await Promise.allSettled([ + getNpmDependentsCount(), + getGithubDependentsCount(), + ]); - if (isUpdated) { - await logPromise("Committing and pushing to remote", async () => { - await runGit(["add", "."]); - await runGit(["commit", "-m", "Update dependents count"]); - await runGit(["push", "--repo", repo]); + if (dependentsCountNpm || dependentsCountGithub) { + processFile("website/src/pages/index.jsx", (content) => { + if (dependentsCountNpm) { + content = content.replace( + /()(.*?)(<\/strong>)/u, + `$1${formatNumber(dependentsCountNpm)}$3`, + ); + } + + if (dependentsCountGithub) { + content = content.replace( + /()(.*?)(<\/strong>)/u, + `$1${formatNumber(dependentsCountGithub)}$3`, + ); + } + + return content; }); + + const isUpdated = await logPromise( + "Checking if dependents count has been updated", + async () => + (await runGit(["diff", "--name-only"])).stdout === + "website/src/pages/index.jsx", + ); + + if (isUpdated) { + await logPromise("Committing and pushing to remote", async () => { + await runGit(["add", "."]); + await runGit(["commit", "-m", "Update dependents count"]); + await runGit(["push", "--repo", repo]); + }); + } + } + + if (dependentsNpmError) { + throw dependentsNpmError; + } + + if (dependentsGithubError) { + throw dependentsGithubError; } } diff --git a/website/src/pages/index.jsx b/website/src/pages/index.jsx index 3fdf48db5..bc52848a7 100644 --- a/website/src/pages/index.jsx +++ b/website/src/pages/index.jsx @@ -331,7 +331,7 @@ function UsersSection() {

More than{" "} - 9.8 million{" "} + 9.9 million{" "} dependent repositories on GitHub

More than{" "} - 19.8k{" "} + 19.4k{" "} dependent packages on npm