From 68a3949327cc8ae081bbfe30269c0668f53a5fc7 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Wed, 13 Jan 2016 02:58:11 -0800 Subject: [PATCH 1/5] chore(package): update lodash.bind to version 4.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7ca32b..76e7c32 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "license": "MIT", "dependencies": { "debug": "^2.2.0", - "lodash.bind": "^3.1.0", + "lodash.bind": "^4.0.0", "uuid": "^2.0.1", "ws": "^1.0.1" }, From 98fa13c9f99ec0afc9039b7fddad22df8fa43698 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Wed, 13 Jan 2016 14:58:51 -0800 Subject: [PATCH 2/5] fix(dependencies) move bind polyfill into test script Instead of using lodash.bind in the main code, just override function.prototype.bind during the browser test code --- browser/index.js | 2 ++ lib/connection.js | 10 +++------- package.json | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/browser/index.js b/browser/index.js index 5bc93cb..73000f1 100644 --- a/browser/index.js +++ b/browser/index.js @@ -7,6 +7,8 @@ var JsonRpcWs = require('../browser'); var browserClient = JsonRpcWs.createClient(); +Function.prototype.bind = require('function-bind'); + browserClient.expose('info', function info (params, reply) { reply(null, 'browser'); diff --git a/lib/connection.js b/lib/connection.js index 0b18784..a225c6b 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -2,7 +2,6 @@ var uuid = require('uuid').v4; var logger = require('debug')('json-rpc-ws'); var Errors = require('./errors'); var Assert = require('assert'); -var Bind = require('lodash.bind'); /** * Quarantined JSON.parse try/catch block in its own function @@ -65,9 +64,9 @@ var Connection = function Connection (socket, parent) { this.parent = parent; this.responseHandlers = {}; if (this.parent.browser) { - this.socket.onmessage = Bind(this.message, this); - this.socket.onclose = Bind(socketClosed, this); - this.socket.onerror = Bind(socketError, this); + this.socket.onmessage = this.message.bind(this) + this.socket.onclose = socketClosed.bind(this); + this.socket.onerror = socketError.bind(this); } else { this.socket.on('message', this.message.bind(this)); this.socket.once('close', this.close.bind(this)); @@ -130,9 +129,6 @@ Connection.prototype.processPayload = function processPayload (payload) { logger('handler got callback %j, %j', err, reply); return this.sendResult(id, err, reply); }; - if (this.parent.browser) { - return handler.call(this, params, Bind(handlerCallback, this)); - } return handler.call(this, params, handlerCallback.bind(this)); } // needs a result or error at this point diff --git a/package.json b/package.json index 76e7c32..6f10a40 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "license": "MIT", "dependencies": { "debug": "^2.2.0", - "lodash.bind": "^4.0.0", "uuid": "^2.0.1", "ws": "^1.0.1" }, @@ -46,6 +45,7 @@ "code": "^2.0.1", "eslint": "^1.1.0", "eslint-plugin-hapi": "^4.0.0", + "function-bind": "^1.0.2", "git-validate": "^2.0.3", "jsdoc": "^3.3.2", "lab": "^8.0.0", From b9f669c6ba64e3bfc1cd30f2992f885c9efb624d Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Wed, 13 Jan 2016 15:00:59 -0800 Subject: [PATCH 3/5] fix(linting) update linting rules Switch to eslint-config-andyet/es5 --- .eslintrc | 79 ++-------------------------------------------------- package.json | 1 + 2 files changed, 4 insertions(+), 76 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5021f57..099491b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,78 +1,5 @@ { - "plugins": [ - "eslint-plugin-hapi" - ], - "rules": { - "consistent-return": 0, - "vars-on-top": 0, - "one-var": 0, - "strict": 0, - "new-cap": 0, - "no-console": 0, - "no-constant-condition": 0, - "no-empty": 0, - "no-native-reassign": 0, - "no-underscore-dangle": 0, - "no-undef": 0, - "no-process-exit": 0, - "no-unused-vars": 0, - "no-use-before-define": 0, - "no-unused-expressions": 0, - "no-regex-spaces": 0, - "no-catch-shadow": 0, - "global-strict": 0, - "handle-callback-err": 0, - "no-lonely-if": 0, - "space-in-brackets": 0, - "brace-style": 0, - "no-shadow": 0, - "hapi/no-shadow-relaxed": [1, { "ignore": ["err", "done"] }], - "hapi/hapi-capitalize-modules": [1, "global-scope-only"], - "hapi/hapi-scope-start": 1, - "array-bracket-spacing": 1, - "dot-notation": 1, - "eol-last": 1, - "camelcase": 1, - "no-trailing-spaces": 1, - "no-eq-null": 1, - "no-extend-native": 1, - "no-redeclare": 1, - "no-loop-func": 1, - "yoda": [1, "never"], - "sort-vars": 1, - "quotes": [2, "single"], - "consistent-this": [2, "self"], - "func-style": [2, "expression"], - "new-parens": 2, - "no-array-constructor": 2, - "no-new-object": 2, - "no-spaced-func": 2, - "no-mixed-spaces-and-tabs": 2, - "space-after-keywords": 2, - "semi": [2, "always"], - "semi-spacing": [2, { "before": false, "after": true }], - "space-infix-ops": 2, - "space-return-throw-case": 2, - "space-unary-ops": [1, { "words": true, "nonwords": false }], - "eqeqeq": 2, - "curly": [2, "all"], - "no-eval": 2, - "no-else-return": 2, - "no-return-assign": 2, - "no-new-wrappers": 2, - "comma-dangle": [2, "never"], - "no-sparse-arrays": 2, - "no-ex-assign": 2, - "indent": [2, 4], - "space-before-function-paren": 2, - "func-style": [2, "expression"], - "object-curly-spacing": [2, "always"], - "func-names": 1, - "valid-jsdoc": [2, { - "requireReturn": false, - "prefer": { - "return": "returns" - } - }] - } + "extend": [ + "eslint-config-andyet/es5" + ] } diff --git a/package.json b/package.json index 6f10a40..c2a868c 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "browserify": "^13.0.0", "code": "^2.0.1", "eslint": "^1.1.0", + "eslint-config-andyet": "^1.0.0", "eslint-plugin-hapi": "^4.0.0", "function-bind": "^1.0.2", "git-validate": "^2.0.3", From 10203084fa819ba8863e8f5d197d6099069e8dcc Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Wed, 13 Jan 2016 15:12:09 -0800 Subject: [PATCH 4/5] fix(tests) Move browser test file It was too easy to confuse with the exported browser sub library --- browser/index.js => browser_test.js | 2 +- package.json | 1 - test/index.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) rename browser/index.js => browser_test.js (90%) diff --git a/browser/index.js b/browser_test.js similarity index 90% rename from browser/index.js rename to browser_test.js index 73000f1..c62d951 100644 --- a/browser/index.js +++ b/browser_test.js @@ -4,7 +4,7 @@ * at least some assurance that the code's working */ -var JsonRpcWs = require('../browser'); +var JsonRpcWs = require('./browser'); var browserClient = JsonRpcWs.createClient(); Function.prototype.bind = require('function-bind'); diff --git a/package.json b/package.json index c2a868c..71893b7 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "files": [ "index.js", "browser.js", - "browser/*", "lib/*" ], "devDependencies": { diff --git a/test/index.js b/test/index.js index 6a57204..fdad8b7 100644 --- a/test/index.js +++ b/test/index.js @@ -255,7 +255,7 @@ lab.experiment('json-rpc ws', function () { process.env.PATH = process.env.PATH + ':./node_modules/.bin'; var b = Browserify(); - b.add('./browser/index.js'); + b.add('./browser_test.js'); b.bundle(function (err, buf) { Code.expect(err).to.not.exist(); From 9e272ab93a1b16a16054fce930097cc656dfe7bb Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Wed, 13 Jan 2016 15:21:59 -0800 Subject: [PATCH 5/5] fix(comments) update comments in browser test code Remove apparently stale mention of assert and explain file's purpose a litle better --- browser_test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/browser_test.js b/browser_test.js index c62d951..75a5f28 100644 --- a/browser_test.js +++ b/browser_test.js @@ -1,7 +1,8 @@ /** * Browser test code - * We use assert here just to throw on errors so we have - * at least some assurance that the code's working + * This code is browserified and sent to phantomjs + * as part of the test suite, it is not part of the + * library itself */ var JsonRpcWs = require('./browser');