Skip to content

Commit

Permalink
Drop Node.js 16, remove ecmaVersion question, pin chai to v4 (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jan 5, 2024
1 parent dc0c265 commit c6655d3
Show file tree
Hide file tree
Showing 123 changed files with 2,139 additions and 1,711 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
project: "./tsconfig.json",
},
Expand Down
2 changes: 1 addition & 1 deletion .github/test_template_creation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mkdir ioBroker.template
trap 'rm -rf ioBroker.template' EXIT

# Test the template creation
TESTING=true node --require ts-node/register create_templates.ts
TESTING=true node --require tsx/cjs create_templates.ts
4 changes: 2 additions & 2 deletions .github/update_templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm -rf ioBroker.template
git clone https://github.com/ioBroker/ioBroker.template

# Create all templates
node --require ts-node/register create_templates.ts
node --require tsx/cjs create_templates.ts

# Commit the changes
cd ioBroker.template
Expand All @@ -33,4 +33,4 @@ git push -u origin $BRANCH_NAME

# Create PR in the ioBroker repo
cd ..
node --require ts-node/register create_pullrequest.ts
node --require tsx/cjs create_pullrequest.ts
6 changes: 3 additions & 3 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Start the CLI on a production environment
run: |
npm ci --only=production
npm ci --omit=dev
TEST_STARTUP=true node ./bin/create-adapter.js
# TODO: Test the console output

Expand All @@ -78,7 +78,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": [
"./test/mocha.setup.js",
"ts-node/register",
"tsx/cjs",
"source-map-support/register"
],
"watch-files": ["src/**/*.test.ts"]
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
## __WORK IN PROGRESS__
(at the beginning of a new line )
-->
## __WORK IN PROGRESS__
* (AlCalzone) Change supported Node.js versions to 18 / 20 (#1082) · [Migration guide](docs/updates/20240105_min_node18.md)
* (AlCalzone) Simplify maintenance of ESLint config by using the `"latest"` parser version (#1082) · [Migration guide](docs/updates/20240105_ecmaversion_latest.md)
* (AlCalzone) Pin `chai` dependency to version 4 (#1082)

## 2.5.0 (2023-07-06)
* (mcm1957) Add `admin/words.js` to `.eslintignore` · [Migration guide](docs/updates/20230507_eslintignore_words_js.md)
* (mcm1957) Change supported Node.js versions to 16 / 18 / 20 (#1032) · [Migration guide](docs/updates/20230507_update_node_versions.md)
Expand Down
22 changes: 22 additions & 0 deletions docs/updates/20240105_ecmaversion_latest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Simplify maintenance of ESLint config by using the `"latest"` parser version

Previously, ESLint required the developer to specify which ECMAScript version to use for parsing. When using newer JavaScript features, this setting had to be changed for ESLint to work.
It is now possible to set the field to `"latest"`, which will make further changes unnecessary.

To do this, edit the ESLint config as follows (2022 can be a diffent number currently):

**If you have a file `.eslintrc.json`:**

```diff
"parserOptions": {
- "ecmaVersion": 2022,
+ "ecmaVersion": "latest",
```

**If you have a file `.eslintrc.js`:**

```diff
parserOptions: {
- ecmaVersion: 2022,
+ ecmaVersion: "latest",
```
91 changes: 91 additions & 0 deletions docs/updates/20240105_min_node18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Update package configuration to reflect minimum Node.js version required

As Node.js 16 is EOL and Node.js 20 is already available, new adapters should support either Node.js 18 or 20 as the minimum version. There are a few changes necessary in `package.json` to reflect this when upgrading an existing adapter.

The `engines` field must specify the minimum version:

```diff
"engines": {
- "node": ">= 16"
+ "node": ">= 18"
},
```

```diff
"engines": {
- "node": ">= 16"
+ "node": ">= 20"
},
```

In addition, the testing workflow also needs to be updated. To do this, edit `.github/workflows/test-and-release.yml` as follows:

```diff
steps:
- uses: ioBroker/testing-action-check@v1
with:
- node-version: '16.x'
+ node-version: '18.x'
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
# install-command: 'npm install'
lint: true
...
runs-on: ${{ matrix.os }}
strategy:
matrix:
- node-version: [16.x, 18.x, 20.x]
+ node-version: [18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
...
# steps:
# - uses: ioBroker/testing-action-deploy@v1
# with:
-# node-version: '16.x'
+# node-version: '18.x'
# # Uncomment the following line if your adapter cannot be installed using 'npm ci'
# # install-command: 'npm install'
# npm-token: ${{ secrets.NPM_TOKEN }}
```

---

When using TypeScript or when type-checking is enabled, the type definitions and `tsconfig.json` need to be updated aswell.
First, update TypeScript itself:

```bash
npm i -D "typescript@~5.3.3"
```

To update the Node.js type definitions, run **one** of the following commands depending on the desired Node.js version:

```bash
npm i -D @types/node@18
npm i -D @types/node@20
```

Next, uninstall the old tsconfig base:

```bash
npm uninstall -D @tsconfig/node16
```

(or an even older version if you still use that).

Then, run **one** of the following commands depending on the desired Node.js version:

```bash
npm i -D @tsconfig/node18
npm i -D @tsconfig/node20
```

Last, reference this new base in your `tsconfig.json` by replacing `node16` with the version you just installed the tsconfig for, e.g. `node18` for Node.js 18:

```diff
{
- "extends": "@tsconfig/node16/tsconfig.json",
+ "extends": "@tsconfig/node18/tsconfig.json",
// ...
}
```
Loading

0 comments on commit c6655d3

Please sign in to comment.