From b937fb9507e6591eccfd383c5606f39575311743 Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Mon, 18 Nov 2024 11:39:42 -0600 Subject: [PATCH 1/3] Fix import support for ESM-based projects --- .github/workflows/nodejs.yml | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index e984adb53..11f181fa3 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -32,7 +32,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x, 20.x, 22.x] + node-version: [18.x, 20.x, 22.x, 23.x] os: [ubuntu-latest, windows-latest, macOS-latest] steps: diff --git a/package.json b/package.json index 929f01d52..4fd970fd8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "./index.js", "types": "index.d.ts", "exports": { - "require": "./index.js" + "require": "./index.js", + "import": "./index.js" }, "scripts": { "test": "npm run build && npm run lint && tap", From 3ff779893a4bda8f72bceff3c8b9530f79c9d8ab Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Mon, 18 Nov 2024 12:01:19 -0600 Subject: [PATCH 2/3] Add quick ESM smoke test Ensures ECMAScript import works --- .github/workflows/nodejs.yml | 8 ++++++++ package.json | 1 + test/esm/package.json | 7 +++++++ test/esm/test-import.mjs | 28 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/esm/package.json create mode 100644 test/esm/test-import.mjs diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 11f181fa3..85f8131d3 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -57,6 +57,10 @@ jobs: run: | npm run test:unit + - name: ECMAScript module test + run: | + npm run test:esm + license: name: License check runs-on: ubuntu-latest @@ -110,3 +114,7 @@ jobs: - name: Unit test run: | bun run test:unit-bun + + - name: ECMAScript module test + run: | + bun run test:esm diff --git a/package.json b/package.json index 4fd970fd8..31b24834e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "test": "npm run build && npm run lint && tap", "test:unit": "npm run build && tap", "test:unit-bun": "bun run build && bunx tap", + "test:esm": "npm run build && cd test/esm/ && npm install && node test-import.mjs", "test:coverage-100": "npm run build && tap --coverage --100", "test:coverage-report": "npm run build && tap --coverage && nyc report --reporter=text-lcov > coverage.lcov", "test:coverage-ui": "npm run build && tap --coverage --coverage-report=html", diff --git a/test/esm/package.json b/test/esm/package.json new file mode 100644 index 000000000..5209563e8 --- /dev/null +++ b/test/esm/package.json @@ -0,0 +1,7 @@ +{ + "name": "esm", + "version": "1.0.0", + "dependencies": { + "@elastic/elasticsearch": "file:../.." + } +} diff --git a/test/esm/test-import.mjs b/test/esm/test-import.mjs new file mode 100644 index 000000000..f7a6f09e6 --- /dev/null +++ b/test/esm/test-import.mjs @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Client } from '@elastic/elasticsearch' + +new Client({ + node: 'http://localhost:9200', + auth: { + username: 'elastic', + password: 'changeme', + } +}) From 626ba4e8a7e9620f4a822350beca5d3813fa8e0e Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Mon, 18 Nov 2024 12:08:29 -0600 Subject: [PATCH 3/3] Add types export --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 31b24834e..57b95f15e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "types": "index.d.ts", "exports": { "require": "./index.js", - "import": "./index.js" + "import": "./index.js", + "types": "./index.d.ts" }, "scripts": { "test": "npm run build && npm run lint && tap",