From 49f9bd750b488fd10d5d15fad8790fb87e0bb057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 14 May 2023 16:56:41 +0200 Subject: [PATCH] Upgrade `@octokit/plugin-throttling` and fix type errors (#294) --- package.json | 2 +- src/readChangesetState.ts | 12 +++++++----- src/run.ts | 20 ++++++++++++++------ src/utils.ts | 1 - yarn.lock | 8 ++++---- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 3abab78..70819a1 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@changesets/pre": "^1.0.9", "@changesets/read": "^0.5.3", "@manypkg/get-packages": "^1.1.3", - "@octokit/plugin-throttling": "5.1.1", + "@octokit/plugin-throttling": "^5.2.1", "@types/fs-extra": "^8.0.0", "@types/jest": "^29.5.1", "@types/node": "^12.7.1", diff --git a/src/readChangesetState.ts b/src/readChangesetState.ts index 9b7e9d8..393758a 100644 --- a/src/readChangesetState.ts +++ b/src/readChangesetState.ts @@ -11,17 +11,19 @@ export default async function readChangesetState( cwd: string = process.cwd() ): Promise { let preState = await readPreState(cwd); - let isInPreMode = preState !== undefined && preState.mode === "pre"; - let changesets = await readChangesets(cwd); - if (isInPreMode) { + if (preState !== undefined && preState.mode === "pre") { let changesetsToFilter = new Set(preState.changesets); - changesets = changesets.filter((x) => !changesetsToFilter.has(x.id)); + + return { + preState, + changesets: changesets.filter((x) => !changesetsToFilter.has(x.id)), + }; } return { - preState: isInPreMode ? preState : undefined, + preState: undefined, changesets, }; } diff --git a/src/run.ts b/src/run.ts index 45a29c1..67d70f0 100644 --- a/src/run.ts +++ b/src/run.ts @@ -17,8 +17,6 @@ import * as gitUtils from "./gitUtils"; import readChangesetState from "./readChangesetState"; import resolveFrom from "resolve-from"; import { throttling } from "@octokit/plugin-throttling"; -// temporary workaround for https://github.com/octokit/plugin-throttling.js/pull/590 -import type {} from "@octokit/plugin-throttling/dist-types/types.d"; // GitHub Issues/PRs messages have a max size limit on the // message body payload. @@ -26,7 +24,7 @@ import type {} from "@octokit/plugin-throttling/dist-types/types.d"; // To avoid that, we ensure to cap the message to 60k chars. const MAX_CHARACTERS_PER_MESSAGE = 60000; -const setupOctokit = (githubToken) => { +const setupOctokit = (githubToken: string) => { return new (GitHub.plugin(throttling))( getOctokitOptions(githubToken, { throttle: { @@ -61,7 +59,7 @@ const setupOctokit = (githubToken) => { }; const createRelease = async ( - octokit: ReturnType, + octokit: ReturnType, { pkg, tagName }: { pkg: Package; tagName: string } ) => { try { @@ -87,7 +85,12 @@ const createRelease = async ( }); } catch (err) { // if we can't find a changelog, the user has probably disabled changelogs - if (err.code !== "ENOENT") { + if ( + err && + typeof err === "object" && + "code" in err && + err.code !== "ENOENT" + ) { throw err; } } @@ -205,7 +208,12 @@ const requireChangesetsCliPkgJson = (cwd: string) => { try { return require(resolveFrom(cwd, "@changesets/cli/package.json")); } catch (err) { - if (err && err.code === "MODULE_NOT_FOUND") { + if ( + err && + typeof err === "object" && + "code" in err && + err.code === "MODULE_NOT_FOUND" + ) { throw new Error( `Have you forgotten to install \`@changesets/cli\` in "${cwd}"?` ); diff --git a/src/utils.ts b/src/utils.ts index 0d23a38..e92a195 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,7 +3,6 @@ import remarkParse from "remark-parse"; import remarkStringify from "remark-stringify"; // @ts-ignore import mdastToString from "mdast-util-to-string"; -import { exec } from "@actions/exec"; import { getPackages, Package } from "@manypkg/get-packages"; export const BumpLevels = { diff --git a/yarn.lock b/yarn.lock index 037c231..d91134d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1751,10 +1751,10 @@ "@octokit/types" "^6.39.0" deprecation "^2.3.1" -"@octokit/plugin-throttling@5.1.1": - version "5.1.1" - resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-5.1.1.tgz#7e7ff4646a8ad622d34d9e0c5be7a7e6ea35ba10" - integrity sha512-UlsdoW3ZOhhvjnK8S+OmQWOvB14kaKKdxseGFAxVHVggKZlgKO/ZtAb1AQoHXaQUCfO7uV/O5BR27o/wbKAzHg== +"@octokit/plugin-throttling@^5.2.1": + version "5.2.1" + resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-5.2.1.tgz#0600a0165bb439afaf40cf7cccae21cea7b3fd03" + integrity sha512-UUTFP301/gYEgsPABIP35QZR4dEXPtyoXHCQhPXU8U4FphXKjXOahoMlHg/T4IQVWMmSy607zsqThuBkpV9Gjg== dependencies: "@octokit/types" "^9.0.0" bottleneck "^2.15.3"