From 854f45102ef8968c5253566b9d147d748fca47b2 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Wed, 27 Nov 2024 17:31:51 +0000 Subject: [PATCH] Fix 404 error if releasing a new package (#763) ## Summary A small fix to handle brand new packages in the release script; we search for `dist-tags` to ensure we can backport from `v*.x` branches, but dist tags won't exist for new packages! ## Checklist - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A KTLO - [ ] ~Added unit/integration tests~ N/A KTLO - [ ] ~Added changesets if applicable~ N/A KTLO --- scripts/release/publish.js | 44 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/scripts/release/publish.js b/scripts/release/publish.js index b0bc324f..b9a51e61 100644 --- a/scripts/release/publish.js +++ b/scripts/release/publish.js @@ -60,6 +60,8 @@ const exec = async (...args) => { } // Get current latest version + let latestVersion; + const { exitCode: latestCode, stdout: latestStdout, @@ -67,22 +69,42 @@ const exec = async (...args) => { } = await getExecOutput("npm", ["dist-tag", "ls"]); if (latestCode !== 0) { - throw new Error( - `npm dist-tag ls exited with ${latestCode}:\n${latestStderr}` - ); - } + // It could be a non-zero code if the package was never published before + const notFoundMsg = "is not in this registry"; - const latestVersion = latestStdout - .split("\n") - .find((line) => line.startsWith("latest: ")) - ?.split(" ")[1]; - - if (!latestVersion) { - throw new Error(`Could not find "latest" dist-tag in:\n${latestStdout}`); + if ( + latestStdout.includes(notFoundMsg) || + latestStderr.includes(notFoundMsg) + ) { + console.log( + "npm dist-tag ls failed but it's okay; package hasn't been published yet" + ); + } else { + throw new Error( + `npm dist-tag ls exited with ${latestCode}:\n${latestStderr}` + ); + } + } else { + latestVersion = latestStdout + ?.split("\n") + ?.find((line) => line.startsWith("latest: ")) + ?.split(" ")[1]; + + if (!latestVersion) { + throw new Error(`Could not find "latest" dist-tag in:\n${latestStdout}`); + } } console.log("latestVersion:", latestVersion); + // If this is going to be backport release, don't allow us to continue if we + // have no latest version to reset to + if (branch !== "main" && !latestVersion) { + throw new Error( + "Cannot continue with backport release; no latest version found" + ); + } + // Release to npm await exec("npm", ["config", "set", "git-tag-version", "false"], { cwd: distDir,