ESM support (#1235)

This commit is contained in:
Tomas Della Vedova
2020-06-26 11:57:43 +02:00
committed by GitHub
parent 148f2fd864
commit d16781e379
4 changed files with 46 additions and 1 deletions

10
index.mjs Normal file
View File

@ -0,0 +1,10 @@
import mod from './index.js'
export default mod
export const Client = mod.Client
export const Transport = mod.Transport
export const ConnectionPool = mod.ConnectionPool
export const Connection = mod.Connection
export const Serializer = mod.Serializer
export const events = mod.events
export const errors = mod.errors

View File

@ -3,6 +3,13 @@
"description": "The official Elasticsearch client for Node.js",
"main": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"require": "./index.js",
"import": "./index.mjs"
},
"./": "./"
},
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
"version": "8.0.0-SNAPSHOT.9f33e3c7",
"keywords": [
@ -28,7 +35,8 @@
"test:coverage-ui": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --coverage-report=html --nyc-arg=\"--exclude=api\"",
"lint": "standard",
"lint:fix": "standard --fix",
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'"
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'",
"build-esm": "npx gen-esm-wrapper . index.mjs && standard --fix index.mjs"
},
"author": {
"name": "Tomas Della Vedova",

8
test/unit/esm/index.mjs Normal file
View File

@ -0,0 +1,8 @@
import t from 'tap'
import { Client } from '../../../index.mjs'
t.test('esm support', t => {
t.plan(1)
const client = new Client({ node: 'http://localhost:9200' })
t.strictEqual(client.name, 'elasticsearch-js')
})

View File

@ -0,0 +1,19 @@
'use strict'
const t = require('tap')
const semver = require('semver')
if (semver.lt(process.versions.node, '12.17.0')) {
t.skip('Skip because Node version < 12.17.0')
t.end()
} else {
// Node v8 throw a `SyntaxError: Unexpected token import`
// even if this branch is never touch in the code,
// by using `eval` we can avoid this issue.
// eslint-disable-next-line
new Function('module', 'return import(module)')('./index.mjs').catch((err) => {
process.nextTick(() => {
throw err
})
})
}