From 780060774c6d869968d3f9b04624efc06fb984b2 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Wed, 21 Feb 2018 07:01:36 +0000 Subject: [PATCH 01/11] fix: package.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/npm:lodash:20180130 Latest report for piranna/mongobox.js: https://snyk.io/test/github/piranna/mongobox.js --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bd2af4f..1b0fc7c 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,10 @@ }, "dependencies": { "temporary": "0.0.8", - "lodash": "~2.4.1", + "lodash": "~4.17.5", "freeport": "~1.0.2" }, - "devDependencies": { - }, + "devDependencies": {}, "main": "index", "engines": { "node": ">=0.8.0" From 6918e6f156254630c73f79fb1ba2e1f17c7ce94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 25 Feb 2019 18:04:34 +0100 Subject: [PATCH 02/11] Removed usage of `temporary` dependency --- lib/index.js | 3 +-- package-lock.json | 31 ------------------------------- package.json | 3 +-- 3 files changed, 2 insertions(+), 35 deletions(-) delete mode 100644 package-lock.json diff --git a/lib/index.js b/lib/index.js index f8b65ea..a196e89 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,4 @@ var fs = require('fs') - , temporary = require('temporary') , fmt = require('util').format , child_process = require('child_process') , net = require('net') @@ -49,7 +48,7 @@ MongoBox.prototype.start = function(callback) { fs.mkdirSync(this.options.databasePath); } } else { - this._temporary = new temporary.Dir(); + this._temporary = fs.mkdtempSync(); this.options.databasePath = this._temporary.path; } diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index fda5e21..0000000 --- a/package-lock.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "mongobox", - "version": "0.1.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "freeport": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/freeport/-/freeport-1.0.5.tgz", - "integrity": "sha1-JV6KuEFwwzuoXZkOghrl9KGpvF0=" - }, - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" - }, - "package": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/package/-/package-1.0.1.tgz", - "integrity": "sha1-0lofmeJQbcsn1nBLg9yooxLk7cw=" - }, - "temporary": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/temporary/-/temporary-0.0.8.tgz", - "integrity": "sha1-oYqYHSi6jKNgJ/s8MFOMPst0CsA=", - "requires": { - "package": ">= 1.0.0 < 1.2.0" - } - } - } -} diff --git a/package.json b/package.json index 95619cd..b8abd41 100644 --- a/package.json +++ b/package.json @@ -15,13 +15,12 @@ "url": "git://github.com/theorm/mongobox.js.git" }, "dependencies": { - "temporary": "0.0.8", "lodash": "4.17.11", "freeport": "1.0.5" }, "devDependencies": {}, "main": "lib", "engines": { - "node": ">=0.8.0" + "node": ">=5.10.0" } } From a1cb47e9afc6266dbe19bef91c499638c6a919dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 25 Feb 2019 18:05:17 +0100 Subject: [PATCH 03/11] Print used MongoDB binary in console --- lib/index.js | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index a196e89..406ec7f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -84,7 +84,7 @@ MongoBox.prototype.start = function(callback) { this.process = child_process.spawn(this.options.mongodBinary, args); - // console.log("%s %s", this.options.mongodBinary, args.join(" ")); + console.log("%s %s", this.options.mongodBinary, args.join(" ")); var self = this; this.process.on('close', function(code) { diff --git a/package.json b/package.json index b8abd41..55aa614 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "lodash": "4.17.11", "freeport": "1.0.5" }, - "devDependencies": {}, "main": "lib", "engines": { "node": ">=5.10.0" From c113e6bf11db99bd2f4328541dde8cefa57c51f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 25 Feb 2019 18:05:30 +0100 Subject: [PATCH 04/11] Allow newer dependencies versions --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 55aa614..06b4c5b 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "url": "git://github.com/theorm/mongobox.js.git" }, "dependencies": { - "lodash": "4.17.11", - "freeport": "1.0.5" + "lodash": "^4.17.11", + "freeport": "^1.0.5" }, "main": "lib", "engines": { From 4a1169a43992879ff2445b1b7064ae0e8b5ff56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 5 Apr 2019 21:48:09 +0200 Subject: [PATCH 05/11] Added missing `prefix` --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 406ec7f..969b53e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,7 +48,7 @@ MongoBox.prototype.start = function(callback) { fs.mkdirSync(this.options.databasePath); } } else { - this._temporary = fs.mkdtempSync(); + this._temporary = fs.mkdtempSync('mongobox-'); this.options.databasePath = this._temporary.path; } From 10847c35803f18dfb1b68e1a2025897b9db46b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 5 Apr 2019 22:11:58 +0200 Subject: [PATCH 06/11] Sorted requires --- lib/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 969b53e..260f4a8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,10 +1,13 @@ -var fs = require('fs') - , fmt = require('util').format - , child_process = require('child_process') - , net = require('net') - , freeport = require('freeport') - , _ = require('lodash') - , utils = require('./utils'); +const child_process = require('child_process') +const fs = require('fs') +const net = require('net') +const {format} = require('util') + +const freeport = require('freeport') +const _ = require('lodash') + +const utils = require('./utils'); + var MONGOD_BIN = 'mongod'; var DEFAULT_ARGS = [ @@ -28,7 +31,7 @@ var MongoBox = function(_options) { this.options.mongodBinary = options.mongodBinary || MONGOD_BIN; if (!this.options.mongodBinary) - throw new Error(fmt('Could not find %s in system PATH. Make sure you have mongod installed.', MONGOD_BIN)); + throw new Error(format('Could not find %s in system PATH. Make sure you have mongod installed.', MONGOD_BIN)); if (fs.existsSync(this.options.databasePath) && !fs.statSync(this.options.databasePath).isDirectory()) { From 290f129220bae61a3513df105fd5ddc4d05ab10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 5 Apr 2019 22:12:11 +0200 Subject: [PATCH 07/11] Sorted args --- lib/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 260f4a8..b12643a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,15 +11,15 @@ const utils = require('./utils'); var MONGOD_BIN = 'mongod'; var DEFAULT_ARGS = [ - // don't flood stdout, we're not reading it - "--quiet", + // journaling on by default in 2.0 and makes it to slow + // for tests, can causes failures in jenkins + "--nojournal", // disable unused. "--nounixsocket", + // don't flood stdout, we're not reading it + "--quiet", // use a smaller default file size "--smallfiles", - // journaling on by default in 2.0 and makes it to slow - // for tests, can causes failures in jenkins - "--nojournal", ] var START_CHECK_ATTEMPTS = 200; From c02d4fc1c877e7832bfae22cdb99c27b03ff9c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 5 Apr 2019 22:12:35 +0200 Subject: [PATCH 08/11] Create dir in `/tmp` folder --- lib/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index b12643a..f26c2ee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,8 @@ const child_process = require('child_process') const fs = require('fs') const net = require('net') +const {tmpdir} = require('os') +const {join} = require('path') const {format} = require('util') const freeport = require('freeport') @@ -51,8 +53,8 @@ MongoBox.prototype.start = function(callback) { fs.mkdirSync(this.options.databasePath); } } else { - this._temporary = fs.mkdtempSync('mongobox-'); - this.options.databasePath = this._temporary.path; + this._temporary = fs.mkdtempSync(join(tmpdir(), 'mongobox-')); + this.options.databasePath = this._temporary; } var self = this; From d4fdd6522c3e0ceee23bb7044f783563177e1fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 13 Apr 2019 05:43:05 +0200 Subject: [PATCH 09/11] Directly export MongoBox constructor --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f26c2ee..4e14406 100644 --- a/lib/index.js +++ b/lib/index.js @@ -146,4 +146,5 @@ MongoBox.prototype._waitTillStarted = function(callback) { tryConnect(); } -module.exports.MongoBox = MongoBox; +MongoBox.MongoBox = MongoBox; +module.exports = MongoBox; From 0455879e59643116f5ed8d0d66c57f3d42340ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 18 Jun 2019 11:21:41 +0200 Subject: [PATCH 10/11] Option disabled by default to print the `mongod` command --- lib/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f26c2ee..1a80434 100644 --- a/lib/index.js +++ b/lib/index.js @@ -89,7 +89,9 @@ MongoBox.prototype.start = function(callback) { this.process = child_process.spawn(this.options.mongodBinary, args); - console.log("%s %s", this.options.mongodBinary, args.join(" ")); + + if (this.options.printCommand) + console.log("%s %s", this.options.mongodBinary, args.join(" ")); var self = this; this.process.on('close', function(code) { From 422f846418252abee8a0b102de3d1b8c0dfeb0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 18 Jun 2019 11:23:04 +0200 Subject: [PATCH 11/11] Code clean-up --- lib/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1a80434..59ec60a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,7 @@ var DEFAULT_ARGS = [ var START_CHECK_ATTEMPTS = 200; -var MongoBox = function(_options) { +function MongoBox(_options) { var options = _options || {}; this.options = options; @@ -65,10 +65,10 @@ MongoBox.prototype.start = function(callback) { doStart.bind(self)(); }); } else { - doStart(); + doStart.call(this); } - var doStart = function() { + function doStart() { var args = _.clone(DEFAULT_ARGS); var op @@ -134,14 +134,13 @@ MongoBox.prototype._waitTillStarted = function(callback) { var self = this; function tryConnect() { - var socket = net.connect({port: self.options.port}, function() { - callback(); - }); - socket.on('error', function() { + net.connect({port: self.options.port}, callback) + .on('error', function() { attempts += 1; if (self.process && attempts < START_CHECK_ATTEMPTS) - setTimeout(tryConnect, 250); - else callback(new Error('MongoDB did not start.')) + return setTimeout(tryConnect, 250); + + callback(new Error('MongoDB did not start.')) }); }