Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backward-compatible code with Babel #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"default": {
"presets": [
["@babel/preset-env", {
"targets": "node 8.0",
"useBuiltIns": "usage",
"corejs": 3,
"exclude": ["es.promise", "es.string.trim"]
}]
]
},
"legacy": {
"presets": [
["@babel/preset-env", {
"targets": "node 0.10",
"useBuiltIns": "usage",
"corejs": 3
}]
]
},
}
}
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Built library assets
lib*

# Logs
logs
*.log
Expand All @@ -11,8 +14,9 @@ pids
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
# Coverage used by tools like istanbul
coverage
coverage.*

# nyc test coverage
.nyc_output
Expand All @@ -35,3 +39,9 @@ jspm_packages

# Optional REPL history
.node_repl_history

# OS-specific files
.DS_Store
.Trash*
.fseventsd
.Spotlight*
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!lib*/**/*.js
!lib*/**/*.js.map
!index.js
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
language: node_js
matrix:
include:
# Babel runtime aren't working on node <= 6
# - node_js: '0.10'
# env: _CXXAUTO=1
# env: BABEL_ENV=legacy
# - node_js: '0.12'
# env: _CXXAUTO=1
# env: BABEL_ENV=legacy
# - node_js: '4'
# env: CXX=g++-4.8
# env: BABEL_ENV=legacy
- node_js: '6'
# env: CXX=g++-4.8
env: BABEL_ENV=legacy
- node_js: '8'
# env: CXX=g++-4.8
- node_js: '10'
dist: trusty
sudo: required
Expand All @@ -35,6 +35,7 @@ before_script:
- (ls -la /var/lib/clickhouse/data/default/ || exit 0)
- (ls -la /var/lib/clickhouse/metadata/default/ || exit 0)
- curl -v "http://127.0.0.1:8123/"
- npm run legacy-install
script:
- npm run test
after_script:
- npm run report
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Tries to import library built for modern nodejs
try {
var nodeVer = process.version.substr(1).split ('.')
if (nodeVer[0] >= 6) {
return module.exports = require('./lib/clickhouse')
}
} catch (e) {}

// Tries to import library built for legacy nodejs
try {
module.exports = require('./lib-legacy/clickhouse')
} catch (e) {
// If all imports are failed it may be dev enviroment
module.exports = require('./src/clickhouse')
}
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"name": "@apla/clickhouse",
"version": "1.6.0",
"description": "Yandex ClickHouse database interface",
"main": "src/clickhouse.js",
"main": "index.js",
"scripts": {
"legacy-install": "node ./src/legacy-support.js",
"launch-docker-image": "docker run --rm -d -p 8123:8123 --name clickhouse-server yandex/clickhouse-server",
"stop-docker-image": "docker stop clickhouse-server",
"test": "nyc mocha --recursive ./test -R spec",
"test": "nyc mocha --require @babel/polyfill --require @babel/register --recursive ./test -R spec",
"report": "nyc report --reporter=lcov > coverage.lcov && codecov",
"simpletest": "mocha --recursive ./test -R spec",
"torturetest": "TORTURE=1 mocha -gc --recursive ./test -R spec"
"torturetest": "TORTURE=1 mocha -gc --recursive ./test -R spec",
"build": "rm -r lib*/; babel src -d lib --source-maps && BABEL_ENV=legacy babel src -d lib-legacy --source-maps",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
Expand All @@ -27,8 +28,18 @@
"url": "https://github.com/apla/node-clickhouse/issues"
},
"homepage": "https://github.com/apla/node-clickhouse#readme",
"dependencies": {},
"dependencies": {
"core-js": "3"
},
"optionalDependencies": {
"buffer-indexof-polyfill": "^1.0.1"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"bluebird": "^3.5.0",
"codecov": "^2.2.0",
"mocha": "^2.5.3",
Expand Down
7 changes: 4 additions & 3 deletions src/clickhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ var util = require ('util');

// var debug = require ('debug')('clickhouse');

require ('./legacy-support');

var RecordStream = require ('./streams').RecordStream;
var JSONStream = require ('./streams').JSONStream;

// node <6 polyfill
require('buffer-indexof-polyfill')

var parseError = require ('./parse-error');

function httpResponseHandler (stream, reqParams, reqData, cb, response) {
Expand Down Expand Up @@ -183,7 +184,7 @@ function httpRequest (reqParams, reqData, cb) {
stream.emit ('error', e);
return cb && cb (e);
});

req.on('timeout', function (e) {
req.abort();
})
Expand Down
46 changes: 0 additions & 46 deletions src/legacy-support.js

This file was deleted.