Skip to content

Commit 22de806

Browse files
authored
Disable client Helpers in Node.js < 10. (#1194)
1 parent b109f60 commit 22de806

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
6464
- name: Test
6565
run: |
66-
npm run test:unit -- --node-arg=--harmony-async-iteration
66+
npm run test:node8
6767
6868
helpers-integration-test:
6969
name: Helpers integration test

docs/helpers.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
The client comes with an handy collection of helpers to give you a more comfortable experience with some APIs.
55

66
CAUTION: The client helpers are experimental, and the API may change in the next minor releases.
7-
If you are using the client with Node.js v8 you should run your code with the `--harmony-async-iteration` argument. +
8-
eg: `node --harmony-async-iteration index.js`
7+
The helpers will not work in any Node.js version lower than 10.
98

109
=== Bulk Helper
1110
Running Bulk requests can be complex due to the shape of the API, this helper aims to provide a nicer developer experience around the Bulk API.

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
'use strict'
66

7+
const nodeMajor = Number(process.versions.node.split('.')[0])
8+
79
const { EventEmitter } = require('events')
810
const { URL } = require('url')
911
const debug = require('debug')('elasticsearch')
1012
const Transport = require('./lib/Transport')
1113
const Connection = require('./lib/Connection')
1214
const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
13-
const Helpers = require('./lib/Helpers')
15+
// Helpers works only in Node.js >= 10
16+
const Helpers = nodeMajor < 10 ? null : require('./lib/Helpers')
1417
const Serializer = require('./lib/Serializer')
1518
const errors = require('./lib/errors')
1619
const { ConfigurationError } = errors
@@ -127,7 +130,9 @@ class Client extends EventEmitter {
127130
opaqueIdPrefix: options.opaqueIdPrefix
128131
})
129132

130-
this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
133+
if (Helpers !== null) {
134+
this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
135+
}
131136

132137
const apis = buildApi({
133138
makeRequest: this.transport.request.bind(this.transport),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"scripts": {
1919
"test": "npm run lint && npm run test:unit && npm run test:behavior && npm run test:types",
20+
"test:node8": "npm run lint && tap test/unit/*.test.js -t 300 --no-coverage && npm run test:behavior && npm run test:types",
2021
"test:unit": "tap test/unit/*.test.js test/unit/**/*.test.js -t 300 --no-coverage",
2122
"test:behavior": "tap test/behavior/*.test.js -t 300 --no-coverage",
2223
"test:integration": "node test/integration/index.js",

0 commit comments

Comments
 (0)