Skip to content

Commit 27333bb

Browse files
committed
fix: drop fs-extra dependency to avoid memory leak on jest tests
Closes #68
1 parent ddf7524 commit 27333bb

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"babel-runtime": "^6.26.0",
5252
"debug": "^3.1.0",
5353
"decompress": "^4.2.0",
54-
"fs-extra": "^6.0.1",
5554
"get-port": "^3.2.0",
5655
"getos": "^3.1.0",
5756
"https-proxy-agent": "^2.2.1",

src/util/MongoBinaryDownload.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os from 'os';
55
import url from 'url';
66
import path from 'path';
7-
import fs from 'fs-extra';
7+
import fs from 'fs';
88
import md5File from 'md5-file';
99
import https from 'https';
1010
import HttpsProxyAgent from 'https-proxy-agent';
@@ -83,7 +83,9 @@ export default class MongoBinaryDownload {
8383
version: this.version,
8484
});
8585

86-
await fs.ensureDir(this.downloadDir);
86+
if (!fs.existsSync(this.downloadDir)) {
87+
fs.mkdirSync(this.downloadDir);
88+
}
8789

8890
const downloadUrl = await mbdUrl.getDownloadUrl();
8991
const mongoDBArchive = await this.download(downloadUrl);
@@ -95,8 +97,9 @@ export default class MongoBinaryDownload {
9597
}
9698

9799
async checkMd5(mongoDBArchiveMd5: string, mongoDBArchive: string) {
98-
const signatureContent = (await fs.readFile(mongoDBArchiveMd5)).toString('UTF-8');
99-
const md5Remote = signatureContent.match(/(.*?)\s/)[1];
100+
const signatureContent = fs.readFileSync(mongoDBArchiveMd5).toString('UTF-8');
101+
const m = signatureContent.match(/(.*?)\s/);
102+
const md5Remote = m ? m[1] : null;
100103
const md5Local = md5File.sync(mongoDBArchive);
101104
if (md5Remote !== md5Local) {
102105
throw new Error('MongoBinaryDownload: md5 check is failed');
@@ -142,7 +145,10 @@ export default class MongoBinaryDownload {
142145
const binaryName = this.platform === 'win32' ? 'mongod.exe' : 'mongod';
143146
const extractDir = path.resolve(this.downloadDir, this.version);
144147
this.debug(`extract(): ${extractDir}`);
145-
await fs.ensureDir(extractDir);
148+
149+
if (!fs.existsSync(extractDir)) {
150+
fs.mkdirSync(extractDir);
151+
}
146152

147153
let filter;
148154
if (this.platform === 'win32') {
@@ -185,11 +191,10 @@ export default class MongoBinaryDownload {
185191
response.pipe(fileStream);
186192

187193
fileStream.on('finish', () => {
188-
fileStream.close(() => {
189-
fs.renameSync(tempDownloadLocation, downloadLocation);
190-
this.debug(`renamed ${tempDownloadLocation} to ${downloadLocation}`);
191-
resolve(downloadLocation);
192-
});
194+
fileStream.close();
195+
fs.renameSync(tempDownloadLocation, downloadLocation);
196+
this.debug(`renamed ${tempDownloadLocation} to ${downloadLocation}`);
197+
resolve(downloadLocation);
193198
});
194199

195200
response.on('data', (chunk: any) => {

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ fs-copy-file-sync@^1.1.1:
23602360
version "1.1.1"
23612361
resolved "https://registry.yarnpkg.com/fs-copy-file-sync/-/fs-copy-file-sync-1.1.1.tgz#11bf32c096c10d126e5f6b36d06eece776062918"
23622362

2363-
fs-extra@^6.0.0, fs-extra@^6.0.1:
2363+
fs-extra@^6.0.0:
23642364
version "6.0.1"
23652365
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-6.0.1.tgz#8abc128f7946e310135ddc93b98bddb410e7a34b"
23662366
dependencies:

0 commit comments

Comments
 (0)