Skip to content

Commit

Permalink
Add babel build
Browse files Browse the repository at this point in the history
  • Loading branch information
nezed committed May 26, 2019
1 parent ecb2f06 commit fa0873c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 58 deletions.
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
}]
]
},
}
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Built library assets
lib*

# Logs
logs
*.log
Expand Down Expand Up @@ -35,3 +38,9 @@ jspm_packages

# Optional REPL history
.node_repl_history

# OS-specific files
.DS_Store
.Trash*
.fseventsd
.Spotlight*
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!lib*/**/*.js
!lib*/**/*.js.map
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js
matrix:
include:
# - node_js: '0.10'
# env: _CXXAUTO=1
# - node_js: '0.12'
# env: _CXXAUTO=1
- node_js: '0.10'
env: BABEL_ENV=legacy
- node_js: '0.12'
env: BABEL_ENV=legacy
# - node_js: '4'
# env: CXX=g++-4.8
- node_js: '6'
Expand All @@ -22,6 +22,7 @@ addons:
# - gcc-4.8
# - g++-4.8
before_script:
- npm run build
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E0C56BD4
- echo "deb http://repo.yandex.ru/clickhouse/deb/stable/ main/" | sudo tee -a /etc/apt/sources.list
- sudo apt-get update -qq
Expand All @@ -35,6 +36,5 @@ 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
after_script:
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')
}
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"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"
},
"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/preset-env": "^7.4.5",
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"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.

0 comments on commit fa0873c

Please sign in to comment.