mongodb-memory-server-core
Advanced tools
Comparing version 6.4.0 to 6.4.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [6.4.1](https://github.com/nodkz/mongodb-memory-server/compare/v6.4.0...v6.4.1) (2020-03-19) | ||
### Bug Fixes | ||
* **MongoBinaryDownload:** Resolve in extractTarGz ([58faef2](https://github.com/nodkz/mongodb-memory-server/commit/58faef2)) | ||
# [6.4.0](https://github.com/nodkz/mongodb-memory-server/compare/v6.3.3...v6.4.0) (2020-03-19) | ||
@@ -8,0 +19,0 @@ |
@@ -63,5 +63,5 @@ "use strict"; | ||
it('should start multiple times', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var opts, replSetBefore, replSetAfter; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var opts, replSetBefore, _a, replSetAfter; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -82,6 +82,14 @@ opts = { | ||
case 1: | ||
_a.sent(); | ||
_b.sent(); | ||
// Write real port to config (because 27017 may be busy, we need to get real port) | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
_a = opts.instanceOpts[0]; | ||
return [4 /*yield*/, replSetBefore.servers[0].getPort()]; | ||
case 2: | ||
// Write real port to config (because 27017 may be busy, we need to get real port) | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
_a.port = _b.sent(); | ||
return [4 /*yield*/, replSetBefore.stop()]; | ||
case 2: | ||
_a.sent(); | ||
case 3: | ||
_b.sent(); | ||
/** | ||
@@ -93,3 +101,3 @@ * get-port has a portlocking-feature that keeps ports locked for | ||
return [4 /*yield*/, sleep(30000)]; | ||
case 3: | ||
case 4: | ||
/** | ||
@@ -100,10 +108,10 @@ * get-port has a portlocking-feature that keeps ports locked for | ||
*/ | ||
_a.sent(); | ||
_b.sent(); | ||
replSetAfter = new MongoMemoryReplSet_1.default(opts); | ||
return [4 /*yield*/, replSetAfter.waitUntilRunning()]; | ||
case 4: | ||
_a.sent(); | ||
case 5: | ||
_b.sent(); | ||
return [4 /*yield*/, replSetAfter.stop()]; | ||
case 5: | ||
_a.sent(); | ||
case 6: | ||
_b.sent(); | ||
return [2 /*return*/]; | ||
@@ -110,0 +118,0 @@ } |
@@ -57,2 +57,16 @@ import { DownloadProgressT } from '../types'; | ||
/** | ||
* Extract a .tar.gz archive | ||
* @param mongoDBArchive Archive location | ||
* @param extractDir Directory to extract to | ||
* @param filter Method to determine which files to extract | ||
*/ | ||
extractTarGz(mongoDBArchive: string, extractDir: string, filter: (file: string) => boolean): Promise<void>; | ||
/** | ||
* Extract a .zip archive | ||
* @param mongoDBArchive Archive location | ||
* @param extractDir Directory to extract to | ||
* @param filter Method to determine which files to extract | ||
*/ | ||
extractZip(mongoDBArchive: string, extractDir: string, filter: (file: string) => boolean): Promise<void>; | ||
/** | ||
* Downlaod given httpOptions to tempDownloadLocation, then move it to downloadLocation | ||
@@ -59,0 +73,0 @@ * @param httpOptions The httpOptions directly passed to https.get |
"use strict"; | ||
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { | ||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } | ||
return cooked; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -55,3 +59,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var https_1 = __importDefault(require("https")); | ||
var decompress_1 = __importDefault(require("decompress")); // 💩💩💩 this package does not work with Node@11+Jest+Babel | ||
var zlib_1 = require("zlib"); | ||
var tar_stream_1 = __importDefault(require("tar-stream")); | ||
var yauzl_1 = __importDefault(require("yauzl")); | ||
var MongoBinaryDownloadUrl_1 = __importDefault(require("./MongoBinaryDownloadUrl")); | ||
@@ -63,2 +69,3 @@ var MongoBinary_1 = require("./MongoBinary"); | ||
var debug_1 = __importDefault(require("debug")); | ||
var dedent_1 = __importDefault(require("dedent")); | ||
var log = debug_1.default('MongoMS:MongoBinaryDownload'); | ||
@@ -230,7 +237,7 @@ /** | ||
MongoBinaryDownload.prototype.extract = function (mongoDBArchive) { | ||
var _a; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var binaryName, extractDir, filter; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
@@ -245,24 +252,26 @@ binaryName = this.platform === 'win32' ? 'mongod.exe' : 'mongod'; | ||
filter = function (file) { | ||
return /bin\/mongod.exe$/.test(file.path) || /.dll$/.test(file.path); | ||
return /bin\/mongod.exe$/.test(file) || /.dll$/.test(file); | ||
}; | ||
} | ||
else { | ||
filter = function (file) { return /bin\/mongod$/.test(file.path); }; | ||
filter = function (file) { return /bin\/mongod$/.test(file); }; | ||
} | ||
return [4 /*yield*/, decompress_1.default(mongoDBArchive, extractDir, { | ||
// extract only `bin/mongod` file | ||
filter: filter, | ||
// extract to root folder | ||
map: function (file) { | ||
file.path = path_1.default.basename(file.path); | ||
return file; | ||
}, | ||
})]; | ||
if (!/(.tar.gz|.tgz)$/.test(path_1.default.extname(mongoDBArchive))) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.extractTarGz(mongoDBArchive, extractDir, filter)]; | ||
case 1: | ||
_b.sent(); | ||
return [4 /*yield*/, this.locationExists(path_1.default.resolve(this.downloadDir, this.version, binaryName))]; | ||
_c.sent(); | ||
return [3 /*break*/, 5]; | ||
case 2: | ||
if (!(_b.sent())) { | ||
throw new Error("MongoBinaryDownload: missing mongod binary in " + mongoDBArchive + " (downloaded from " + (_a = this | ||
._downloadingUrl, (_a !== null && _a !== void 0 ? _a : 'unkown')) + "). Broken archive from MongoDB Provider?"); | ||
if (!/.zip$/.test(path_1.default.extname(mongoDBArchive))) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, this.extractZip(mongoDBArchive, extractDir, filter)]; | ||
case 3: | ||
_c.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: throw new Error("MongoBinaryDownload: unsupported archive " + mongoDBArchive + " (downloaded from " + (_a = this | ||
._downloadingUrl, (_a !== null && _a !== void 0 ? _a : 'unkown')) + "). Broken archive from MongoDB Provider?"); | ||
case 5: return [4 /*yield*/, this.locationExists(path_1.default.resolve(this.downloadDir, this.version, binaryName))]; | ||
case 6: | ||
if (!(_c.sent())) { | ||
throw new Error("MongoBinaryDownload: missing mongod binary in " + mongoDBArchive + " (downloaded from " + (_b = this | ||
._downloadingUrl, (_b !== null && _b !== void 0 ? _b : 'unkown')) + "). Broken archive from MongoDB Provider?"); | ||
} | ||
@@ -275,2 +284,74 @@ return [2 /*return*/, extractDir]; | ||
/** | ||
* Extract a .tar.gz archive | ||
* @param mongoDBArchive Archive location | ||
* @param extractDir Directory to extract to | ||
* @param filter Method to determine which files to extract | ||
*/ | ||
MongoBinaryDownload.prototype.extractTarGz = function (mongoDBArchive, extractDir, filter) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var extract; | ||
return __generator(this, function (_a) { | ||
extract = tar_stream_1.default.extract(); | ||
extract.on('entry', function (header, stream, next) { | ||
if (filter(header.name)) { | ||
stream.pipe(fs_1.default.createWriteStream(path_1.default.resolve(extractDir, path_1.default.basename(header.name)), { | ||
mode: 509, | ||
})); | ||
} | ||
stream.on('end', function () { return next(); }); | ||
stream.resume(); | ||
}); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
fs_1.default.createReadStream(mongoDBArchive) | ||
.on('error', function (err) { | ||
reject('Unable to open tarball ' + mongoDBArchive + ': ' + err); | ||
}) | ||
.pipe(zlib_1.createUnzip()) | ||
.on('error', function (err) { | ||
reject('Error during unzip for ' + mongoDBArchive + ': ' + err); | ||
}) | ||
.pipe(extract) | ||
.on('error', function (err) { | ||
reject('Error during untar for ' + mongoDBArchive + ': ' + err); | ||
}) | ||
.on('finish', function (result) { | ||
resolve(result); | ||
}); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Extract a .zip archive | ||
* @param mongoDBArchive Archive location | ||
* @param extractDir Directory to extract to | ||
* @param filter Method to determine which files to extract | ||
*/ | ||
MongoBinaryDownload.prototype.extractZip = function (mongoDBArchive, extractDir, filter) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
yauzl_1.default.open(mongoDBArchive, { lazyEntries: true }, function (e, zipfile) { | ||
if (e || !zipfile) | ||
return reject(e); | ||
zipfile.readEntry(); | ||
zipfile.on('end', function () { return resolve(); }); | ||
zipfile.on('entry', function (entry) { | ||
if (!filter(entry.fileName)) | ||
return zipfile.readEntry(); | ||
zipfile.openReadStream(entry, function (e, r) { | ||
if (e || !r) | ||
return reject(e); | ||
r.on('end', function () { return zipfile.readEntry(); }); | ||
r.pipe(fs_1.default.createWriteStream(path_1.default.resolve(extractDir, path_1.default.basename(entry.fileName)), { | ||
mode: 509, | ||
})); | ||
}); | ||
}); | ||
}); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Downlaod given httpOptions to tempDownloadLocation, then move it to downloadLocation | ||
@@ -291,4 +372,3 @@ * @param httpOptions The httpOptions directly passed to https.get | ||
if (response.statusCode === 403) { | ||
reject(new Error("Status Code is 403 (MongoDB's 404)\n" + | ||
'This means that the requested version-platform combination dosnt exist')); | ||
reject(new Error(dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Status Code is 403 (MongoDB's 404)\n\n This means that the requested version-platform combination dosnt exist\n "], ["\n Status Code is 403 (MongoDB's 404)\\n\n This means that the requested version-platform combination dosnt exist\n "]))))); | ||
return; | ||
@@ -354,4 +434,3 @@ } | ||
var crReturn = this.platform === 'win32' ? '\x1b[0G' : '\r'; | ||
process.stdout.write("Downloading MongoDB " + this.version + ": " + percentComplete + " % (" + mbComplete + "mb " + | ||
("/ " + this.dlProgress.totalMb + "mb)" + crReturn)); | ||
process.stdout.write("Downloading MongoDB " + this.version + ": " + percentComplete + " % (" + mbComplete + "mb / " + this.dlProgress.totalMb + "mb)" + crReturn); | ||
}; | ||
@@ -387,2 +466,3 @@ /** | ||
exports.default = MongoBinaryDownload; | ||
var templateObject_1; | ||
//# sourceMappingURL=MongoBinaryDownload.js.map |
{ | ||
"name": "mongodb-memory-server-core", | ||
"version": "6.4.0", | ||
"version": "6.4.1", | ||
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.", | ||
@@ -36,2 +36,4 @@ "main": "lib/index", | ||
"@types/mongodb": "3.5.2", | ||
"@types/tar-stream": "^2.1.0", | ||
"@types/yauzl": "^2.9.1", | ||
"@typescript-eslint/eslint-plugin": "2.23.0", | ||
@@ -52,3 +54,2 @@ "@typescript-eslint/parser": "2.23.0", | ||
"@types/debug": "^4.1.5", | ||
"@types/decompress": "^4.2.3", | ||
"@types/dedent": "^0.7.0", | ||
@@ -66,3 +67,2 @@ "@types/find-cache-dir": "^3.2.0", | ||
"debug": "^4.1.1", | ||
"decompress": "^4.2.0", | ||
"dedent": "^0.7.0", | ||
@@ -76,4 +76,6 @@ "find-cache-dir": "3.3.1", | ||
"mkdirp": "^1.0.3", | ||
"tar-stream": "^2.1.1", | ||
"tmp": "^0.1.0", | ||
"uuid": "^7.0.2" | ||
"uuid": "^7.0.2", | ||
"yauzl": "^2.10.0" | ||
}, | ||
@@ -95,3 +97,3 @@ "optionalDependencies": { | ||
}, | ||
"gitHead": "9bd61b9ae98099f63d273a4db4dcbcf62ed4937e" | ||
"gitHead": "6653542a3867689dbbf8b168e1eea5b959b5ce09" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
352777
5081
15
+ Addedtar-stream@^2.1.1
+ Addedyauzl@^2.10.0
+ Addedbl@4.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedtar-stream@2.2.0(transitive)
- Removed@types/decompress@^4.2.3
- Removeddecompress@^4.2.0
- Removed@types/decompress@4.2.7(transitive)
- Removedbl@1.2.3(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removeddecompress@4.2.1(transitive)
- Removeddecompress-tar@4.1.1(transitive)
- Removeddecompress-tarbz2@4.1.1(transitive)
- Removeddecompress-targz@4.1.1(transitive)
- Removeddecompress-unzip@4.0.1(transitive)
- Removedfile-type@3.9.05.2.06.2.0(transitive)
- Removedget-stream@2.3.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedis-natural-number@4.0.1(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedmake-dir@1.3.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpify@2.3.03.0.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedseek-bzip@1.0.6(transitive)
- Removedstrip-dirs@2.1.0(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedthrough@2.3.8(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedunbzip2-stream@1.4.3(transitive)
- Removedxtend@4.0.2(transitive)