Skip to content

Drop Node 18 support #1927

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/meilisearch-prototype-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- '7700:7700'
strategy:
matrix:
node: ['18', '20', '22']
node: ['20', '22']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- '7700:7700'
strategy:
matrix:
node: ['18', '20', '22']
node: ['20', '22']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18', '20', '22']
node: ['20', '22']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume

To run this project, you will need:

- Node >= v18 and Node <= 22
- Node >= v20 and Node <= 22
- Yarn v1.x

### Setup
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
package:
image: node:18
image: node:22
tty: true
stdin_open: true
working_dir: /home/package
Expand Down
3 changes: 1 addition & 2 deletions src/http-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ function getHeaders(config: Config, headersInit?: HeadersInit): Headers {
return headers;
}

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

/**
* Attach a timeout signal to a {@link RequestInit}, while preserving original
Expand Down
3 changes: 1 addition & 2 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import type {
} from "./types/index.js";
import type { HttpRequests } from "./http-requests.js";

// TODO: Convert to Symbol("timeout id") when Node.js 18 is dropped
/**
* Used to identify whether an error is a timeout error in
* {@link TaskClient.waitForTask}.
*/
const TIMEOUT_ID = {};
const TIMEOUT_ID = Symbol("<task timeout>");

/**
* @returns A function which defines an extra function property on a
Expand Down
16 changes: 0 additions & 16 deletions src/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { webcrypto } from "node:crypto";
import type {
TenantTokenGeneratorOptions,
TenantTokenHeader,
Expand Down Expand Up @@ -31,19 +30,6 @@ function encodeToBase64(data: unknown): string {
return btoa(typeof data === "string" ? data : JSON.stringify(data));
}

// missing crypto global for Node.js 18 https://nodejs.org/api/globals.html#crypto_1
let cryptoPonyfill: Promise<Crypto | typeof webcrypto> | undefined;
function getCrypto(): NonNullable<typeof cryptoPonyfill> {
if (cryptoPonyfill === undefined) {
cryptoPonyfill =
typeof crypto === "undefined"
? import("node:crypto").then((v) => v.webcrypto)
: Promise.resolve(crypto);
}

return cryptoPonyfill;
}

const textEncoder = new TextEncoder();

/** Create the signature of the token. */
Expand All @@ -52,8 +38,6 @@ async function sign(
encodedPayload: string,
encodedHeader: string,
): Promise<string> {
const crypto = await getCrypto();

const cryptoKey = await crypto.subtle.importKey(
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#raw
"raw",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// We don't want to check node_modules
"skipLibCheck": true,
"module": "node18",
// Node.js 18 supports up to ES2022 according to https://www.npmjs.com/package/@tsconfig/node18
"target": "es2022",
// Node.js 20 at https://node.green/#ES2023
"target": "es2023",
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"resolveJsonModule": true,
"strict": true,
Expand Down
15 changes: 6 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default defineConfig(({ mode }) => {
minify: !isCJSBuild,
sourcemap: true,
// UMD build should target the lowest level ES,
// while CJS the lowest Node.js LTS compatible version
target: isCJSBuild ? "es2022" : "es6",
// while CJS the lowest Node.js LTS/Maintenance compatible version (https://node.green/#ES2023)
target: isCJSBuild ? "es2023" : "es6",
lib: {
// leave out token export from UMD build
entry: isCJSBuild ? [indexInput, tokenInput] : indexInput,
Expand All @@ -34,12 +34,8 @@ export default defineConfig(({ mode }) => {
}
},
},
rollupOptions: isCJSBuild
? {
// make sure external imports that should not be bundled are listed here for CJS build
external: ["node:crypto"],
}
: // the following code enables Vite in UMD mode to extend the global object with all of
rollupOptions: !isCJSBuild
? // the following code enables Vite in UMD mode to extend the global object with all of
// the exports, and not just a property of it ( https://github.com/vitejs/vite/issues/11624 )
// TODO: Remove this in the future ( https://github.com/meilisearch/meilisearch-js/issues/1806 )
{
Expand All @@ -52,7 +48,8 @@ export default defineConfig(({ mode }) => {
}
})();`,
},
},
}
: undefined,
},
test: {
include: ["tests/**/*.test.ts"],
Expand Down