mongodb-memory-server 2.1.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -2
- package/lib/MongoMemoryReplSet.d.ts +57 -0
- package/lib/MongoMemoryReplSet.js +307 -0
- package/lib/MongoMemoryReplSet.js.flow +252 -0
- package/lib/MongoMemoryServer.d.ts +47 -0
- package/lib/MongoMemoryServer.js +76 -78
- package/lib/MongoMemoryServer.js.flow +22 -26
- package/lib/__tests__/multipleDB-test.js +68 -0
- package/lib/__tests__/replset-test.js +87 -0
- package/lib/__tests__/singleDB-test.js +43 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +32 -14
- package/lib/index.js.flow +2 -1
- package/lib/types.d.ts +49 -0
- package/lib/types.js +1 -0
- package/lib/types.js.flow +60 -0
- package/lib/util/MongoBinary.d.ts +23 -0
- package/lib/util/MongoBinary.js +46 -42
- package/lib/util/MongoBinary.js.flow +13 -6
- package/lib/util/MongoBinaryDownload.d.ts +33 -0
- package/lib/util/MongoBinaryDownload.js +84 -73
- package/lib/util/MongoBinaryDownload.js.flow +5 -11
- package/lib/util/MongoBinaryDownloadUrl.d.ts +35 -0
- package/lib/util/MongoBinaryDownloadUrl.js +68 -31
- package/lib/util/MongoBinaryDownloadUrl.js.flow +12 -17
- package/lib/util/MongoInstance.d.ts +49 -0
- package/lib/util/MongoInstance.js +50 -32
- package/lib/util/MongoInstance.js.flow +12 -17
- package/lib/util/__tests__/MongoBinary-test.js +52 -0
- package/lib/util/__tests__/MongoBinaryDownload-test.js +42 -0
- package/lib/util/__tests__/MongoBinaryDownloadUrl-test.js +179 -0
- package/lib/util/__tests__/MongoInstance-test.js +133 -0
- package/lib/util/db_util.d.ts +20 -0
- package/lib/util/db_util.js +56 -0
- package/lib/util/db_util.js.flow +29 -0
- package/lib/util/mongo_killer.d.ts +0 -0
- package/lib/util/mongo_killer.js +5 -5
- package/package.json +36 -23
|
@@ -1,57 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _os = require(
|
|
8
|
+
var _os = _interopRequireDefault(require("os"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _url = _interopRequireDefault(require("url"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
15
|
|
|
15
|
-
var
|
|
16
|
+
var _md5File = _interopRequireDefault(require("md5-file"));
|
|
16
17
|
|
|
17
|
-
var
|
|
18
|
+
var _https = _interopRequireDefault(require("https"));
|
|
18
19
|
|
|
19
|
-
var
|
|
20
|
+
var _httpsProxyAgent = _interopRequireDefault(require("https-proxy-agent"));
|
|
20
21
|
|
|
21
|
-
var
|
|
22
|
+
var _decompress = _interopRequireDefault(require("decompress"));
|
|
22
23
|
|
|
23
|
-
var
|
|
24
|
+
var _MongoBinaryDownloadUrl = _interopRequireDefault(require("./MongoBinaryDownloadUrl"));
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var _https = require('https');
|
|
28
|
-
|
|
29
|
-
var _https2 = _interopRequireDefault(_https);
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
27
|
|
|
31
|
-
var
|
|
28
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
32
29
|
|
|
33
|
-
var
|
|
30
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
class MongoBinaryDownload {
|
|
35
|
+
constructor({
|
|
36
|
+
platform,
|
|
37
|
+
arch,
|
|
38
|
+
downloadDir,
|
|
39
|
+
version,
|
|
40
|
+
debug
|
|
41
|
+
}) {
|
|
42
|
+
_defineProperty(this, "debug", void 0);
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
_defineProperty(this, "dlProgress", void 0);
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
_defineProperty(this, "downloadDir", void 0);
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
_defineProperty(this, "arch", void 0);
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
/* eslint-disable class-methods-use-this */
|
|
50
|
+
_defineProperty(this, "version", void 0);
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
_defineProperty(this, "platform", void 0);
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
this.arch = arch || _os2.default.arch();
|
|
54
|
+
this.platform = platform || _os.default.platform();
|
|
55
|
+
this.arch = arch || _os.default.arch();
|
|
53
56
|
this.version = version || 'latest';
|
|
54
|
-
this.downloadDir =
|
|
57
|
+
this.downloadDir = _path.default.resolve(downloadDir || 'mongodb-download');
|
|
55
58
|
this.dlProgress = {
|
|
56
59
|
current: 0,
|
|
57
60
|
length: 0,
|
|
@@ -75,14 +78,17 @@ class MongoBinaryDownload {
|
|
|
75
78
|
|
|
76
79
|
return _asyncToGenerator(function* () {
|
|
77
80
|
const binaryName = _this.platform === 'win32' ? 'mongod.exe' : 'mongod';
|
|
78
|
-
|
|
81
|
+
|
|
82
|
+
const mongodPath = _path.default.resolve(_this.downloadDir, _this.version, binaryName);
|
|
83
|
+
|
|
79
84
|
if (_this.locationExists(mongodPath)) {
|
|
80
85
|
return mongodPath;
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
const mongoDBArchive = yield _this.startDownload();
|
|
84
89
|
yield _this.extract(mongoDBArchive);
|
|
85
|
-
|
|
90
|
+
|
|
91
|
+
_fs.default.unlinkSync(mongoDBArchive);
|
|
86
92
|
|
|
87
93
|
if (_this.locationExists(mongodPath)) {
|
|
88
94
|
return mongodPath;
|
|
@@ -96,32 +102,33 @@ class MongoBinaryDownload {
|
|
|
96
102
|
var _this2 = this;
|
|
97
103
|
|
|
98
104
|
return _asyncToGenerator(function* () {
|
|
99
|
-
const mbdUrl = new
|
|
105
|
+
const mbdUrl = new _MongoBinaryDownloadUrl.default({
|
|
100
106
|
platform: _this2.platform,
|
|
101
107
|
arch: _this2.arch,
|
|
102
108
|
version: _this2.version
|
|
103
109
|
});
|
|
104
110
|
|
|
105
|
-
if (!
|
|
106
|
-
|
|
111
|
+
if (!_fs.default.existsSync(_this2.downloadDir)) {
|
|
112
|
+
_fs.default.mkdirSync(_this2.downloadDir);
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
const downloadUrl = yield mbdUrl.getDownloadUrl();
|
|
110
116
|
const mongoDBArchive = yield _this2.download(downloadUrl);
|
|
111
|
-
|
|
112
117
|
const mongoDBArchiveMd5 = yield _this2.download(`${downloadUrl}.md5`);
|
|
113
118
|
yield _this2.checkMd5(mongoDBArchiveMd5, mongoDBArchive);
|
|
114
|
-
|
|
115
119
|
return mongoDBArchive;
|
|
116
120
|
})();
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
checkMd5(mongoDBArchiveMd5, mongoDBArchive) {
|
|
120
124
|
return _asyncToGenerator(function* () {
|
|
121
|
-
const signatureContent =
|
|
125
|
+
const signatureContent = _fs.default.readFileSync(mongoDBArchiveMd5).toString('UTF-8');
|
|
126
|
+
|
|
122
127
|
const m = signatureContent.match(/(.*?)\s/);
|
|
123
128
|
const md5Remote = m ? m[1] : null;
|
|
124
|
-
|
|
129
|
+
|
|
130
|
+
const md5Local = _md5File.default.sync(mongoDBArchive);
|
|
131
|
+
|
|
125
132
|
if (md5Remote !== md5Local) {
|
|
126
133
|
throw new Error('MongoBinaryDownload: md5 check is failed');
|
|
127
134
|
}
|
|
@@ -134,24 +141,27 @@ class MongoBinaryDownload {
|
|
|
134
141
|
return _asyncToGenerator(function* () {
|
|
135
142
|
const proxy = process.env['yarn_https-proxy'] || process.env.yarn_proxy || process.env['npm_config_https-proxy'] || process.env.npm_config_proxy || process.env.https_proxy || process.env.http_proxy;
|
|
136
143
|
|
|
137
|
-
const urlObject =
|
|
144
|
+
const urlObject = _url.default.parse(downloadUrl);
|
|
138
145
|
|
|
139
146
|
const downloadOptions = {
|
|
140
147
|
hostname: urlObject.hostname,
|
|
141
148
|
port: urlObject.port || 443,
|
|
142
149
|
path: urlObject.path,
|
|
143
150
|
method: 'GET',
|
|
144
|
-
agent: proxy ? new
|
|
151
|
+
agent: proxy ? new _httpsProxyAgent.default(proxy) : undefined
|
|
145
152
|
};
|
|
146
|
-
|
|
147
153
|
const filename = (urlObject.pathname || '').split('/').pop();
|
|
154
|
+
|
|
148
155
|
if (!filename) {
|
|
149
156
|
throw new Error(`MongoBinaryDownload: missing filename for url ${downloadUrl}`);
|
|
150
157
|
}
|
|
151
158
|
|
|
152
|
-
const downloadLocation =
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
const downloadLocation = _path.default.resolve(_this3.downloadDir, filename);
|
|
160
|
+
|
|
161
|
+
const tempDownloadLocation = _path.default.resolve(_this3.downloadDir, `${filename}.downloading`);
|
|
162
|
+
|
|
163
|
+
_this3.debug(`Downloading${proxy ? ` via proxy ${proxy}` : ''}:`, downloadUrl);
|
|
164
|
+
|
|
155
165
|
const downloadedFile = yield _this3.httpDownload(downloadOptions, downloadLocation, tempDownloadLocation);
|
|
156
166
|
return downloadedFile;
|
|
157
167
|
})();
|
|
@@ -162,39 +172,40 @@ class MongoBinaryDownload {
|
|
|
162
172
|
|
|
163
173
|
return _asyncToGenerator(function* () {
|
|
164
174
|
const binaryName = _this4.platform === 'win32' ? 'mongod.exe' : 'mongod';
|
|
165
|
-
|
|
175
|
+
|
|
176
|
+
const extractDir = _path.default.resolve(_this4.downloadDir, _this4.version);
|
|
177
|
+
|
|
166
178
|
_this4.debug(`extract(): ${extractDir}`);
|
|
167
179
|
|
|
168
|
-
if (!
|
|
169
|
-
|
|
180
|
+
if (!_fs.default.existsSync(extractDir)) {
|
|
181
|
+
_fs.default.mkdirSync(extractDir);
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
let filter;
|
|
185
|
+
|
|
173
186
|
if (_this4.platform === 'win32') {
|
|
174
|
-
filter =
|
|
175
|
-
return
|
|
176
|
-
);
|
|
187
|
+
filter = file => {
|
|
188
|
+
return /bin\/mongod.exe$/.test(file.path) || /.dll$/.test(file.path);
|
|
177
189
|
};
|
|
178
190
|
} else {
|
|
179
|
-
filter =
|
|
180
|
-
return (/bin\/mongod$/.test(file.path)
|
|
181
|
-
);
|
|
182
|
-
};
|
|
191
|
+
filter = file => /bin\/mongod$/.test(file.path);
|
|
183
192
|
}
|
|
184
193
|
|
|
185
|
-
yield (0,
|
|
194
|
+
yield (0, _decompress.default)(mongoDBArchive, extractDir, {
|
|
186
195
|
// extract only `bin/mongod` file
|
|
187
196
|
filter,
|
|
188
197
|
// extract to root folder
|
|
189
|
-
map:
|
|
190
|
-
file.path =
|
|
198
|
+
map: file => {
|
|
199
|
+
file.path = _path.default.basename(file.path); // eslint-disable-line
|
|
200
|
+
|
|
191
201
|
return file;
|
|
192
202
|
}
|
|
193
203
|
});
|
|
194
204
|
|
|
195
|
-
if (!_this4.locationExists(
|
|
205
|
+
if (!_this4.locationExists(_path.default.resolve(_this4.downloadDir, _this4.version, binaryName))) {
|
|
196
206
|
throw new Error(`MongoBinaryDownload: missing mongod binary in ${mongoDBArchive}`);
|
|
197
207
|
}
|
|
208
|
+
|
|
198
209
|
return extractDir;
|
|
199
210
|
})();
|
|
200
211
|
}
|
|
@@ -203,29 +214,29 @@ class MongoBinaryDownload {
|
|
|
203
214
|
var _this5 = this;
|
|
204
215
|
|
|
205
216
|
return _asyncToGenerator(function* () {
|
|
206
|
-
return new Promise(
|
|
207
|
-
const fileStream =
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
const fileStream = _fs.default.createWriteStream(tempDownloadLocation);
|
|
208
219
|
|
|
209
|
-
const req =
|
|
220
|
+
const req = _https.default.get(httpOptions, response => {
|
|
210
221
|
_this5.dlProgress.current = 0;
|
|
211
222
|
_this5.dlProgress.length = parseInt(response.headers['content-length'], 10);
|
|
212
223
|
_this5.dlProgress.totalMb = Math.round(_this5.dlProgress.length / 1048576 * 10) / 10;
|
|
213
|
-
|
|
214
224
|
response.pipe(fileStream);
|
|
215
|
-
|
|
216
|
-
fileStream.on('finish', function () {
|
|
225
|
+
fileStream.on('finish', () => {
|
|
217
226
|
fileStream.close();
|
|
218
|
-
|
|
227
|
+
|
|
228
|
+
_fs.default.renameSync(tempDownloadLocation, downloadLocation);
|
|
229
|
+
|
|
219
230
|
_this5.debug(`renamed ${tempDownloadLocation} to ${downloadLocation}`);
|
|
231
|
+
|
|
220
232
|
resolve(downloadLocation);
|
|
221
233
|
});
|
|
222
|
-
|
|
223
|
-
response.on('data', function (chunk) {
|
|
234
|
+
response.on('data', chunk => {
|
|
224
235
|
_this5.printDownloadProgress(chunk);
|
|
225
236
|
});
|
|
226
|
-
|
|
227
|
-
req.on('error', function (e) {
|
|
237
|
+
req.on('error', e => {
|
|
228
238
|
_this5.debug('request error:', e);
|
|
239
|
+
|
|
229
240
|
reject(e);
|
|
230
241
|
});
|
|
231
242
|
});
|
|
@@ -235,26 +246,26 @@ class MongoBinaryDownload {
|
|
|
235
246
|
|
|
236
247
|
printDownloadProgress(chunk) {
|
|
237
248
|
this.dlProgress.current += chunk.length;
|
|
238
|
-
|
|
239
249
|
const now = Date.now();
|
|
240
250
|
if (now - this.dlProgress.lastPrintedAt < 2000) return;
|
|
241
251
|
this.dlProgress.lastPrintedAt = now;
|
|
242
|
-
|
|
243
252
|
const percentComplete = Math.round(100.0 * this.dlProgress.current / this.dlProgress.length * 10) / 10;
|
|
244
253
|
const mbComplete = Math.round(this.dlProgress.current / 1048576 * 10) / 10;
|
|
245
|
-
|
|
246
254
|
const crReturn = this.platform === 'win32' ? '\x1b[0G' : '\r';
|
|
247
255
|
process.stdout.write(`Downloading MongoDB ${this.version}: ${percentComplete} % (${mbComplete}mb ` + `/ ${this.dlProgress.totalMb}mb)${crReturn}`);
|
|
248
256
|
}
|
|
249
257
|
|
|
250
258
|
locationExists(location) {
|
|
251
259
|
try {
|
|
252
|
-
|
|
260
|
+
_fs.default.lstatSync(location);
|
|
261
|
+
|
|
253
262
|
return true;
|
|
254
263
|
} catch (e) {
|
|
255
264
|
if (e.code !== 'ENOENT') throw e;
|
|
256
265
|
return false;
|
|
257
266
|
}
|
|
258
267
|
}
|
|
268
|
+
|
|
259
269
|
}
|
|
270
|
+
|
|
260
271
|
exports.default = MongoBinaryDownload;
|
|
@@ -10,25 +10,19 @@ import https from 'https';
|
|
|
10
10
|
import HttpsProxyAgent from 'https-proxy-agent';
|
|
11
11
|
import decompress from 'decompress';
|
|
12
12
|
import MongoBinaryDownloadUrl from './MongoBinaryDownloadUrl';
|
|
13
|
+
import type { DebugFn, DebugPropT, DownloadProgressT } from '../types';
|
|
13
14
|
|
|
14
15
|
export type MongoBinaryDownloadOpts = {
|
|
15
16
|
version: string,
|
|
16
17
|
downloadDir: string,
|
|
17
18
|
platform: string,
|
|
18
19
|
arch: string,
|
|
19
|
-
debug?:
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type dlProgress = {
|
|
23
|
-
current: number,
|
|
24
|
-
length: number,
|
|
25
|
-
totalMb: number,
|
|
26
|
-
lastPrintedAt: number,
|
|
20
|
+
debug?: DebugPropT,
|
|
27
21
|
};
|
|
28
22
|
|
|
29
23
|
export default class MongoBinaryDownload {
|
|
30
|
-
debug:
|
|
31
|
-
dlProgress:
|
|
24
|
+
debug: DebugFn;
|
|
25
|
+
dlProgress: DownloadProgressT;
|
|
32
26
|
|
|
33
27
|
downloadDir: string;
|
|
34
28
|
arch: string;
|
|
@@ -132,7 +126,7 @@ export default class MongoBinaryDownload {
|
|
|
132
126
|
|
|
133
127
|
const downloadLocation = path.resolve(this.downloadDir, filename);
|
|
134
128
|
const tempDownloadLocation = path.resolve(this.downloadDir, `${filename}.downloading`);
|
|
135
|
-
|
|
129
|
+
this.debug(`Downloading${proxy ? ` via proxy ${proxy}` : ''}:`, downloadUrl);
|
|
136
130
|
const downloadedFile = await this.httpDownload(
|
|
137
131
|
downloadOptions,
|
|
138
132
|
downloadLocation,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types='getos' />
|
|
2
|
+
|
|
3
|
+
import * as getos from 'getos';
|
|
4
|
+
|
|
5
|
+
export interface MongoBinaryDownloadUrlOpts {
|
|
6
|
+
version: string;
|
|
7
|
+
platform: string;
|
|
8
|
+
arch: string;
|
|
9
|
+
os?: getos.Os | null; // getos() result
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class MongoBinaryDownloadUrl {
|
|
13
|
+
platform: string;
|
|
14
|
+
arch: string;
|
|
15
|
+
version: string;
|
|
16
|
+
os: getos.Os | null | undefined;
|
|
17
|
+
|
|
18
|
+
constructor(opts: MongoBinaryDownloadUrlOpts);
|
|
19
|
+
getDownloadUrl(): Promise<string>;
|
|
20
|
+
getArchiveName(): Promise<string>;
|
|
21
|
+
getArchiveNameWin(): Promise<string>;
|
|
22
|
+
getArchiveNameOsx(): Promise<string>;
|
|
23
|
+
getArchiveNameLinux(): Promise<string>;
|
|
24
|
+
getos(): Promise<getos.Os>;
|
|
25
|
+
getLinuxOSVersionString(os: getos.Os): string;
|
|
26
|
+
getDebianVersionString(os: getos.Os): string;
|
|
27
|
+
getFedoraVersionString(os: getos.Os): string;
|
|
28
|
+
getRhelVersionString(os: getos.Os): string;
|
|
29
|
+
getElementaryOSVersionString(os: getos.Os): string;
|
|
30
|
+
getLegacyVersionString(os: getos.Os): string;
|
|
31
|
+
getSuseVersionString(os: getos.Os): string;
|
|
32
|
+
getUbuntuVersionString(os: getos.Os): string;
|
|
33
|
+
translatePlatform(platform: string): string;
|
|
34
|
+
translateArch(arch: string, mongoPlatform: string): string;
|
|
35
|
+
}
|
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
+
var _getos = _interopRequireDefault(require("getos"));
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
12
13
|
|
|
13
|
-
function
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
15
|
+
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
17
|
+
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
|
|
22
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
23
|
|
|
15
|
-
function
|
|
16
|
-
/* eslint-disable class-methods-use-this */
|
|
24
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
25
|
|
|
18
26
|
class MongoBinaryDownloadUrl {
|
|
27
|
+
constructor({
|
|
28
|
+
platform,
|
|
29
|
+
arch,
|
|
30
|
+
version,
|
|
31
|
+
os
|
|
32
|
+
}) {
|
|
33
|
+
_defineProperty(this, "platform", void 0);
|
|
34
|
+
|
|
35
|
+
_defineProperty(this, "arch", void 0);
|
|
36
|
+
|
|
37
|
+
_defineProperty(this, "version", void 0);
|
|
38
|
+
|
|
39
|
+
_defineProperty(this, "os", void 0);
|
|
19
40
|
|
|
20
|
-
constructor({ platform, arch, version, os }) {
|
|
21
41
|
this.platform = this.translatePlatform(platform);
|
|
22
42
|
this.arch = this.translateArch(arch, this.platform);
|
|
23
43
|
this.version = version;
|
|
@@ -40,16 +60,18 @@ class MongoBinaryDownloadUrl {
|
|
|
40
60
|
switch (_this2.platform) {
|
|
41
61
|
case 'osx':
|
|
42
62
|
return _this2.getArchiveNameOsx();
|
|
63
|
+
|
|
43
64
|
case 'win32':
|
|
44
65
|
return _this2.getArchiveNameWin();
|
|
66
|
+
|
|
45
67
|
case 'linux':
|
|
46
68
|
default:
|
|
47
69
|
return _this2.getArchiveNameLinux();
|
|
48
70
|
}
|
|
49
71
|
})();
|
|
50
|
-
}
|
|
72
|
+
} // https://www.mongodb.org/dl/win32
|
|
73
|
+
|
|
51
74
|
|
|
52
|
-
// https://www.mongodb.org/dl/win32
|
|
53
75
|
getArchiveNameWin() {
|
|
54
76
|
var _this3 = this;
|
|
55
77
|
|
|
@@ -60,50 +82,52 @@ class MongoBinaryDownloadUrl {
|
|
|
60
82
|
name += `-${_this3.version}.zip`;
|
|
61
83
|
return name;
|
|
62
84
|
})();
|
|
63
|
-
}
|
|
85
|
+
} // https://www.mongodb.org/dl/osx
|
|
86
|
+
|
|
64
87
|
|
|
65
|
-
// https://www.mongodb.org/dl/osx
|
|
66
88
|
getArchiveNameOsx() {
|
|
67
89
|
var _this4 = this;
|
|
68
90
|
|
|
69
91
|
return _asyncToGenerator(function* () {
|
|
70
92
|
let name = `mongodb-osx`;
|
|
93
|
+
|
|
71
94
|
if (!(_this4.version.indexOf('3.0') === 0 || _this4.version.indexOf('2.') === 0 || _this4.version.indexOf('1.') === 0)) {
|
|
72
95
|
name += '-ssl';
|
|
73
96
|
}
|
|
97
|
+
|
|
74
98
|
name += `-${_this4.arch}`;
|
|
75
99
|
name += `-${_this4.version}.tgz`;
|
|
76
100
|
return name;
|
|
77
101
|
})();
|
|
78
|
-
}
|
|
102
|
+
} // https://www.mongodb.org/dl/linux
|
|
103
|
+
|
|
79
104
|
|
|
80
|
-
// https://www.mongodb.org/dl/linux
|
|
81
105
|
getArchiveNameLinux() {
|
|
82
106
|
var _this5 = this;
|
|
83
107
|
|
|
84
108
|
return _asyncToGenerator(function* () {
|
|
85
109
|
let name = `mongodb-linux`;
|
|
86
110
|
name += `-${_this5.arch}`;
|
|
87
|
-
|
|
88
111
|
let osString;
|
|
112
|
+
|
|
89
113
|
if (_this5.arch !== 'i686') {
|
|
90
114
|
if (!_this5.os) _this5.os = yield _this5.getos();
|
|
91
115
|
osString = _this5.getLinuxOSVersionString(_this5.os);
|
|
92
116
|
}
|
|
117
|
+
|
|
93
118
|
if (osString) {
|
|
94
119
|
name += `-${osString}`;
|
|
95
120
|
}
|
|
96
121
|
|
|
97
122
|
name += `-${_this5.version}.tgz`;
|
|
98
|
-
|
|
99
123
|
return name;
|
|
100
124
|
})();
|
|
101
125
|
}
|
|
102
126
|
|
|
103
127
|
getos() {
|
|
104
128
|
return _asyncToGenerator(function* () {
|
|
105
|
-
return new Promise(
|
|
106
|
-
(0,
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
(0, _getos.default)((e, os) => {
|
|
107
131
|
if (e) reject(e);
|
|
108
132
|
resolve(os);
|
|
109
133
|
});
|
|
@@ -127,6 +151,7 @@ class MongoBinaryDownloadUrl {
|
|
|
127
151
|
} else if (/mint/i.test(os.dist)) {
|
|
128
152
|
return this.getMintVersionString(os);
|
|
129
153
|
}
|
|
154
|
+
|
|
130
155
|
console.warn(`Unknown linux distro ${os.dist}, falling back to legacy MongoDB build`);
|
|
131
156
|
return this.getLegacyVersionString(os);
|
|
132
157
|
}
|
|
@@ -134,6 +159,7 @@ class MongoBinaryDownloadUrl {
|
|
|
134
159
|
getDebianVersionString(os) {
|
|
135
160
|
let name = 'debian';
|
|
136
161
|
const release = parseFloat(os.release);
|
|
162
|
+
|
|
137
163
|
if (release >= 9) {
|
|
138
164
|
name += '92';
|
|
139
165
|
} else if (release >= 8.1) {
|
|
@@ -141,12 +167,14 @@ class MongoBinaryDownloadUrl {
|
|
|
141
167
|
} else if (release >= 7.1) {
|
|
142
168
|
name += '71';
|
|
143
169
|
}
|
|
170
|
+
|
|
144
171
|
return name;
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
getFedoraVersionString(os) {
|
|
148
175
|
let name = 'rhel';
|
|
149
176
|
const fedoraVer = parseInt(os.release, 10);
|
|
177
|
+
|
|
150
178
|
if (fedoraVer > 18) {
|
|
151
179
|
name += '70';
|
|
152
180
|
} else if (fedoraVer < 19 && fedoraVer >= 12) {
|
|
@@ -154,6 +182,7 @@ class MongoBinaryDownloadUrl {
|
|
|
154
182
|
} else if (fedoraVer < 12 && fedoraVer >= 6) {
|
|
155
183
|
name += '55';
|
|
156
184
|
}
|
|
185
|
+
|
|
157
186
|
return name;
|
|
158
187
|
}
|
|
159
188
|
|
|
@@ -170,43 +199,42 @@ class MongoBinaryDownloadUrl {
|
|
|
170
199
|
name += '55';
|
|
171
200
|
}
|
|
172
201
|
}
|
|
202
|
+
|
|
173
203
|
return name;
|
|
174
|
-
}
|
|
204
|
+
} // eslint-disable-next-line no-unused-vars
|
|
205
|
+
|
|
175
206
|
|
|
176
|
-
// eslint-disable-next-line no-unused-vars
|
|
177
207
|
getElementaryOSVersionString(os) {
|
|
178
208
|
return 'ubuntu1404';
|
|
179
|
-
}
|
|
209
|
+
} // eslint-disable-next-line no-unused-vars
|
|
210
|
+
|
|
180
211
|
|
|
181
|
-
// eslint-disable-next-line no-unused-vars
|
|
182
212
|
getMintVersionString(os) {
|
|
183
213
|
// unfortunately getos doesn't return version for Mint
|
|
184
214
|
return 'ubuntu1404';
|
|
185
|
-
}
|
|
215
|
+
} // eslint-disable-next-line no-unused-vars
|
|
216
|
+
|
|
186
217
|
|
|
187
|
-
// eslint-disable-next-line no-unused-vars
|
|
188
218
|
getLegacyVersionString(os) {
|
|
189
219
|
return '';
|
|
190
220
|
}
|
|
191
221
|
|
|
192
222
|
getSuseVersionString(os) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const release = _ref2[0];
|
|
197
|
-
|
|
223
|
+
const _ref = os.release.match(/(^11|^12)/) || [null],
|
|
224
|
+
_ref2 = _slicedToArray(_ref, 1),
|
|
225
|
+
release = _ref2[0];
|
|
198
226
|
|
|
199
227
|
if (release) {
|
|
200
228
|
return `suse${release}`;
|
|
201
229
|
}
|
|
230
|
+
|
|
202
231
|
return '';
|
|
203
232
|
}
|
|
204
233
|
|
|
205
234
|
getUbuntuVersionString(os) {
|
|
206
235
|
let name = 'ubuntu';
|
|
207
236
|
const ubuntuVer = os.release ? os.release.split('.') : [];
|
|
208
|
-
const majorVer = parseInt(ubuntuVer[0], 10);
|
|
209
|
-
// const minorVer: string = ubuntuVer[1];
|
|
237
|
+
const majorVer = parseInt(ubuntuVer[0], 10); // const minorVer: string = ubuntuVer[1];
|
|
210
238
|
|
|
211
239
|
if (os.release === '12.04') {
|
|
212
240
|
name += '1204';
|
|
@@ -223,6 +251,7 @@ class MongoBinaryDownloadUrl {
|
|
|
223
251
|
} else {
|
|
224
252
|
name += '1404';
|
|
225
253
|
}
|
|
254
|
+
|
|
226
255
|
return name;
|
|
227
256
|
}
|
|
228
257
|
|
|
@@ -230,14 +259,19 @@ class MongoBinaryDownloadUrl {
|
|
|
230
259
|
switch (platform) {
|
|
231
260
|
case 'darwin':
|
|
232
261
|
return 'osx';
|
|
262
|
+
|
|
233
263
|
case 'win32':
|
|
234
264
|
return 'win32';
|
|
265
|
+
|
|
235
266
|
case 'linux':
|
|
236
267
|
return 'linux';
|
|
268
|
+
|
|
237
269
|
case 'elementary OS':
|
|
238
270
|
return 'linux';
|
|
271
|
+
|
|
239
272
|
case 'sunos':
|
|
240
273
|
return 'sunos5';
|
|
274
|
+
|
|
241
275
|
default:
|
|
242
276
|
throw new Error(`unsupported OS ${platform}`);
|
|
243
277
|
}
|
|
@@ -250,6 +284,7 @@ class MongoBinaryDownloadUrl {
|
|
|
250
284
|
} else if (mongoPlatform === 'win32') {
|
|
251
285
|
return 'i386';
|
|
252
286
|
}
|
|
287
|
+
|
|
253
288
|
throw new Error('unsupported architecture');
|
|
254
289
|
} else if (arch === 'x64') {
|
|
255
290
|
return 'x86_64';
|
|
@@ -257,5 +292,7 @@ class MongoBinaryDownloadUrl {
|
|
|
257
292
|
throw new Error('unsupported architecture, ia32 and x64 are the only valid options');
|
|
258
293
|
}
|
|
259
294
|
}
|
|
295
|
+
|
|
260
296
|
}
|
|
297
|
+
|
|
261
298
|
exports.default = MongoBinaryDownloadUrl;
|