Skip to content

Commit a305def

Browse files
flevi29Strift
authored andcommitted
Remove all Node.js 18 references, adapt code to version 20
1 parent 45eabe1 commit a305def

File tree

10 files changed

+15
-36
lines changed

10 files changed

+15
-36
lines changed

.github/workflows/meilisearch-prototype-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- '7700:7700'
4747
strategy:
4848
matrix:
49-
node: ['18', '20', '22']
49+
node: ['20', '22']
5050
name: integration-tests (Node.js ${{ matrix.node }})
5151
steps:
5252
- uses: actions/checkout@v4

.github/workflows/pre-release-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- '7700:7700'
4444
strategy:
4545
matrix:
46-
node: ['18', '20', '22']
46+
node: ['20', '22']
4747
name: integration-tests (Node.js ${{ matrix.node }})
4848
steps:
4949
- uses: actions/checkout@v4

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
node: ['18', '20', '22']
39+
node: ['20', '22']
4040
name: integration-tests (Node.js ${{ matrix.node }})
4141
steps:
4242
- uses: actions/checkout@v4

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
3434

3535
To run this project, you will need:
3636

37-
- Node >= v18 and Node <= 22
37+
- Node >= v20 and Node <= 22
3838
- Yarn v1.x
3939

4040
### Setup

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
package:
3-
image: node:18
3+
image: node:22
44
tty: true
55
stdin_open: true
66
working_dir: /home/package

src/http-requests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ function getHeaders(config: Config, headersInit?: HeadersInit): Headers {
6969
return headers;
7070
}
7171

72-
// TODO: Convert to Symbol("timeout id") when Node.js 18 is dropped
7372
/** Used to identify whether an error is a timeout error after fetch request. */
74-
const TIMEOUT_ID = {};
73+
const TIMEOUT_ID = Symbol("<timeout>");
7574

7675
/**
7776
* Attach a timeout signal to a {@link RequestInit}, while preserving original

src/task.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import type {
1212
} from "./types/index.js";
1313
import type { HttpRequests } from "./http-requests.js";
1414

15-
// TODO: Convert to Symbol("timeout id") when Node.js 18 is dropped
1615
/**
1716
* Used to identify whether an error is a timeout error in
1817
* {@link TaskClient.waitForTask}.
1918
*/
20-
const TIMEOUT_ID = {};
19+
const TIMEOUT_ID = Symbol("<task timeout>");
2120

2221
/**
2322
* @returns A function which defines an extra function property on a

src/token.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { webcrypto } from "node:crypto";
21
import type {
32
TenantTokenGeneratorOptions,
43
TenantTokenHeader,
@@ -31,19 +30,6 @@ function encodeToBase64(data: unknown): string {
3130
return btoa(typeof data === "string" ? data : JSON.stringify(data));
3231
}
3332

34-
// missing crypto global for Node.js 18 https://nodejs.org/api/globals.html#crypto_1
35-
let cryptoPonyfill: Promise<Crypto | typeof webcrypto> | undefined;
36-
function getCrypto(): NonNullable<typeof cryptoPonyfill> {
37-
if (cryptoPonyfill === undefined) {
38-
cryptoPonyfill =
39-
typeof crypto === "undefined"
40-
? import("node:crypto").then((v) => v.webcrypto)
41-
: Promise.resolve(crypto);
42-
}
43-
44-
return cryptoPonyfill;
45-
}
46-
4733
const textEncoder = new TextEncoder();
4834

4935
/** Create the signature of the token. */
@@ -52,8 +38,6 @@ async function sign(
5238
encodedPayload: string,
5339
encodedHeader: string,
5440
): Promise<string> {
55-
const crypto = await getCrypto();
56-
5741
const cryptoKey = await crypto.subtle.importKey(
5842
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#raw
5943
"raw",

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// We don't want to check node_modules
44
"skipLibCheck": true,
55
"module": "node18",
6-
// Node.js 18 supports up to ES2022 according to https://www.npmjs.com/package/@tsconfig/node18
7-
"target": "es2022",
6+
// Node.js 20 at https://node.green/#ES2023
7+
"target": "es2023",
88
"lib": ["ESNext", "DOM", "DOM.Iterable"],
99
"resolveJsonModule": true,
1010
"strict": true,

vite.config.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default defineConfig(({ mode }) => {
1616
minify: !isCJSBuild,
1717
sourcemap: true,
1818
// UMD build should target the lowest level ES,
19-
// while CJS the lowest Node.js LTS compatible version
20-
target: isCJSBuild ? "es2022" : "es6",
19+
// while CJS the lowest Node.js LTS compatible version (https://node.green/#ES2023)
20+
target: isCJSBuild ? "es2023" : "es6",
2121
lib: {
2222
// leave out token export from UMD build
2323
entry: isCJSBuild ? [indexInput, tokenInput] : indexInput,
@@ -34,12 +34,8 @@ export default defineConfig(({ mode }) => {
3434
}
3535
},
3636
},
37-
rollupOptions: isCJSBuild
38-
? {
39-
// make sure external imports that should not be bundled are listed here for CJS build
40-
external: ["node:crypto"],
41-
}
42-
: // the following code enables Vite in UMD mode to extend the global object with all of
37+
rollupOptions: !isCJSBuild
38+
? // the following code enables Vite in UMD mode to extend the global object with all of
4339
// the exports, and not just a property of it ( https://github.com/vitejs/vite/issues/11624 )
4440
// TODO: Remove this in the future ( https://github.com/meilisearch/meilisearch-js/issues/1806 )
4541
{
@@ -52,7 +48,8 @@ export default defineConfig(({ mode }) => {
5248
}
5349
})();`,
5450
},
55-
},
51+
}
52+
: undefined,
5653
},
5754
test: {
5855
include: ["tests/**/*.test.ts"],

0 commit comments

Comments
 (0)