Skip to content

Commit 4b58d3e

Browse files
Backports to 9.3 (#3178)
* Bump to 9.3.1 (#3176) * fix bundle issue (#3175) --------- Co-authored-by: margaretjgu <136839162+margaretjgu@users.noreply.github.com>
1 parent e0fef9a commit 4b58d3e

8 files changed

Lines changed: 101 additions & 11 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,32 @@ jobs:
123123
shell: bash
124124
run: |
125125
[ "$CODE_CHANGED" = "true" ] && bun run test:esm || exit 0
126+
127+
test-bundler:
128+
name: Test ESM bundle (Bun/Rolldown compatibility)
129+
runs-on: ubuntu-latest
130+
needs: paths-filter
131+
env:
132+
CODE_CHANGED: ${{ needs.paths-filter.outputs.src-only }}
133+
134+
steps:
135+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
136+
with:
137+
persist-credentials: false
138+
139+
- name: Use Node.js
140+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
141+
with:
142+
node-version: 24.x
143+
144+
- name: Install
145+
run: npm install
146+
147+
- name: Bundler test (esbuild bundle + run)
148+
shell: bash
149+
run: |
150+
if [ "$CODE_CHANGED" = "true" ]; then
151+
npm run test:bundler;
152+
else
153+
exit 0;
154+
fi

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ test/benchmarks/macro/fixtures/*
6060
.cache
6161

6262
test/bundlers/**/bundle.js
63+
test/bundlers/**/bundled.js
6364
test/bundlers/parcel-test/.parcel-cache
6465

6566
lib
6667
esm/
68+
src/version.generated.ts
6769
junit-output
6870
bun.lockb
6971
test-results

docs/release-notes/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ To check for security updates, go to [Security announcements for the Elastic sta
2020
% ### Fixes [elasticsearch-javascript-client-next-fixes]
2121
% \*
2222

23+
## 9.3.1 [elasticsearch-javascript-client-9.3.1-release-notes]
24+
25+
### Fixes [elasticsearch-javascript-client-9.3.1-fixes]
26+
27+
- **Improved ESM compatibility:** Ensure `estypes` is exported for ESM-based projects, and that ESM modules work correctly for JavaScript bundlers.
28+
- **Improved compatibility with Elasticsearch 9.3:** improvements and corrections have been made to the Elasticsearch specification for 9.3 that are reflected here.
29+
2330
## 9.3.0 [elasticsearch-javascript-client-9.3.0-release-notes]
2431

2532
### Features and enhancements [elasticsearch-javascript-client-9.3.0-features-enhancements]

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@elastic/elasticsearch",
3-
"version": "9.3.0",
4-
"versionCanary": "9.3.0-canary.0",
3+
"version": "9.3.1",
4+
"versionCanary": "9.3.1-canary.0",
55
"description": "The official Elasticsearch client for Node.js",
66
"type": "commonjs",
77
"main": "./index.js",
@@ -28,6 +28,7 @@
2828
"test": "npm run build && npm run lint && c8 --exclude='**/api/**' --exclude='**/test/**' --check-coverage --statements=96 --branches=90 --lines=96 --functions=88 tap --disable-coverage",
2929
"test:unit": "npm run build && tap",
3030
"test:unit-bun": "bun run build && bunx tap",
31+
"test:bundler": "npm run build && cd test/bundlers/repro && npm install file:../../.. && npx esbuild@0.24 --bundle --platform=node repro.mjs --outfile=bundled.js && node bundled.js",
3132
"test:esm": "npm run build:esm && tap test/esm/",
3233
"test:coverage-100": "npm run build && tap --coverage --100",
3334
"test:coverage-report": "npm run build && tap --coverage && nyc report --reporter=text-lcov > coverage.lcov",
@@ -38,7 +39,8 @@
3839
"lint:fix": "ts-standard --fix src",
3940
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'",
4041
"license-header": "./scripts/check-spdx",
41-
"prebuild": "npm run clean-build && npm run lint",
42+
"generate-version": "node scripts/generate-version.js",
43+
"prebuild": "npm run clean-build && npm run generate-version && npm run lint",
4244
"build": "npm run build:cjs && npm run build:esm",
4345
"build:cjs": "tsc && rm -f lib/package.json lib/index.js lib/index.d.ts",
4446
"build:esm": "tsc -p tsconfig.esm.json && npm run build:esm-fix && npm run build:esm-package",
@@ -113,7 +115,7 @@
113115
"zx": "8.8.0"
114116
},
115117
"dependencies": {
116-
"@elastic/transport": "^9.3.2",
118+
"@elastic/transport": "^9.3.3",
117119
"apache-arrow": "18.x - 21.x",
118120
"tslib": "^2.4.0"
119121
}

scripts/generate-version.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Copyright Elasticsearch B.V. and contributors
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
const fs = require('fs')
8+
const path = require('path')
9+
10+
const rootDir = path.join(__dirname, '..')
11+
const clientPkg = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'))
12+
let transportVersion = '0.0.0'
13+
try {
14+
const transportPkgPath = require.resolve('@elastic/transport/package.json', { paths: [rootDir] })
15+
const transportPkg = JSON.parse(fs.readFileSync(transportPkgPath, 'utf8'))
16+
transportVersion = transportPkg.version
17+
} catch (_) {
18+
// @elastic/transport not installed (e.g. pre-install); use placeholder 0.0.0
19+
}
20+
21+
const outPath = path.join(rootDir, 'src', 'version.generated.ts')
22+
const content = `/*
23+
* Copyright Elasticsearch B.V. and contributors
24+
* SPDX-License-Identifier: Apache-2.0
25+
*
26+
* Generated by scripts/generate-version.js - do not edit manually.
27+
*/
28+
29+
export const clientVersion: string = '${clientPkg.version}'
30+
export const transportVersion: string = '${transportVersion}'
31+
`
32+
33+
fs.writeFileSync(outPath, content, 'utf8')
34+
console.log(`Generated ${outPath} (client: ${clientPkg.version}, transport: ${transportVersion})`)

src/client.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,19 @@ import SniffingTransport from './sniffingTransport'
3737
import Helpers from './helpers'
3838
import API from './api'
3939
import { kAcceptedParams } from './symbols'
40-
41-
/* eslint-disable @typescript-eslint/no-var-requires */
42-
const packageJson = require('../package.json')
43-
const transportPackageJson = require('@elastic/transport/package.json')
44-
/* eslint-enable @typescript-eslint/no-var-requires */
40+
import { clientVersion as rawClientVersion, transportVersion as rawTransportVersion } from './version.generated'
4541

4642
const kChild = Symbol('elasticsearchjs-child')
4743
const kInitialOptions = Symbol('elasticsearchjs-initial-options')
4844
export { kAcceptedParams }
4945

50-
let clientVersion: string = packageJson.version
46+
let clientVersion: string = rawClientVersion
5147
/* istanbul ignore next */
5248
if (clientVersion.includes('-')) {
5349
// clean prerelease
5450
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
5551
}
56-
let transportVersion: string = transportPackageJson.version // eslint-disable-line
52+
let transportVersion: string = rawTransportVersion
5753
/* istanbul ignore next */
5854
if (transportVersion.includes('-')) {
5955
// clean prerelease

test/bundlers/repro/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "repro",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "Minimal repro for ESM bundling regression",
6+
"license": "Apache-2.0",
7+
"type": "commonjs",
8+
"dependencies": {
9+
"@elastic/elasticsearch": "file:../../.."
10+
}
11+
}

test/bundlers/repro/repro.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { Client } from "@elastic/elasticsearch"
7+
const c = new Client({ node: "http://localhost:9200" })
8+
console.log("Client created:", typeof c)
9+
process.exit(0)

0 commit comments

Comments
 (0)