Skip to content

Commit 1860356

Browse files
authored
upgrade dependencies, drop Node.js 12 (#519)
1 parent 9f1f8dc commit 1860356

17 files changed

Lines changed: 474 additions & 648 deletions

File tree

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ indent_size = 4
2525
[*.{yml,md}]
2626
indent_style = space
2727
indent_size = 4
28+
29+
[.github/workflows/*.yml]
30+
indent_style = space
31+
indent_size = 2

.github/workflows/test-and-release.yml

Lines changed: 109 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,114 @@ name: Test and Release
33
# Run this job on all pushes and pull requests
44
# as well as tags with a semantic version
55
on:
6-
push:
7-
branches:
8-
- "*"
9-
tags:
10-
# normal versions
11-
- "v[0-9]+.[0-9]+.[0-9]+"
12-
# pre-releases
13-
- "v[0-9]+.[0-9]+.[0-9]+-**"
14-
pull_request: {}
6+
push:
7+
branches:
8+
- "*"
9+
tags:
10+
# normal versions
11+
- "v[0-9]+.[0-9]+.[0-9]+"
12+
# pre-releases
13+
- "v[0-9]+.[0-9]+.[0-9]+-**"
14+
pull_request: {}
1515

1616
jobs:
17-
# Performs quick checks before the expensive test runs
18-
check-and-lint:
19-
if: contains(github.event.head_commit.message, '[skip ci]') == false
20-
21-
runs-on: ubuntu-latest
22-
strategy:
23-
matrix:
24-
node-version: [14.x]
25-
26-
steps:
27-
- uses: actions/checkout@v1
28-
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v1
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
33-
- name: Install dependencies
34-
run: npm ci
35-
36-
- name: Perform a type check
37-
run: npm run check
38-
env:
39-
CI: true
40-
41-
- name: Lint TypeScript code
42-
run: npm run lint
43-
44-
# ===================
45-
46-
# Runs unit tests on all supported node versions and OSes
47-
unit-tests:
48-
if: contains(github.event.head_commit.message, '[skip ci]') == false
49-
50-
needs: [check-and-lint]
51-
52-
runs-on: ${{ matrix.os }}
53-
strategy:
54-
matrix:
55-
node-version: [12.x, 14.x, 16.x]
56-
os: [ubuntu-latest]
57-
58-
steps:
59-
- uses: actions/checkout@v1
60-
- name: Use Node.js ${{ matrix.node-version }}
61-
uses: actions/setup-node@v1
62-
with:
63-
node-version: ${{ matrix.node-version }}
64-
65-
- name: Install dependencies
66-
run: npm ci
67-
68-
- name: Run component tests
69-
run: npm run test
70-
env:
71-
CI: true
72-
73-
# ===================
74-
75-
# Deploys the final package to NPM
76-
deploy:
77-
# Trigger this step only when a commit on master is tagged with a version number
78-
if: |
79-
contains(github.event.head_commit.message, '[skip ci]') == false &&
80-
github.event_name == 'push' &&
81-
startsWith(github.ref, 'refs/tags/v')
82-
83-
needs: [unit-tests]
84-
85-
runs-on: ubuntu-latest
86-
strategy:
87-
matrix:
88-
node-version: [14.x]
89-
90-
steps:
91-
- uses: actions/checkout@v1
92-
- name: Use Node.js ${{ matrix.node-version }}
93-
uses: actions/setup-node@v1
94-
with:
95-
node-version: ${{ matrix.node-version }}
96-
97-
- name: Install dependencies
98-
run: npm ci
99-
100-
- name: Create a clean build
101-
run: npm run build
102-
103-
- name: Publish package to npm
104-
run: |
105-
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
106-
npm whoami
107-
npm publish
17+
# Performs quick checks before the expensive test runs
18+
check-and-lint:
19+
if: contains(github.event.head_commit.message, '[skip ci]') == false
20+
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
node-version: [16.x] # This should be LTS
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v3
29+
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
cache: "npm"
35+
36+
- name: Install dependencies
37+
run: npm ci
38+
39+
- name: Perform a type check
40+
run: npm run check
41+
env:
42+
CI: true
43+
44+
- name: Lint TypeScript code
45+
run: npm run lint
46+
47+
# ===================
48+
49+
# Runs unit tests on all supported node versions and OSes
50+
unit-tests:
51+
if: contains(github.event.head_commit.message, '[skip ci]') == false
52+
53+
needs: [check-and-lint]
54+
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
matrix:
58+
node-version: [14.x, 16.x, 18.x]
59+
os: [ubuntu-latest]
60+
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v3
64+
65+
- name: Use Node.js ${{ matrix.node-version }}
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: ${{ matrix.node-version }}
69+
cache: "npm"
70+
71+
- name: Install dependencies
72+
run: npm ci
73+
74+
- name: Run component tests
75+
run: npm run test
76+
env:
77+
CI: true
78+
79+
# ===================
80+
81+
# Deploys the final package to NPM
82+
deploy:
83+
# Trigger this step only when a commit on master is tagged with a version number
84+
if: |
85+
contains(github.event.head_commit.message, '[skip ci]') == false &&
86+
github.event_name == 'push' &&
87+
startsWith(github.ref, 'refs/tags/v')
88+
89+
needs: [unit-tests]
90+
91+
runs-on: ubuntu-latest
92+
strategy:
93+
matrix:
94+
node-version: [16.x] # This should be LTS
95+
96+
steps:
97+
- name: Checkout code
98+
uses: actions/checkout@v3
99+
100+
- name: Use Node.js ${{ matrix.node-version }}
101+
uses: actions/setup-node@v3
102+
with:
103+
node-version: ${{ matrix.node-version }}
104+
cache: "npm"
105+
106+
- name: Install dependencies
107+
run: npm ci
108+
109+
- name: Create a clean build
110+
run: npm run build
111+
112+
- name: Publish package to npm
113+
run: |
114+
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
115+
npm whoami
116+
npm publish

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@ module.exports = {
66
useTabs: true,
77
tabWidth: 4,
88
endOfLine: "lf",
9+
10+
overrides: [
11+
{
12+
files: ".github/workflows/*.yml",
13+
options: {
14+
useTabs: false,
15+
tabWidth: 2,
16+
},
17+
},
18+
],
919
};

build/lib/executeCommand.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function executeCommand(command, argsOrOptions, options) {
4646
let bufferedStderr;
4747
const cmd = (0, child_process_1.spawn)(command, args, spawnOptions).on("close", (code, signal) => {
4848
resolve({
49-
exitCode: code !== null && code !== void 0 ? code : undefined,
50-
signal: signal !== null && signal !== void 0 ? signal : undefined,
49+
exitCode: code ?? undefined,
50+
signal: signal ?? undefined,
5151
stdout: bufferedStdout,
5252
stderr: bufferedStderr,
5353
});

build/tests/integration/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ function testAdapter(adapterDir, options = {}) {
4848
console.log(`Running tests in ${testDir}`);
4949
console.log();
5050
async function prepareTests() {
51-
var _a;
5251
// Installation may take a while - especially if rsa-compat needs to be installed
5352
const oneMinute = 60000;
5453
this.timeout(30 * oneMinute);
@@ -63,7 +62,7 @@ function testAdapter(adapterDir, options = {}) {
6362
// Only then we can install the adapter, because some (including VIS) try to access
6463
// the databases if JS Controller is installed
6564
await adapterSetup.installAdapterInTestDir();
66-
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
65+
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug"));
6766
await dbConnection.start();
6867
controllerSetup.setupSystemConfig(dbConnection);
6968
await controllerSetup.disableAdminInstances(dbConnection);
@@ -82,9 +81,8 @@ function testAdapter(adapterDir, options = {}) {
8281
harness.removeAllListeners();
8382
}
8483
async function resetDbAndStartHarness() {
85-
var _a, _b;
8684
this.timeout(30000);
87-
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
85+
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug"));
8886
// Clean up before every single test
8987
await Promise.all([
9088
controllerSetup.clearDBDir(),
@@ -98,7 +96,7 @@ function testAdapter(adapterDir, options = {}) {
9896
await harness.changeAdapterConfig(adapterName, {
9997
common: {
10098
enabled: true,
101-
loglevel: (_b = options.loglevel) !== null && _b !== void 0 ? _b : "debug",
99+
loglevel: options.loglevel ?? "debug",
102100
},
103101
});
104102
// And enable the sendTo emulation
@@ -110,9 +108,8 @@ function testAdapter(adapterDir, options = {}) {
110108
beforeEach(resetDbAndStartHarness);
111109
afterEach(shutdownTests);
112110
it("The adapter starts", function () {
113-
var _a;
114111
this.timeout(60000);
115-
const allowedExitCodes = new Set((_a = options.allowedExitCodes) !== null && _a !== void 0 ? _a : []);
112+
const allowedExitCodes = new Set(options.allowedExitCodes ?? []);
116113
// Adapters with these modes are allowed to "immediately" exit with code 0
117114
switch (harness.getAdapterExecutionMode()) {
118115
case "schedule":

build/tests/integration/lib/dbConnection.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// <reference types="iobroker" />
2+
/// <reference types="iobroker" />
3+
/// <reference types="node" />
24
/// <reference types="node" />
35
import EventEmitter from "events";
46
export declare type ObjectsDB = Record<string, ioBroker.Object>;

build/tests/integration/lib/dbConnection.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,16 @@ class DBConnection extends events_1.default {
152152
debug("DB instances started");
153153
}
154154
async stop() {
155-
var _a, _b, _c, _d;
156155
if (!this._isRunning) {
157156
debug("No DB instance is running, nothing to stop...");
158157
return;
159158
}
160159
debug("Stopping DB instances...");
161160
// Stop clients before servers
162-
await ((_a = this._objectsClient) === null || _a === void 0 ? void 0 : _a.destroy());
163-
await ((_b = this._objectsServer) === null || _b === void 0 ? void 0 : _b.destroy());
164-
await ((_c = this._statesClient) === null || _c === void 0 ? void 0 : _c.destroy());
165-
await ((_d = this._statesServer) === null || _d === void 0 ? void 0 : _d.destroy());
161+
await this._objectsClient?.destroy();
162+
await this._objectsServer?.destroy();
163+
await this._statesClient?.destroy();
164+
await this._statesServer?.destroy();
166165
this._objectsClient = null;
167166
this._objectsServer = null;
168167
this._statesClient = null;
@@ -279,20 +278,18 @@ class DBConnection extends events_1.default {
279278
this._statesClient.pushMessage(instanceId, msg, callback);
280279
}
281280
async getStateIDs(pattern = "*") {
282-
var _a, _b, _c, _d;
283281
if (!this._statesClient) {
284282
throw new Error("States DB is not running");
285283
}
286-
return (((_b = (_a = this._statesClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) ||
287-
((_d = (_c = this._statesClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern)));
284+
return (this._statesClient.getKeysAsync?.(pattern) ||
285+
this._statesClient.getKeys?.(pattern));
288286
}
289287
async getObjectIDs(pattern = "*") {
290-
var _a, _b, _c, _d;
291288
if (!this._objectsClient) {
292289
throw new Error("Objects DB is not running");
293290
}
294-
return (((_b = (_a = this._objectsClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) ||
295-
((_d = (_c = this._objectsClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern)));
291+
return (this._objectsClient.getKeysAsync?.(pattern) ||
292+
this._objectsClient.getKeys?.(pattern));
296293
}
297294
}
298295
exports.DBConnection = DBConnection;

build/tests/integration/lib/harness.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/// <reference types="iobroker" />
22
/// <reference types="node" />
3+
/// <reference types="node" />
4+
/// <reference types="iobroker" />
5+
/// <reference types="node" />
36
import { ChildProcess } from "child_process";
47
import { EventEmitter } from "events";
58
import type { DBConnection } from "./dbConnection";

build/tests/integration/lib/harness.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class TestHarness extends events_1.EventEmitter {
190190
if (!this.isAdapterRunning())
191191
return;
192192
return new Promise(async (resolve) => {
193-
var _a;
194193
const onClose = (code, signal) => {
195194
if (!this._adapterProcess)
196195
return;
@@ -214,7 +213,7 @@ class TestHarness extends events_1.EventEmitter {
214213
}
215214
catch {
216215
// DB connection may be closed already, kill the process
217-
(_a = this._adapterProcess) === null || _a === void 0 ? void 0 : _a.kill("SIGTERM");
216+
this._adapterProcess?.kill("SIGTERM");
218217
}
219218
});
220219
}

build/tests/integration/lib/logger.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ var LoglevelOrder;
1010
LoglevelOrder[LoglevelOrder["silly"] = 4] = "silly";
1111
})(LoglevelOrder || (LoglevelOrder = {}));
1212
function createLogger(loglevel) {
13-
var _a;
14-
const loglevelNumeric = (_a = LoglevelOrder[loglevel !== null && loglevel !== void 0 ? loglevel : "debug"]) !== null && _a !== void 0 ? _a : LoglevelOrder.debug;
13+
const loglevelNumeric = LoglevelOrder[loglevel ?? "debug"] ?? LoglevelOrder.debug;
1514
// eslint-disable-next-line @typescript-eslint/no-empty-function
1615
const ignore = () => { };
1716
return {

0 commit comments

Comments
 (0)