From 1ff40fdf0ef72c56350fcd147de269b1883e6662 Mon Sep 17 00:00:00 2001 From: Niclas Heltoft <9364318+heltoft@users.noreply.github.com> Date: Mon, 5 Feb 2024 07:42:10 +0100 Subject: [PATCH] Upgrade node engine to >=18.19.0 & @types/node to ^18.19.14 The currently used node environment has reached end of life. Updating to 18.x which is the version with Maintenance status for Node.js. - Upgraded node engine to >= 18.19.0 - Upgraded @types/node to ^18.19.14 --- CHANGELOG.md | 3 + Dockerfile | 4 +- appveyor.yml | 2 +- package.json | 6 +- source/api/_tests/fetch.test.ts | 10 ++- .../platforms/_tests/_encoding_parser.test.ts | 17 +++++ source/platforms/encodingParser.ts | 10 +++ source/platforms/github/GitHubUtils.ts | 4 +- source/platforms/gitlab/GitLabAPI.ts | 4 +- yarn.lock | 69 ++++++++++--------- 10 files changed, 85 insertions(+), 44 deletions(-) create mode 100644 source/platforms/_tests/_encoding_parser.test.ts create mode 100644 source/platforms/encodingParser.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7a18640..886685087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ## Main +- Upgrade `node` engine from `>=14.13.1` to `>=18.19.0` [@heltoft] +- Upgrade `@types/node` from `^10.11.3` to `^18.19.14` [@heltoft] ## 11.3.1 @@ -2002,6 +2004,7 @@ Not usable for others, only stubs of classes etc. - [@orta] [@hanneskaeufler]: https://github.com/hanneskaeufler [@happylinks]: https://github.com/happylinks [@hellocore]: https://github.com/HelloCore +[@heltoft]: https://github.com/heltoft [@hiroppy]: https://github.com/hiroppy [@hmcc]: https://github.com/hmcc [@hmschreiner]: https://github.com/hmschreiner diff --git a/Dockerfile b/Dockerfile index 6128831dc..b008a408e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:14-slim as build +FROM node:18-slim as build LABEL maintainer="Orta Therox" LABEL "com.github.actions.name"="Danger JS Action" @@ -16,7 +16,7 @@ RUN yarn install --production --frozen-lockfile RUN chmod +x distribution/commands/danger.js -FROM node:14-slim +FROM node:18-slim WORKDIR /usr/src/danger ENV PATH="/usr/src/danger/node_modules/.bin:$PATH" COPY package.json ./ diff --git a/appveyor.yml b/appveyor.yml index 77790bb5f..7cf1fd9e3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ # Test against this version of Node.js environment: - nodejs_version: "14" + nodejs_version: "18" # Install scripts. (runs after repo cloning) install: diff --git a/package.json b/package.json index 002fd7aa9..790a222e5 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ }, "homepage": "https://github.com/danger/danger-js#readme", "engines": { - "node": ">=14.13.1" + "node": ">=18.19.0" }, "devDependencies": { "@babel/cli": "7.16.7", @@ -109,7 +109,7 @@ "@types/lodash.mapvalues": "^4.6.6", "@types/lodash.memoize": "^4.1.3", "@types/micromatch": "^3.1.0", - "@types/node": "^10.11.3", + "@types/node": "^18.19.14", "@types/node-fetch": "^2.5.12", "@types/p-limit": "^2.0.0", "@types/prettier": "^1.16.1", @@ -123,7 +123,7 @@ "eslint": "^8.8.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jest": "^26.0.0", - "eslint-plugin-jsdoc": "^37.7.0", + "eslint-plugin-jsdoc": "^39.9.1", "flow-bin": "^0.77.0", "husky": "^1.0.1", "jest": "^24.0.0", diff --git a/source/api/_tests/fetch.test.ts b/source/api/_tests/fetch.test.ts index 086fe33ab..2cda92580 100644 --- a/source/api/_tests/fetch.test.ts +++ b/source/api/_tests/fetch.test.ts @@ -28,7 +28,10 @@ class TestServer { start = async (response: ResponseMock): Promise => { this.response = response return new Promise((resolve, reject) => { - this.server.listen(this.port, this.hostname, (err: any) => (err ? reject(err) : resolve())) + this.server.on("error", (e) => { + reject(e) + }) + this.server.listen(this.port, this.hostname, undefined, () => resolve()) }) } stop = async (): Promise => { @@ -52,7 +55,10 @@ class TestProxy { start = async (): Promise => { return new Promise((resolve, reject) => { this.isRunning = true - this.server.listen(this.port, this.hostname, (err: any) => (err ? reject(err) : resolve())) + this.server.on("error", (e) => { + reject(e) + }) + this.server.listen(this.port, this.hostname, undefined, () => resolve()) }) } stop = async (): Promise => { diff --git a/source/platforms/_tests/_encoding_parser.test.ts b/source/platforms/_tests/_encoding_parser.test.ts new file mode 100644 index 000000000..37aa421c1 --- /dev/null +++ b/source/platforms/_tests/_encoding_parser.test.ts @@ -0,0 +1,17 @@ +import { encodingParser } from "../encodingParser" + +describe("parsing encoding", () => { + it("handles base64", () => { + expect(encodingParser("base64")).toEqual("base64") + }) + + it("handles utf8", () => { + expect(encodingParser("utf8")).toEqual("utf8") + }) + + it("throws on unknown encoding", () => { + expect(() => { + encodingParser("unknownencoding") + }).toThrowError() + }) +}) diff --git a/source/platforms/encodingParser.ts b/source/platforms/encodingParser.ts new file mode 100644 index 000000000..e7e7402b1 --- /dev/null +++ b/source/platforms/encodingParser.ts @@ -0,0 +1,10 @@ +/** + * Verifies that the given encoding is a valid BufferEncoding. + * @throws in case the encoding is unsupported. + */ +export function encodingParser(encoding: string): BufferEncoding { + if (Buffer.isEncoding(encoding)) { + return encoding as BufferEncoding + } + throw new Error(`Unsupported buffer encoding ${encoding}`) +} diff --git a/source/platforms/github/GitHubUtils.ts b/source/platforms/github/GitHubUtils.ts index 73d1ca4b9..bdda1c2b0 100644 --- a/source/platforms/github/GitHubUtils.ts +++ b/source/platforms/github/GitHubUtils.ts @@ -5,6 +5,7 @@ import { filepathContentsMapToUpdateGitHubBranch, BranchCreationConfig } from "m import { sentence, href } from "../../runner/DangerUtils" import { GitHubPRDSL, GitHubUtilsDSL } from "./../../dsl/GitHubDSL" import { debug } from "../../debug" +import { encodingParser } from "../encodingParser" export type GetContentResponseData = | OctokitOpenApiTypes["schemas"]["content-file"] @@ -87,7 +88,8 @@ export const fileContentsGenerator = return "" } if (isFileContents(response.data) && response.data.content) { - const buffer = Buffer.from(response.data.content, response.data.encoding) + const encoding = encodingParser(response.data.encoding) + const buffer = Buffer.from(response.data.content, encoding) return buffer.toString() } else { return "" diff --git a/source/platforms/gitlab/GitLabAPI.ts b/source/platforms/gitlab/GitLabAPI.ts index fdf2cee0c..53ad937e6 100644 --- a/source/platforms/gitlab/GitLabAPI.ts +++ b/source/platforms/gitlab/GitLabAPI.ts @@ -3,6 +3,7 @@ import { Gitlab, Types } from "@gitbeaker/node" import { Types as CoreTypes } from "@gitbeaker/core/dist" import { Env } from "../../ci_source/ci_source" import { debug } from "../../debug" +import { encodingParser } from "../encodingParser" export type GitLabAPIToken = string export type GitLabOAuthToken = string @@ -209,7 +210,8 @@ class GitLabAPI { try { this.d("getFileContents", projectId, path, ref) const response = await api.show(projectId, path, ref) - const result: string = Buffer.from(response.content, response.encoding).toString() + const encoding = encodingParser(response.encoding) + const result: string = Buffer.from(response.content, encoding).toString() this.d("getFileContents", result) return result } catch (e) { diff --git a/yarn.lock b/yarn.lock index 16f5b0ed8..8339e60bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1162,14 +1162,14 @@ dependencies: "@cspotcode/source-map-consumer" "0.8.0" -"@es-joy/jsdoccomment@~0.18.0": - version "0.18.0" - resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.18.0.tgz#2532b2ecb8576d694011b157c447ed6b12534c70" - integrity sha512-TjT8KJULV4I6ZiwIoKr6eMs+XpRejqwJ/VA+QPDeFGe9j6bZFKmMJ81EeFsGm6JNZhnzm37aoxVROmTh2PZoyA== +"@es-joy/jsdoccomment@~0.36.1": + version "0.36.1" + resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.36.1.tgz#c37db40da36e4b848da5fd427a74bae3b004a30f" + integrity sha512-922xqFsTpHs6D0BUiG4toiyPOMc8/jafnWKxz1KWgS4XzKPy2qXf1Pe6UFuNSCQqt6tOuhAWXBNuuyUhJmw9Vg== dependencies: - comment-parser "1.3.0" + comment-parser "1.3.1" esquery "^1.4.0" - jsdoc-type-pratt-parser "~2.2.2" + jsdoc-type-pratt-parser "~3.1.0" "@eslint/eslintrc@^1.0.5": version "1.0.5" @@ -1685,16 +1685,18 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.0.tgz#b417deda18cf8400f278733499ad5547ed1abec4" integrity sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ== -"@types/node@^10.11.3": - version "10.17.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.55.tgz#a147f282edec679b894d4694edb5abeb595fecbd" - integrity sha512-koZJ89uLZufDvToeWO5BrC4CR4OUfHnUz2qoPs/daQH6qq3IN62QFxCTZ+bKaCE0xaoCAJYE4AXre8AbghCrhg== - "@types/node@^16.9.2": version "16.11.27" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.27.tgz#5da19383bdbeda99bc0d09cfbb88cab7297ebc51" integrity sha512-C1pD3kgLoZ56Uuy5lhfOxie4aZlA3UMGLX9rXteq4WitEZH6Rl80mwactt9QG0w0gLFlN/kLBTFnGXtDVWvWQw== +"@types/node@^18.19.14": + version "18.19.14" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.14.tgz#1880ff1b3ac913f3877f711588e5ed227da01886" + integrity sha512-EnQ4Us2rmOS64nHDWr0XqAD8DsO6f3XR6lf9UIIrZQpUzPVdN/oPuEzfDWNHSyXLvoGgjuEm/sPwFGSSs35Wtg== + dependencies: + undici-types "~5.26.4" + "@types/p-limit@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@types/p-limit/-/p-limit-2.0.0.tgz#c076b7daa9163108a35899ea6a9d927526943ea2" @@ -3011,10 +3013,10 @@ commander@~2.17.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg== -comment-parser@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.3.0.tgz#68beb7dbe0849295309b376406730cd16c719c44" - integrity sha512-hRpmWIKgzd81vn0ydoWoyPoALEOnF4wt8yKD35Ib1D6XC2siLiYaiqfGkYrunuKdsXGwpBpHU3+9r+RVw2NZfA== +comment-parser@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.3.1.tgz#3d7ea3adaf9345594aedee6563f422348f165c1b" + integrity sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA== commondir@^1.0.1: version "1.0.1" @@ -3293,7 +3295,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0: dependencies: ms "2.0.0" -debug@4, debug@^4.0.0, debug@^4.3.1: +debug@4, debug@^4.0.0, debug@^4.3.1, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -3817,18 +3819,17 @@ eslint-plugin-jest@^26.0.0: dependencies: "@typescript-eslint/utils" "^5.10.0" -eslint-plugin-jsdoc@^37.7.0: - version "37.7.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.7.0.tgz#975d9f18cb0520dde7a2b0db5f4421dfee3fdd17" - integrity sha512-vzy3/ltXoGtabRnjLogaEmhGxxIv5B8HK5MJLIrdxFJUvhBppZjuVuLr71DjIBi0jg6bFomwkYKjojt29cN8PA== +eslint-plugin-jsdoc@^39.9.1: + version "39.9.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.9.1.tgz#e9ce1723411fd7ea0933b3ef0dd02156ae3068e2" + integrity sha512-Rq2QY6BZP2meNIs48aZ3GlIlJgBqFCmR55+UBvaDkA3ZNQ0SvQXOs2QKkubakEijV8UbIVbVZKsOVN8G3MuqZw== dependencies: - "@es-joy/jsdoccomment" "~0.18.0" - comment-parser "1.3.0" - debug "^4.3.3" + "@es-joy/jsdoccomment" "~0.36.1" + comment-parser "1.3.1" + debug "^4.3.4" escape-string-regexp "^4.0.0" esquery "^1.4.0" - regextras "^0.8.0" - semver "^7.3.5" + semver "^7.3.8" spdx-expression-parse "^3.0.1" eslint-scope@^5.1.1: @@ -6083,10 +6084,10 @@ jsbn@~0.1.0: resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM= -jsdoc-type-pratt-parser@~2.2.2: - version "2.2.2" - resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-2.2.2.tgz#a85e407ac502b444dc23333aa4d6d0dc83f76187" - integrity sha512-zRokSWcPLSWkoNzsWn9pq7YYSwDhKyEe+cJYT2qaPqLOOJb5sFSi46BPj81vP+e8chvCNdQL9RG86Bi9EI6MDw== +jsdoc-type-pratt-parser@~3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-3.1.0.tgz#a4a56bdc6e82e5865ffd9febc5b1a227ff28e67e" + integrity sha512-MgtD0ZiCDk9B+eI73BextfRrVQl0oyzRG8B2BjORts6jbunj4ScKPcyXGTbB6eXL4y9TzxCm6hyeLq/2ASzNdw== jsdom@^11.5.1: version "11.5.1" @@ -8171,11 +8172,6 @@ regexpu-core@^5.0.1: unicode-match-property-ecmascript "^2.0.0" unicode-match-property-value-ecmascript "^2.0.0" -regextras@^0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/regextras/-/regextras-0.8.0.tgz#ec0f99853d4912839321172f608b544814b02217" - integrity sha512-k519uI04Z3SaY0fLX843MRXnDeG2+vHOFsyhiPZvNLe7r8rD2YNRjq4BQLZZ0oAr2NrtvZlICsXysGNFPGa3CQ== - registry-auth-token@^3.0.1: version "3.3.1" resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.1.tgz#fb0d3289ee0d9ada2cbb52af5dfe66cb070d3006" @@ -9667,6 +9663,11 @@ uglify-to-browserify@~1.0.0: resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" integrity sha1-bgkk1r2mta/jSeOabWMoUKD4grc= +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc"