From 11951fe8fc5b77b0d5ee9dfd7d6588eb5bfb31fb Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Thu, 14 May 2020 16:03:08 +0200 Subject: [PATCH] Disable client Helpers in Node.js < 10. (#1194) --- .github/workflows/nodejs.yml | 2 +- docs/helpers.asciidoc | 3 +-- index.js | 9 +++++++-- package.json | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 94e26bd3c..a3525de58 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -63,7 +63,7 @@ jobs: - name: Test run: | - npm run test:unit -- --node-arg=--harmony-async-iteration + npm run test:node8 helpers-integration-test: name: Helpers integration test diff --git a/docs/helpers.asciidoc b/docs/helpers.asciidoc index 5933e87f3..fa5465f48 100644 --- a/docs/helpers.asciidoc +++ b/docs/helpers.asciidoc @@ -4,8 +4,7 @@ The client comes with an handy collection of helpers to give you a more comfortable experience with some APIs. CAUTION: The client helpers are experimental, and the API may change in the next minor releases. -If you are using the client with Node.js v8 you should run your code with the `--harmony-async-iteration` argument. + -eg: `node --harmony-async-iteration index.js` +The helpers will not work in any Node.js version lower than 10. === Bulk Helper 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. diff --git a/index.js b/index.js index 7a545b566..07a737fc6 100644 --- a/index.js +++ b/index.js @@ -4,13 +4,16 @@ 'use strict' +const nodeMajor = Number(process.versions.node.split('.')[0]) + const { EventEmitter } = require('events') const { URL } = require('url') const debug = require('debug')('elasticsearch') const Transport = require('./lib/Transport') const Connection = require('./lib/Connection') const { ConnectionPool, CloudConnectionPool } = require('./lib/pool') -const Helpers = require('./lib/Helpers') +// Helpers works only in Node.js >= 10 +const Helpers = nodeMajor < 10 ? null : require('./lib/Helpers') const Serializer = require('./lib/Serializer') const errors = require('./lib/errors') const { ConfigurationError } = errors @@ -127,7 +130,9 @@ class Client extends EventEmitter { opaqueIdPrefix: options.opaqueIdPrefix }) - this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries }) + if (Helpers !== null) { + this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries }) + } const apis = buildApi({ makeRequest: this.transport.request.bind(this.transport), diff --git a/package.json b/package.json index 809737619..03ab14a59 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ ], "scripts": { "test": "npm run lint && npm run test:unit && npm run test:behavior && npm run test:types", + "test:node8": "npm run lint && tap test/unit/*.test.js -t 300 --no-coverage && npm run test:behavior && npm run test:types", "test:unit": "tap test/unit/*.test.js test/unit/**/*.test.js -t 300 --no-coverage", "test:behavior": "tap test/behavior/*.test.js -t 300 --no-coverage", "test:integration": "node test/integration/index.js",