Skip to content

Commit 5629c17

Browse files
AJRdevnodkz
authored andcommitted
fix(build): add mongo_killer.js to the package
Resolves #151
1 parent b8e4d23 commit 5629c17

File tree

6 files changed

+26
-37
lines changed

6 files changed

+26
-37
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
flow-typed/*
22
lib/*
3-
postinstall.js

.old.tslint.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"repository": "https://github.com/nodkz/mongodb-memory-server",
88
"files": [
99
"lib",
10-
"postinstall.js"
10+
"scripts"
1111
],
1212
"keywords": [
1313
"mongodb",
@@ -80,7 +80,7 @@
8080
"test": "npm run lint && npm run tscheck && npm run coverage",
8181
"tscheck": "tsc --noEmit",
8282
"semantic-release": "semantic-release",
83-
"postinstall": "node ./postinstall.js"
83+
"postinstall": "node ./scripts/postinstall.js"
8484
},
8585
"config": {
8686
"commitizen": {

src/util/mongo_killer.js renamed to scripts/mongo_killer.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/* eslint-disable */
21
/*
3-
make sure every few seconds that parent is still alive
4-
and if it is dead, we will kill child too.
5-
this is to ensure that exits done via kill
6-
wont leave mongod around
2+
Make sure every few seconds that `parent` and `child` are alive:
3+
- if `parent` is dead:
4+
- kill child
5+
- kill itself
6+
- if `child` is dead:
7+
- kill itself
78
*/
89

9-
var parentPid = parseInt(process.argv[2], 10);
10-
var childPid = parseInt(process.argv[3], 10);
10+
const parentPid = parseInt(process.argv[2], 10);
11+
const childPid = parseInt(process.argv[3], 10);
1112

1213
if (parentPid && childPid) {
1314
setInterval(() => {

postinstall.js renamed to scripts/postinstall.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ if (skipDownload) {
2525
process.exit(0);
2626
}
2727

28-
if (isModuleExists('./lib/util/MongoBinary')) {
29-
const MongoBinary = require('./lib/util/MongoBinary').default;
28+
if (isModuleExists('../lib/util/MongoBinary')) {
29+
const MongoBinary = require('../lib/util/MongoBinary').default;
3030

3131
console.log('mongodb-memory-server: checking MongoDB binaries cache...');
3232
MongoBinary.getPath({})
33-
.then(binPath => {
33+
.then((binPath) => {
3434
console.log(`mongodb-memory-server: binary path is ${binPath}`);
3535
})
36-
.catch(err => {
36+
.catch((err) => {
3737
console.log(`failed to download/install MongoDB binaries. The error:
3838
${err}`);
3939
process.exit(0);

src/util/MongoInstance.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,24 @@ export default class MongoInstance {
169169
}
170170

171171
_launchKiller(parentPid: number, childPid: number): ChildProcess {
172+
this.debug(`Called MongoInstance._launchKiller(parent: ${parentPid}, child: ${childPid}):`);
172173
// spawn process which kills itself and mongo process if current process is dead
173174
const killer = spawnChild(
174175
process.argv[0],
175-
[path.resolve(__dirname, 'mongo_killer.js'), parentPid.toString(), childPid.toString()],
176+
[
177+
path.resolve(__dirname, '../../scripts/mongo_killer.js'),
178+
parentPid.toString(),
179+
childPid.toString(),
180+
],
176181
{ stdio: 'pipe' }
177182
);
178183

184+
['exit', 'message', 'disconnect', 'error'].forEach((e) => {
185+
killer.on(e, (...args) => {
186+
this.debug(`[MongoKiller]: ${e} - ${JSON.stringify(args)}`);
187+
});
188+
});
189+
179190
return killer;
180191
}
181192

0 commit comments

Comments
 (0)