mongodb-memory-server-core 8.15.0 → 9.0.0-beta.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/lib/MongoMemoryReplSet.d.ts +3 -19
- package/lib/MongoMemoryReplSet.d.ts.map +1 -1
- package/lib/MongoMemoryReplSet.js +283 -294
- package/lib/MongoMemoryReplSet.js.map +1 -1
- package/lib/MongoMemoryServer.d.ts +13 -26
- package/lib/MongoMemoryServer.d.ts.map +1 -1
- package/lib/MongoMemoryServer.js +323 -333
- package/lib/MongoMemoryServer.js.map +1 -1
- package/lib/util/DryMongoBinary.d.ts +1 -1
- package/lib/util/DryMongoBinary.d.ts.map +1 -1
- package/lib/util/DryMongoBinary.js +158 -172
- package/lib/util/DryMongoBinary.js.map +1 -1
- package/lib/util/MongoBinary.js +85 -85
- package/lib/util/MongoBinary.js.map +1 -1
- package/lib/util/MongoBinaryDownload.d.ts +2 -11
- package/lib/util/MongoBinaryDownload.d.ts.map +1 -1
- package/lib/util/MongoBinaryDownload.js +210 -262
- package/lib/util/MongoBinaryDownload.js.map +1 -1
- package/lib/util/MongoBinaryDownloadUrl.d.ts +3 -5
- package/lib/util/MongoBinaryDownloadUrl.d.ts.map +1 -1
- package/lib/util/MongoBinaryDownloadUrl.js +67 -94
- package/lib/util/MongoBinaryDownloadUrl.js.map +1 -1
- package/lib/util/MongoInstance.d.ts +3 -1
- package/lib/util/MongoInstance.d.ts.map +1 -1
- package/lib/util/MongoInstance.js +125 -126
- package/lib/util/MongoInstance.js.map +1 -1
- package/lib/util/errors.d.ts +10 -9
- package/lib/util/errors.d.ts.map +1 -1
- package/lib/util/errors.js +16 -27
- package/lib/util/errors.js.map +1 -1
- package/lib/util/getos/index.d.ts +1 -1
- package/lib/util/getos/index.d.ts.map +1 -1
- package/lib/util/getos/index.js +53 -59
- package/lib/util/getos/index.js.map +1 -1
- package/lib/util/getport/index.d.ts +34 -0
- package/lib/util/getport/index.d.ts.map +1 -0
- package/lib/util/getport/index.js +108 -0
- package/lib/util/getport/index.js.map +1 -0
- package/lib/util/lockfile.d.ts.map +1 -1
- package/lib/util/lockfile.js +155 -169
- package/lib/util/lockfile.js.map +1 -1
- package/lib/util/postinstallHelper.js +15 -18
- package/lib/util/postinstallHelper.js.map +1 -1
- package/lib/util/resolveConfig.d.ts.map +1 -1
- package/lib/util/resolveConfig.js +9 -8
- package/lib/util/resolveConfig.js.map +1 -1
- package/lib/util/utils.d.ts +20 -4
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +135 -118
- package/lib/util/utils.js.map +1 -1
- package/package.json +8 -12
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MongoBinaryDownload = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const os_1 =
|
|
5
|
+
const os_1 = tslib_1.__importDefault(require("os"));
|
|
6
6
|
const url_1 = require("url");
|
|
7
|
-
const path_1 =
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
|
-
const md5_file_1 = (0, tslib_1.__importDefault)(require("md5-file"));
|
|
10
9
|
const follow_redirects_1 = require("follow-redirects");
|
|
11
10
|
const zlib_1 = require("zlib");
|
|
12
|
-
const tar_stream_1 =
|
|
13
|
-
const yauzl_1 =
|
|
14
|
-
const MongoBinaryDownloadUrl_1 =
|
|
11
|
+
const tar_stream_1 = tslib_1.__importDefault(require("tar-stream"));
|
|
12
|
+
const yauzl_1 = tslib_1.__importDefault(require("yauzl"));
|
|
13
|
+
const MongoBinaryDownloadUrl_1 = tslib_1.__importDefault(require("./MongoBinaryDownloadUrl"));
|
|
15
14
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
16
|
-
const resolveConfig_1 =
|
|
17
|
-
const debug_1 =
|
|
15
|
+
const resolveConfig_1 = tslib_1.__importStar(require("./resolveConfig"));
|
|
16
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
18
17
|
const utils_1 = require("./utils");
|
|
19
18
|
const DryMongoBinary_1 = require("./DryMongoBinary");
|
|
20
19
|
const readline_1 = require("readline");
|
|
@@ -24,21 +23,19 @@ const log = (0, debug_1.default)('MongoMS:MongoBinaryDownload');
|
|
|
24
23
|
* Download and extract the "mongod" binary
|
|
25
24
|
*/
|
|
26
25
|
class MongoBinaryDownload {
|
|
27
|
-
// end get/set backwards compat section
|
|
28
26
|
constructor(opts) {
|
|
29
|
-
var _a, _b, _c, _d, _e, _f;
|
|
30
27
|
(0, utils_1.assertion)(typeof opts.downloadDir === 'string', new Error('An DownloadDir must be specified!'));
|
|
31
|
-
const version =
|
|
28
|
+
const version = opts.version ?? (0, resolveConfig_1.default)(resolveConfig_1.ResolveConfigVariables.VERSION);
|
|
32
29
|
(0, utils_1.assertion)(typeof version === 'string', new Error('An MongoDB Binary version must be specified!'));
|
|
33
30
|
// DryMongoBinary.generateOptions cannot be used here, because its async
|
|
34
31
|
this.binaryOpts = {
|
|
35
|
-
platform:
|
|
36
|
-
arch:
|
|
32
|
+
platform: opts.platform ?? os_1.default.platform(),
|
|
33
|
+
arch: opts.arch ?? os_1.default.arch(),
|
|
37
34
|
version: version,
|
|
38
35
|
downloadDir: opts.downloadDir,
|
|
39
|
-
checkMD5:
|
|
40
|
-
systemBinary:
|
|
41
|
-
os:
|
|
36
|
+
checkMD5: opts.checkMD5 ?? (0, resolveConfig_1.envToBool)((0, resolveConfig_1.default)(resolveConfig_1.ResolveConfigVariables.MD5_CHECK)),
|
|
37
|
+
systemBinary: opts.systemBinary ?? '',
|
|
38
|
+
os: opts.os ?? { os: 'unknown' },
|
|
42
39
|
};
|
|
43
40
|
this.dlProgress = {
|
|
44
41
|
current: 0,
|
|
@@ -47,91 +44,53 @@ class MongoBinaryDownload {
|
|
|
47
44
|
lastPrintedAt: 0,
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
|
-
// TODO: for an major version, remove the compat get/set
|
|
51
|
-
// the following get/set are to not break existing stuff
|
|
52
|
-
get checkMD5() {
|
|
53
|
-
return this.binaryOpts.checkMD5;
|
|
54
|
-
}
|
|
55
|
-
set checkMD5(val) {
|
|
56
|
-
this.binaryOpts.checkMD5 = val;
|
|
57
|
-
}
|
|
58
|
-
get downloadDir() {
|
|
59
|
-
return this.binaryOpts.downloadDir;
|
|
60
|
-
}
|
|
61
|
-
set downloadDir(val) {
|
|
62
|
-
this.binaryOpts.downloadDir = val;
|
|
63
|
-
}
|
|
64
|
-
get arch() {
|
|
65
|
-
return this.binaryOpts.arch;
|
|
66
|
-
}
|
|
67
|
-
set arch(val) {
|
|
68
|
-
this.binaryOpts.arch = val;
|
|
69
|
-
}
|
|
70
|
-
get version() {
|
|
71
|
-
return this.binaryOpts.version;
|
|
72
|
-
}
|
|
73
|
-
set version(val) {
|
|
74
|
-
this.binaryOpts.version = val;
|
|
75
|
-
}
|
|
76
|
-
get platform() {
|
|
77
|
-
return this.binaryOpts.platform;
|
|
78
|
-
}
|
|
79
|
-
set platform(val) {
|
|
80
|
-
this.binaryOpts.platform = val;
|
|
81
|
-
}
|
|
82
47
|
/**
|
|
83
48
|
* Get the full path with filename
|
|
84
49
|
* @returns Absoulte Path with FileName
|
|
85
50
|
*/
|
|
86
|
-
getPath() {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return DryMongoBinary_1.DryMongoBinary.combineBinaryName(this.downloadDir, yield DryMongoBinary_1.DryMongoBinary.getBinaryName(opts));
|
|
90
|
-
});
|
|
51
|
+
async getPath() {
|
|
52
|
+
const opts = await DryMongoBinary_1.DryMongoBinary.generateOptions(this.binaryOpts);
|
|
53
|
+
return DryMongoBinary_1.DryMongoBinary.combineBinaryName(this.binaryOpts.downloadDir, await DryMongoBinary_1.DryMongoBinary.getBinaryName(opts));
|
|
91
54
|
}
|
|
92
55
|
/**
|
|
93
56
|
* Get the path of the already downloaded "mongod" file
|
|
94
57
|
* otherwise download it and then return the path
|
|
95
58
|
*/
|
|
96
|
-
getMongodPath() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
throw new Error(`Cannot find downloaded mongod binary by path "${mongodPath}"`);
|
|
111
|
-
});
|
|
59
|
+
async getMongodPath() {
|
|
60
|
+
log('getMongodPath');
|
|
61
|
+
const mongodPath = await this.getPath();
|
|
62
|
+
if (await (0, utils_1.pathExists)(mongodPath)) {
|
|
63
|
+
log(`getMongodPath: mongod path "${mongodPath}" already exists, using this`);
|
|
64
|
+
return mongodPath;
|
|
65
|
+
}
|
|
66
|
+
const mongoDBArchive = await this.startDownload();
|
|
67
|
+
await this.extract(mongoDBArchive);
|
|
68
|
+
await fs_1.promises.unlink(mongoDBArchive);
|
|
69
|
+
if (await (0, utils_1.pathExists)(mongodPath)) {
|
|
70
|
+
return mongodPath;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`Cannot find downloaded mongod binary by path "${mongodPath}"`);
|
|
112
73
|
}
|
|
113
74
|
/**
|
|
114
75
|
* Download the MongoDB Archive and check it against an MD5
|
|
115
76
|
* @returns The MongoDB Archive location
|
|
116
77
|
*/
|
|
117
|
-
startDownload() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return mongoDBArchive;
|
|
134
|
-
});
|
|
78
|
+
async startDownload() {
|
|
79
|
+
log('startDownload');
|
|
80
|
+
const mbdUrl = new MongoBinaryDownloadUrl_1.default(this.binaryOpts);
|
|
81
|
+
await (0, utils_1.mkdir)(this.binaryOpts.downloadDir);
|
|
82
|
+
try {
|
|
83
|
+
await fs_1.promises.access(this.binaryOpts.downloadDir, fs_1.constants.X_OK | fs_1.constants.W_OK); // check that this process has permissions to create files & modify file contents & read file contents
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error(`Download Directory at "${this.binaryOpts.downloadDir}" does not have sufficient permissions to be used by this process\n` +
|
|
87
|
+
'Needed Permissions: Write & Execute (-wx)\n');
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
const downloadUrl = await mbdUrl.getDownloadUrl();
|
|
91
|
+
const mongoDBArchive = await this.download(downloadUrl);
|
|
92
|
+
await this.makeMD5check(`${downloadUrl}.md5`, mongoDBArchive);
|
|
93
|
+
return mongoDBArchive;
|
|
135
94
|
}
|
|
136
95
|
/**
|
|
137
96
|
* Download MD5 file and check it against the MongoDB Archive
|
|
@@ -142,94 +101,87 @@ class MongoBinaryDownload {
|
|
|
142
101
|
* @returns {true} if the md5 check was successful
|
|
143
102
|
* @throws if the md5 check failed
|
|
144
103
|
*/
|
|
145
|
-
makeMD5check(urlForReferenceMD5, mongoDBArchive) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return true;
|
|
163
|
-
});
|
|
104
|
+
async makeMD5check(urlForReferenceMD5, mongoDBArchive) {
|
|
105
|
+
log('makeMD5check: Checking MD5 of downloaded binary...');
|
|
106
|
+
if (!this.binaryOpts.checkMD5) {
|
|
107
|
+
log('makeMD5check: checkMD5 is disabled');
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const archiveMD5Path = await this.download(urlForReferenceMD5);
|
|
111
|
+
const signatureContent = (await fs_1.promises.readFile(archiveMD5Path)).toString('utf-8');
|
|
112
|
+
const regexMatch = signatureContent.match(/^\s*([\w\d]+)\s*/i);
|
|
113
|
+
const md5SigRemote = regexMatch ? regexMatch[1] : null;
|
|
114
|
+
const md5SigLocal = await (0, utils_1.md5FromFile)(mongoDBArchive);
|
|
115
|
+
log(`makeMD5check: Local MD5: ${md5SigLocal}, Remote MD5: ${md5SigRemote}`);
|
|
116
|
+
if (md5SigRemote !== md5SigLocal) {
|
|
117
|
+
throw new errors_1.Md5CheckFailedError(md5SigLocal, md5SigRemote || 'unknown');
|
|
118
|
+
}
|
|
119
|
+
await fs_1.promises.unlink(archiveMD5Path);
|
|
120
|
+
return true;
|
|
164
121
|
}
|
|
165
122
|
/**
|
|
166
123
|
* Download file from downloadUrl
|
|
167
124
|
* @param downloadUrl URL to download a File
|
|
168
125
|
* @returns The Path to the downloaded archive file
|
|
169
126
|
*/
|
|
170
|
-
download(downloadUrl) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return downloadedFile;
|
|
204
|
-
});
|
|
127
|
+
async download(downloadUrl) {
|
|
128
|
+
log('download');
|
|
129
|
+
const proxy = process.env['yarn_https-proxy'] ||
|
|
130
|
+
process.env.yarn_proxy ||
|
|
131
|
+
process.env['npm_config_https-proxy'] ||
|
|
132
|
+
process.env.npm_config_proxy ||
|
|
133
|
+
process.env.https_proxy ||
|
|
134
|
+
process.env.http_proxy ||
|
|
135
|
+
process.env.HTTPS_PROXY ||
|
|
136
|
+
process.env.HTTP_PROXY;
|
|
137
|
+
const strictSsl = process.env.npm_config_strict_ssl === 'true';
|
|
138
|
+
const urlObject = new url_1.URL(downloadUrl);
|
|
139
|
+
urlObject.port = urlObject.port || '443';
|
|
140
|
+
const requestOptions = {
|
|
141
|
+
method: 'GET',
|
|
142
|
+
rejectUnauthorized: strictSsl,
|
|
143
|
+
protocol: (0, resolveConfig_1.envToBool)((0, resolveConfig_1.default)(resolveConfig_1.ResolveConfigVariables.USE_HTTP)) ? 'http:' : 'https:',
|
|
144
|
+
agent: proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined,
|
|
145
|
+
};
|
|
146
|
+
const filename = urlObject.pathname.split('/').pop();
|
|
147
|
+
if (!filename) {
|
|
148
|
+
throw new Error(`MongoBinaryDownload: missing filename for url "${downloadUrl}"`);
|
|
149
|
+
}
|
|
150
|
+
const downloadLocation = path_1.default.resolve(this.binaryOpts.downloadDir, filename);
|
|
151
|
+
const tempDownloadLocation = path_1.default.resolve(this.binaryOpts.downloadDir, `${filename}.downloading`);
|
|
152
|
+
log(`download: Downloading${proxy ? ` via proxy "${proxy}"` : ''}: "${downloadUrl}"`);
|
|
153
|
+
if (await (0, utils_1.pathExists)(downloadLocation)) {
|
|
154
|
+
log('download: Already downloaded archive found, skipping download');
|
|
155
|
+
return downloadLocation;
|
|
156
|
+
}
|
|
157
|
+
this.assignDownloadingURL(urlObject);
|
|
158
|
+
const downloadedFile = await this.httpDownload(urlObject, requestOptions, downloadLocation, tempDownloadLocation);
|
|
159
|
+
return downloadedFile;
|
|
205
160
|
}
|
|
206
161
|
/**
|
|
207
162
|
* Extract given Archive
|
|
208
163
|
* @param mongoDBArchive Archive location
|
|
209
164
|
* @returns extracted directory location
|
|
210
165
|
*/
|
|
211
|
-
extract(mongoDBArchive) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
return mongodbFullPath;
|
|
232
|
-
});
|
|
166
|
+
async extract(mongoDBArchive) {
|
|
167
|
+
log('extract');
|
|
168
|
+
const mongodbFullPath = await this.getPath();
|
|
169
|
+
log(`extract: archive: "${mongoDBArchive}" final: "${mongodbFullPath}"`);
|
|
170
|
+
await (0, utils_1.mkdir)(path_1.default.dirname(mongodbFullPath));
|
|
171
|
+
const filter = (file) => /(?:bin\/(?:mongod(?:\.exe)?))$/i.test(file);
|
|
172
|
+
if (/(.tar.gz|.tgz)$/.test(mongoDBArchive)) {
|
|
173
|
+
await this.extractTarGz(mongoDBArchive, mongodbFullPath, filter);
|
|
174
|
+
}
|
|
175
|
+
else if (/.zip$/.test(mongoDBArchive)) {
|
|
176
|
+
await this.extractZip(mongoDBArchive, mongodbFullPath, filter);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new Error(`MongoBinaryDownload: unsupported archive "${mongoDBArchive}" (downloaded from "${this._downloadingUrl ?? 'unknown'}"). Broken archive from MongoDB Provider?`);
|
|
180
|
+
}
|
|
181
|
+
if (!(await (0, utils_1.pathExists)(mongodbFullPath))) {
|
|
182
|
+
throw new Error(`MongoBinaryDownload: missing mongod binary in "${mongoDBArchive}" (downloaded from "${this._downloadingUrl ?? 'unknown'}"). Broken archive from MongoDB Provider?`);
|
|
183
|
+
}
|
|
184
|
+
return mongodbFullPath;
|
|
233
185
|
}
|
|
234
186
|
/**
|
|
235
187
|
* Extract a .tar.gz archive
|
|
@@ -237,34 +189,32 @@ class MongoBinaryDownload {
|
|
|
237
189
|
* @param extractPath Directory to extract to
|
|
238
190
|
* @param filter Method to determine which files to extract
|
|
239
191
|
*/
|
|
240
|
-
extractTarGz(mongoDBArchive, extractPath, filter) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
.on('finish', res);
|
|
267
|
-
});
|
|
192
|
+
async extractTarGz(mongoDBArchive, extractPath, filter) {
|
|
193
|
+
log('extractTarGz');
|
|
194
|
+
const extract = tar_stream_1.default.extract();
|
|
195
|
+
extract.on('entry', (header, stream, next) => {
|
|
196
|
+
if (filter(header.name)) {
|
|
197
|
+
stream.pipe((0, fs_1.createWriteStream)(extractPath, {
|
|
198
|
+
mode: 0o775,
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
stream.on('end', () => next());
|
|
202
|
+
stream.resume();
|
|
203
|
+
});
|
|
204
|
+
return new Promise((res, rej) => {
|
|
205
|
+
(0, fs_1.createReadStream)(mongoDBArchive)
|
|
206
|
+
.on('error', (err) => {
|
|
207
|
+
rej(new errors_1.GenericMMSError('Unable to open tarball ' + mongoDBArchive + ': ' + err));
|
|
208
|
+
})
|
|
209
|
+
.pipe((0, zlib_1.createUnzip)())
|
|
210
|
+
.on('error', (err) => {
|
|
211
|
+
rej(new errors_1.GenericMMSError('Error during unzip for ' + mongoDBArchive + ': ' + err));
|
|
212
|
+
})
|
|
213
|
+
.pipe(extract)
|
|
214
|
+
.on('error', (err) => {
|
|
215
|
+
rej(new errors_1.GenericMMSError('Error during untar for ' + mongoDBArchive + ': ' + err));
|
|
216
|
+
})
|
|
217
|
+
.on('finish', res);
|
|
268
218
|
});
|
|
269
219
|
}
|
|
270
220
|
/**
|
|
@@ -273,29 +223,27 @@ class MongoBinaryDownload {
|
|
|
273
223
|
* @param extractPath Directory to extract to
|
|
274
224
|
* @param filter Method to determine which files to extract
|
|
275
225
|
*/
|
|
276
|
-
extractZip(mongoDBArchive, extractPath, filter) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
226
|
+
async extractZip(mongoDBArchive, extractPath, filter) {
|
|
227
|
+
log('extractZip');
|
|
228
|
+
return new Promise((resolve, reject) => {
|
|
229
|
+
yauzl_1.default.open(mongoDBArchive, { lazyEntries: true }, (err, zipfile) => {
|
|
230
|
+
if (err || !zipfile) {
|
|
231
|
+
return reject(err);
|
|
232
|
+
}
|
|
233
|
+
zipfile.readEntry();
|
|
234
|
+
zipfile.on('end', () => resolve());
|
|
235
|
+
zipfile.on('entry', (entry) => {
|
|
236
|
+
if (!filter(entry.fileName)) {
|
|
237
|
+
return zipfile.readEntry();
|
|
283
238
|
}
|
|
284
|
-
zipfile.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (!filter(entry.fileName)) {
|
|
288
|
-
return zipfile.readEntry();
|
|
239
|
+
zipfile.openReadStream(entry, (err2, r) => {
|
|
240
|
+
if (err2 || !r) {
|
|
241
|
+
return reject(err2);
|
|
289
242
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
r.on('end', () => zipfile.readEntry());
|
|
295
|
-
r.pipe((0, fs_1.createWriteStream)(extractPath, {
|
|
296
|
-
mode: 0o775,
|
|
297
|
-
}));
|
|
298
|
-
});
|
|
243
|
+
r.on('end', () => zipfile.readEntry());
|
|
244
|
+
r.pipe((0, fs_1.createWriteStream)(extractPath, {
|
|
245
|
+
mode: 0o775,
|
|
246
|
+
}));
|
|
299
247
|
});
|
|
300
248
|
});
|
|
301
249
|
});
|
|
@@ -307,59 +255,59 @@ class MongoBinaryDownload {
|
|
|
307
255
|
* @param downloadLocation The location the File should be after the download
|
|
308
256
|
* @param tempDownloadLocation The location the File should be while downloading
|
|
309
257
|
*/
|
|
310
|
-
httpDownload(url, httpOptions, downloadLocation, tempDownloadLocation) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
reject(new errors_1.DownloadError(downloadUrl, `Status Code isnt 200! (it is ${response.statusCode})`));
|
|
258
|
+
async httpDownload(url, httpOptions, downloadLocation, tempDownloadLocation) {
|
|
259
|
+
log('httpDownload');
|
|
260
|
+
const downloadUrl = this.assignDownloadingURL(url);
|
|
261
|
+
const maxRedirects = parseInt((0, resolveConfig_1.default)(resolveConfig_1.ResolveConfigVariables.MAX_REDIRECTS) || '');
|
|
262
|
+
const useHttpsOptions = {
|
|
263
|
+
maxRedirects: Number.isNaN(maxRedirects) ? 2 : maxRedirects,
|
|
264
|
+
...httpOptions,
|
|
265
|
+
};
|
|
266
|
+
return new Promise((resolve, reject) => {
|
|
267
|
+
log(`httpDownload: trying to download "${downloadUrl}"`);
|
|
268
|
+
follow_redirects_1.https
|
|
269
|
+
.get(url, useHttpsOptions, (response) => {
|
|
270
|
+
if (response.statusCode != 200) {
|
|
271
|
+
if (response.statusCode === 403) {
|
|
272
|
+
reject(new errors_1.DownloadError(downloadUrl, "Status Code is 403 (MongoDB's 404)\n" +
|
|
273
|
+
"This means that the requested version-platform combination doesn't exist\n" +
|
|
274
|
+
"Try to use different version 'new MongoMemoryServer({ binary: { version: 'X.Y.Z' } })'\n" +
|
|
275
|
+
'List of available versions can be found here: ' +
|
|
276
|
+
'https://www.mongodb.com/download-center/community/releases/archive'));
|
|
330
277
|
return;
|
|
331
278
|
}
|
|
332
|
-
|
|
333
|
-
|
|
279
|
+
reject(new errors_1.DownloadError(downloadUrl, `Status Code isnt 200! (it is ${response.statusCode})`));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (typeof response.headers['content-length'] != 'string') {
|
|
283
|
+
reject(new errors_1.DownloadError(downloadUrl, 'Response header "content-length" is empty!'));
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.dlProgress.current = 0;
|
|
287
|
+
this.dlProgress.length = parseInt(response.headers['content-length'], 10);
|
|
288
|
+
this.dlProgress.totalMb = Math.round((this.dlProgress.length / 1048576) * 10) / 10;
|
|
289
|
+
const fileStream = (0, fs_1.createWriteStream)(tempDownloadLocation);
|
|
290
|
+
response.pipe(fileStream);
|
|
291
|
+
fileStream.on('finish', async () => {
|
|
292
|
+
if (this.dlProgress.current < this.dlProgress.length &&
|
|
293
|
+
!httpOptions.path?.endsWith('.md5')) {
|
|
294
|
+
reject(new errors_1.DownloadError(downloadUrl, `Too small (${this.dlProgress.current} bytes) mongod binary downloaded.`));
|
|
334
295
|
return;
|
|
335
296
|
}
|
|
336
|
-
this.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
!((_a = httpOptions.path) === null || _a === void 0 ? void 0 : _a.endsWith('.md5'))) {
|
|
345
|
-
reject(new errors_1.DownloadError(downloadUrl, `Too small (${this.dlProgress.current} bytes) mongod binary downloaded.`));
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
this.printDownloadProgress({ length: 0 }, true);
|
|
349
|
-
fileStream.close();
|
|
350
|
-
yield fs_1.promises.rename(tempDownloadLocation, downloadLocation);
|
|
351
|
-
log(`httpDownload: moved "${tempDownloadLocation}" to "${downloadLocation}"`);
|
|
352
|
-
resolve(downloadLocation);
|
|
353
|
-
}));
|
|
354
|
-
response.on('data', (chunk) => {
|
|
355
|
-
this.printDownloadProgress(chunk);
|
|
356
|
-
});
|
|
357
|
-
})
|
|
358
|
-
.on('error', (err) => {
|
|
359
|
-
// log it without having debug enabled
|
|
360
|
-
console.error(`Couldnt download "${downloadUrl}"!`, err.message);
|
|
361
|
-
reject(new errors_1.DownloadError(downloadUrl, err.message));
|
|
297
|
+
this.printDownloadProgress({ length: 0 }, true);
|
|
298
|
+
fileStream.close();
|
|
299
|
+
await fs_1.promises.rename(tempDownloadLocation, downloadLocation);
|
|
300
|
+
log(`httpDownload: moved "${tempDownloadLocation}" to "${downloadLocation}"`);
|
|
301
|
+
resolve(downloadLocation);
|
|
302
|
+
});
|
|
303
|
+
response.on('data', (chunk) => {
|
|
304
|
+
this.printDownloadProgress(chunk);
|
|
362
305
|
});
|
|
306
|
+
})
|
|
307
|
+
.on('error', (err) => {
|
|
308
|
+
// log it without having debug enabled
|
|
309
|
+
console.error(`Couldnt download "${downloadUrl}"!`, err.message);
|
|
310
|
+
reject(new errors_1.DownloadError(downloadUrl, err.message));
|
|
363
311
|
});
|
|
364
312
|
});
|
|
365
313
|
}
|
|
@@ -376,8 +324,8 @@ class MongoBinaryDownload {
|
|
|
376
324
|
this.dlProgress.lastPrintedAt = now;
|
|
377
325
|
const percentComplete = Math.round(((100.0 * this.dlProgress.current) / this.dlProgress.length) * 10) / 10;
|
|
378
326
|
const mbComplete = Math.round((this.dlProgress.current / 1048576) * 10) / 10;
|
|
379
|
-
const crReturn = this.platform === 'win32' ? '\x1b[0G' : '\r';
|
|
380
|
-
const message = `Downloading MongoDB "${this.version}": ${percentComplete}% (${mbComplete}mb / ${this.dlProgress.totalMb}mb)${crReturn}`;
|
|
327
|
+
const crReturn = this.binaryOpts.platform === 'win32' ? '\x1b[0G' : '\r';
|
|
328
|
+
const message = `Downloading MongoDB "${this.binaryOpts.version}": ${percentComplete}% (${mbComplete}mb / ${this.dlProgress.totalMb}mb)${crReturn}`;
|
|
381
329
|
if (process.stdout.isTTY) {
|
|
382
330
|
// if TTY overwrite last line over and over until finished and clear line to avoid residual characters
|
|
383
331
|
(0, readline_1.clearLine)(process.stdout, 0); // this is because "process.stdout.clearLine" does not exist anymore
|