From 6918a32b6de42094f41c165ffb48c2f997d24494 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:24:37 -0500 Subject: [PATCH 01/12] fix: remove deprecated code BREAKING CHANGE: remove `code` and `headers` properties that were previously deprecated --- src/index.ts | 55 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2626118..0fb3ae8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,5 @@ -import { Deprecation } from "deprecation"; -import once from "once"; -const logOnceCode = once((deprecation: any) => console.warn(deprecation)); -const logOnceHeaders = once((deprecation: any) => console.warn(deprecation)); - -import type { - RequestOptions, - ResponseHeaders, - OctokitResponse, -} from "@octokit/types"; -import type { RequestErrorOptions } from "./types"; +import type { RequestOptions, OctokitResponse } from "@octokit/types"; +import type { RequestErrorOptions } from "./types.js"; /** * Error with extra properties to help with debugging @@ -21,25 +12,11 @@ export class RequestError extends Error { */ status: number; - /** - * http status code - * - * @deprecated `error.code` is deprecated in favor of `error.status` - */ - code!: number; - /** * Request options that lead to the error. */ request: RequestOptions; - /** - * error response headers - * - * @deprecated `error.headers` is deprecated in favor of `error.response.headers` - */ - headers!: ResponseHeaders; - /** * Response object if a response was received */ @@ -60,15 +37,9 @@ export class RequestError extends Error { this.name = "HttpError"; this.status = statusCode; - let headers: ResponseHeaders; - - if ("headers" in options && typeof options.headers !== "undefined") { - headers = options.headers; - } if ("response" in options) { this.response = options.response; - headers = options.response.headers; } // redact request credentials without mutating original request options @@ -91,27 +62,5 @@ export class RequestError extends Error { .replace(/\baccess_token=\w+/g, "access_token=[REDACTED]"); this.request = requestCopy; - - // deprecations - Object.defineProperty(this, "code", { - get() { - logOnceCode( - new Deprecation( - "[@octokit/request-error] `error.code` is deprecated, use `error.status`.", - ), - ); - return statusCode; - }, - }); - Object.defineProperty(this, "headers", { - get() { - logOnceHeaders( - new Deprecation( - "[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`.", - ), - ); - return headers || {}; - }, - }); } } From 75a350de10571eb804f0f6c2c6d7157dafcdb95c Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:26:10 -0500 Subject: [PATCH 02/12] build: output ESM BREAKING CHANGE: switch package to ESM instead of CommonJS --- package-lock.json | 8 ++++---- package.json | 3 ++- scripts/build.mjs | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index d1578c2..d8a7859 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "once": "^1.4.0" }, "devDependencies": { - "@octokit/tsconfig": "^2.0.0", + "@octokit/tsconfig": "^3.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", "@types/once": "^1.4.0", @@ -1490,9 +1490,9 @@ "integrity": "sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==" }, "node_modules/@octokit/tsconfig": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-2.0.0.tgz", - "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-3.0.0.tgz", + "integrity": "sha512-tQLwgXYfBq9iUbOq26kWCzsJL6DY7qjOLzqcg5tCFQ4ob48H47iX98NudHW7S5OQ/fpSKYJhb3eQehyBNzYjfA==", "dev": true }, "node_modules/@octokit/types": { diff --git a/package.json b/package.json index 052d160..5919dc0 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "publishConfig": { "access": "public" }, + "type": "module", "description": "Error class for Octokit request errors", "scripts": { "build": "node scripts/build.mjs && tsc -p tsconfig.json", @@ -27,7 +28,7 @@ "once": "^1.4.0" }, "devDependencies": { - "@octokit/tsconfig": "^2.0.0", + "@octokit/tsconfig": "^3.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", "@types/once": "^1.4.0", diff --git a/scripts/build.mjs b/scripts/build.mjs index 51561a5..dbd8922 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -43,7 +43,7 @@ async function main() { bundle: true, platform: "node", target: "node18", - format: "cjs", + format: "esm", ...sharedOptions, }), // Build an ESM browser bundle @@ -74,10 +74,18 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "dist-node/index.js", - browser: "dist-web/index.js", - types: "dist-types/index.d.ts", - module: "dist-src/index.js", + exports: { + ".": { + node: { + types: "./dist-types/index.d.ts", + import: "./dist-node/index.js", + }, + browser: { + types: "./dist-types/index.d.ts", + import: "./dist-web/index.js", + } + } + }, sideEffects: false, unpkg: "dist-web/index.js", }, From 92f595dc665fc14bad52ce208d8d78731ef3b2dc Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:28:03 -0500 Subject: [PATCH 03/12] fix(types): remove deprecated code --- src/types.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/types.ts b/src/types.ts index 268c339..97f0f0e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,16 +1,6 @@ -import type { - RequestOptions, - ResponseHeaders, - OctokitResponse, -} from "@octokit/types"; +import type { RequestOptions, OctokitResponse } from "@octokit/types"; -export type RequestErrorOptions = - | { - /** @deprecated set `response` instead */ - headers?: ResponseHeaders; - request: RequestOptions; - } - | { - response: OctokitResponse; - request: RequestOptions; - }; +export type RequestErrorOptions = { + response: OctokitResponse; + request: RequestOptions; +}; From 7dd7a4191ec2dec2c888444c335b645d1f7b8182 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:36:04 -0500 Subject: [PATCH 04/12] tests: use ESM --- package.json | 11 +++++++++-- test/request-error.test.ts | 4 ++-- test/tsconfig.test.json | 9 --------- 3 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 test/tsconfig.test.json diff --git a/package.json b/package.json index 5919dc0..7e42279 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint": "prettier --check '{src,test}/**/*' README.md package.json", "lint:fix": "prettier --write '{src,test}/**/*' README.md package.json", "pretest": "npm run -s lint", - "test": "jest --coverage" + "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage" }, "repository": "github:octokit/request-error.js", "keywords": [ @@ -40,14 +40,21 @@ "typescript": "^5.0.0" }, "jest": { + "extensionsToTreatAsEsm": [ + ".ts" + ], "transform": { "^.+\\.(ts|tsx)$": [ "ts-jest", { - "tsconfig": "test/tsconfig.test.json" + "tsconfig": "tsconfig.json", + "useESM": true } ] }, + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.js$": "$1" + }, "coverageThreshold": { "global": { "statements": 100, diff --git a/test/request-error.test.ts b/test/request-error.test.ts index a14be91..6f0b623 100644 --- a/test/request-error.test.ts +++ b/test/request-error.test.ts @@ -1,5 +1,5 @@ -import { RequestError } from "../src"; -import type { RequestErrorOptions } from "../src/types"; +import { RequestError } from "../src/index.js"; +import type { RequestErrorOptions } from "../src/types.js"; const mockOptions: RequestErrorOptions = { request: { diff --git a/test/tsconfig.test.json b/test/tsconfig.test.json deleted file mode 100644 index b0961e1..0000000 --- a/test/tsconfig.test.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "emitDeclarationOnly": false, - "noEmit": true, - "verbatimModuleSyntax": false - }, - "include": ["src/**/*"] -} From 6b5f30447efca2dac89289a6d15b094861d48c46 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:36:19 -0500 Subject: [PATCH 05/12] tests: remove deprecated code --- test/request-error.test.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/request-error.test.ts b/test/request-error.test.ts index 6f0b623..d32fa0f 100644 --- a/test/request-error.test.ts +++ b/test/request-error.test.ts @@ -130,27 +130,4 @@ describe("RequestError", () => { url: "https://api.github.com/", }); }); - - test("deprecates .code", () => { - global.console.warn = jest.fn(); - expect(new RequestError("test", 123, mockOptions).code).toEqual(123); - expect(new RequestError("test", 404, mockOptions).code).toEqual(404); - expect(console.warn).toHaveBeenCalledTimes(1); - }); - - test("deprecates .headers", () => { - global.console.warn = jest.fn(); - expect(new RequestError("test", 123, mockOptions).headers).toStrictEqual( - {}, - ); - expect( - new RequestError("test", 404, { ...mockOptions, headers: { foo: "bar" } }) - .headers, - ).toStrictEqual({ foo: "bar" }); - expect( - new RequestError("test", 404, { ...mockOptions, headers: undefined }) - .headers, - ).toStrictEqual({}); - expect(console.warn).toHaveBeenCalledTimes(1); - }); }); From 545b713584cacb25775d1c4873e84482abb66673 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:36:39 -0500 Subject: [PATCH 06/12] tests: fixup for removed deprecated code --- test/request-error.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/request-error.test.ts b/test/request-error.test.ts index d32fa0f..fef4b2c 100644 --- a/test/request-error.test.ts +++ b/test/request-error.test.ts @@ -7,6 +7,12 @@ const mockOptions: RequestErrorOptions = { url: "https://api.github.com/", headers: {}, }, + response: { + headers: {}, + status: 200, + url: "https://api.github.com/", + data: {}, + }, }; describe("RequestError", () => { From 518b3701983eb7c259d0f744fc2ff4588d52b463 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:38:00 -0500 Subject: [PATCH 07/12] fix: empty commit to trigger release From 81599c77d2f9bc45773266bd7315e3aa1b8ba910 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:41:45 -0500 Subject: [PATCH 08/12] test: re-add tsconfig --- package.json | 2 +- test/tsconfig.test.json | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/tsconfig.test.json diff --git a/package.json b/package.json index 7e42279..ba24829 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "^.+\\.(ts|tsx)$": [ "ts-jest", { - "tsconfig": "tsconfig.json", + "tsconfig": "test/tsconfig.json", "useESM": true } ] diff --git a/test/tsconfig.test.json b/test/tsconfig.test.json new file mode 100644 index 0000000..3165996 --- /dev/null +++ b/test/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": false, + "noEmit": true + }, + "include": ["src/**/*"] +} \ No newline at end of file From 2ccc8583c3c3e8cc9c731d26a0bc14436f4848b2 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:42:11 -0500 Subject: [PATCH 09/12] style: prettier --- test/tsconfig.test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tsconfig.test.json b/test/tsconfig.test.json index 3165996..fe99a4e 100644 --- a/test/tsconfig.test.json +++ b/test/tsconfig.test.json @@ -5,4 +5,4 @@ "noEmit": true }, "include": ["src/**/*"] -} \ No newline at end of file +} From c3be04dbc57bbcfab918eb0499831f4a26ec0764 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:43:52 -0500 Subject: [PATCH 10/12] test: fix path to tsconfig --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba24829..d1a4d7a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "^.+\\.(ts|tsx)$": [ "ts-jest", { - "tsconfig": "test/tsconfig.json", + "tsconfig": "test/tsconfig.test.json", "useESM": true } ] From b44e6d13cea6b783f97f85f4da203b81fbd5a45c Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:46:29 -0500 Subject: [PATCH 11/12] fix(types): response can be undefined --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 97f0f0e..4e0e5f6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type { RequestOptions, OctokitResponse } from "@octokit/types"; export type RequestErrorOptions = { - response: OctokitResponse; + response?: OctokitResponse; request: RequestOptions; }; From 790e189042f580e89db0c29675d8571b3da4b7d8 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sat, 17 Feb 2024 17:53:35 -0500 Subject: [PATCH 12/12] fix(deps): remove now-unused dependencies --- package-lock.json | 20 ++++---------------- package.json | 5 +---- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8a7859..0ec0f53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,15 +9,12 @@ "version": "0.0.0-development", "license": "MIT", "dependencies": { - "@octokit/types": "^12.0.0", - "deprecation": "^2.0.0", - "once": "^1.4.0" + "@octokit/types": "^12.0.0" }, "devDependencies": { "@octokit/tsconfig": "^3.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", - "@types/once": "^1.4.0", "esbuild": "^0.20.0", "glob": "^10.2.6", "jest": "^29.0.0", @@ -1630,12 +1627,6 @@ "undici-types": "~5.26.4" } }, - "node_modules/@types/once": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@types/once/-/once-1.4.4.tgz", - "integrity": "sha512-KSwEbnmPvnbHLtDj05t0w2CBAYctJ1M6gj/6JfWK+pLeD7/T7QGWGyXHaqLAMOQfDJP+sO/ujPDiPAAlHR3GOg==", - "dev": true - }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -2191,11 +2182,6 @@ "node": ">=0.10.0" } }, - "node_modules/deprecation": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", - "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -3733,6 +3719,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "dependencies": { "wrappy": "1" } @@ -4686,7 +4673,8 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "node_modules/write-file-atomic": { "version": "4.0.2", diff --git a/package.json b/package.json index d1a4d7a..170eafa 100644 --- a/package.json +++ b/package.json @@ -23,15 +23,12 @@ "author": "Gregor Martynus (https://github.com/gr2m)", "license": "MIT", "dependencies": { - "@octokit/types": "^12.0.0", - "deprecation": "^2.0.0", - "once": "^1.4.0" + "@octokit/types": "^12.0.0" }, "devDependencies": { "@octokit/tsconfig": "^3.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.0.0", - "@types/once": "^1.4.0", "esbuild": "^0.20.0", "glob": "^10.2.6", "jest": "^29.0.0",