Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade node engine to >=18 & @types/node to ^18.19.14 #1424

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:

steps:
# Check out, and set up the node/ruby infra
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "16"
node-version: "18"

# Get local dependencies & test
- run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
tag: v2.1.5-procursus6

- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "14"
node-version: "18"

- name: Install dependencies
run: npm install
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
## Main

<!-- Your comment below this -->
- Upgrade `node` engine from `>=14.13.1` to `>=18` [@heltoft]
- Upgrade `@types/node` from `^10.11.3` to `^18.19.14` [@heltoft]
<!-- Your comment above this -->

## 11.3.1
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 ./
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
},
"homepage": "https://github.com/danger/danger-js#readme",
"engines": {
"node": ">=14.13.1"
"node": ">=18"
},
"devDependencies": {
"@babel/cli": "7.16.7",
Expand All @@ -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",
Expand All @@ -123,13 +123,13 @@
"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",
"jest-json-reporter": "^1.2.2",
"lint-staged": "^12.3.7",
"madge": "^5.0.1",
"madge": "^6.0.1",
"nock": "^13.2.0",
"pkg": "^5.4.0",
"prettier": "^2.5.1",
Expand Down
10 changes: 8 additions & 2 deletions source/api/_tests/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class TestServer {
start = async (response: ResponseMock): Promise<void> => {
this.response = response
return new Promise<void>((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<void> => {
Expand All @@ -52,7 +55,10 @@ class TestProxy {
start = async (): Promise<void> => {
return new Promise<void>((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<void> => {
Expand Down
17 changes: 17 additions & 0 deletions source/platforms/_tests/_encoding_parser.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
10 changes: 10 additions & 0 deletions source/platforms/encodingParser.ts
Original file line number Diff line number Diff line change
@@ -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}`)
}
4 changes: 3 additions & 1 deletion source/platforms/github/GitHubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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 ""
Expand Down
4 changes: 3 additions & 1 deletion source/platforms/gitlab/GitLabAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading