New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

node-persistent-software

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-persistent-software - npm Package Compare versions

Comparing version
1.3.0
to
1.4.0
+26
lib/index.d.ts
/// <reference types="node" />
declare module "node-persistent-software" {
class PersistantSoftware extends require("asynchronous-eventemitter") {
protected _software: string;
protected _args: Array<string>;
protected _options: object;
protected _ended: boolean;
public maxCountRun: number;
public successCountRun: number;
constructor(software: string, args?: Array<string>, options?: object);
public max(max: number): PersistantSoftware;
public infinite(): PersistantSoftware;
public start(): PersistantSoftware;
public end(): PersistantSoftware;
}
export = PersistantSoftware;
}
"use strict";
// deps
const { exec } = require("child_process");
const { join } = require("path");
const { unlink } = require("fs");
// consts
const MAX_TIMEOUT = 10000;
// tests
describe("compilation typescript", () => {
after((done) => {
unlink(join(__dirname, "typescript", "compilation.js"), (err) => {
return err ? done(err) : done();
});
});
it("should compile typescript file", (done) => {
exec("tsc " + join(__dirname, "typescript", "compilation.ts"), {
"cwd": join(__dirname, ".."),
"windowsHide": true
}, (err) => {
return err ? done(err) : done();
});
}).timeout(MAX_TIMEOUT);
});
/// <reference path="../../lib/index.d.ts" />
import PersistantSoftware = require("../../lib/main.js");
new PersistantSoftware("node", [ "-v" ]).on("error", (err: Error) => {
console.log(err);
})
.infinite()
.on("firststart", () => {
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("node is started again...");
}).on("start", (child_process) => {
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
new PersistantSoftware("node", [ "-v" ]).on("error", (err: Error) => {
console.log(err);
})
.max(5)
.on("firststart", () => {
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("node is started again...");
}).on("start", () => {
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
+4
-1
language: node_js
node_js:
- "6"
- "8"
install:
- "npm install -g typescript"
- "npm install"
script: "npm run-script tests"
sudo: false
+23
-30

@@ -12,13 +12,13 @@

constructor (software, args, options) {
constructor (software, args = null, options = null) {
super();
this.software = software;
this.args = args && "object" === typeof args && args instanceof Array ? args : null;
this.options = options && "object" === typeof options ? options : null;
this._software = software;
this._args = args && "object" === typeof args && args instanceof Array ? args : null;
this._options = options && "object" === typeof options ? options : null;
this.currentChildProcess = null;
this._currentChildProcess = null;
this.ended = false;
this._ended = false;

@@ -46,19 +46,19 @@ this.infinite();

if (!this.ended) {
if (!this._ended) {
if (!this.args) {
this.currentChildProcess = spawn(this.software);
if (!this._args) {
this._currentChildProcess = spawn(this._software);
}
else if (!this.options) {
this.currentChildProcess = spawn(this.software, this.args);
else if (!this._options) {
this._currentChildProcess = spawn(this._software, this._args);
}
else {
this.currentChildProcess = spawn(this.software, this.args, this.options);
this._currentChildProcess = spawn(this._software, this._args, this._options);
}
this.currentChildProcess.on("error", (err) => {
this._currentChildProcess.on("error", (err) => {
this.emit("error", err);
});
if (!this.currentChildProcess || !this.currentChildProcess.pid) {
if (!this._currentChildProcess || !this._currentChildProcess.pid) {
this.end();

@@ -77,9 +77,9 @@ }

this.emit("start", this.currentChildProcess);
this.emit("start", this._currentChildProcess);
this.currentChildProcess.on("exit", () => {
this._currentChildProcess.on("exit", () => {
this.emit("stop");
if (!this.ended) {
if (!this._ended) {

@@ -115,10 +115,10 @@ if (0 >= this.maxCountRun) {

this.ended = true;
this._ended = true;
if (this.currentChildProcess) {
if (this._currentChildProcess) {
if (this.currentChildProcess.pid) {
if (this._currentChildProcess.pid) {
try {
process.kill(this.currentChildProcess.pid);
process.kill(this._currentChildProcess.pid);
}

@@ -131,17 +131,10 @@ catch (e) {

this.currentChildProcess = null;
this._currentChildProcess = null;
}
this.emit("end")
.removeAllListeners("start")
.removeAllListeners("firststart")
.removeAllListeners("restart")
.removeAllListeners("stop")
.removeAllListeners("end");
return this.emit("end");
return this;
}
};
{
"name": "node-persistent-software",
"version": "1.3.0",
"version": "1.4.0",
"description": "Spawn a software and keep it running",
"main": "lib/main.js",
"typings": "lib/index.d.ts",
"scripts": {
"start": "node lib/main.js",
"tests": "gulp tests"
},
"pre-commit": [
"test"
"pre-push": [
"tests"
],

@@ -31,5 +31,6 @@ "repository": {

"dependencies": {
"asynchronous-eventemitter": "0.3.0"
"asynchronous-eventemitter": "0.3.2"
},
"devDependencies": {
"@types/node": "9.6.6",
"gulp": "3.9.1",

@@ -41,3 +42,3 @@ "gulp-plumber": "1.1.0",

"gulp-coveralls": "0.1.4",
"pre-commit": "1.2.2"
"pre-push": "0.1.1"
},

@@ -44,0 +45,0 @@ "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme",

+40
-38

@@ -18,42 +18,35 @@ # node-persistent-software

* ``` string software ``` path to the software
* ``` array arguments ``` arguments passed to the software
* ``` object options ``` options passed to the software
* ``` object currentChildProcess ``` current child_process
* ``` boolean ended ``` if ended, don't restart it
* ``` int maxCountRun ``` max start iteration
* ``` int successCountRun ``` current success start iteration
* ``` asynchronous-eventemitter eventEmitter ``` async events manager
* ``` maxCountRun: number ``` max start iteration
* ``` successCountRun: number ``` current success start iteration
### Constructor
* ``` constructor(string software [, array arguments [, object options ] ] ) ``` => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
* ``` constructor(software: string, args?: Array<string>, options?: object) ``` => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
### Methods
* ``` max(int maxIteration) : this ``` change max iterations and reset current
* ``` max(maxIteration: number) : this ``` change max iterations and reset current
* ``` infinite() : this ``` no max iteration and reset current
* ``` start() : this ``` run the software for the first time
* ``` end() : this ``` stop the software and don't restart it
* ``` end() : this ``` stop the software and does not restart it
### Events
* ``` on("error", (string err) => {}) : this ``` fire if an error occurs (use try/catch to avoid loop)
* ``` on("error", (err: Error) => void) : this ``` fire if an error occurs (use try/catch to avoid loop)
* ``` on("firststart", () => {}) : this ``` fire if the software starts for the first time
* ``` on("restart", () => {}) : this ``` fire if the software restarts
* ``` on("start", (object child_process) => {}) : this ``` fire if the software starts (firststart && restart) => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
* ``` on("firststart", () => void) : this ``` fire if the software starts for the first time
* ``` on("restart", () => void) : this ``` fire if the software restarts
* ``` on("start", (child_process: child_process.ChildProcess) => void) : this ``` fire if the software starts (firststart && restart) => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
* ``` on("stop", () => {}) : this ``` fire if the software is killed
* ``` on("end", () => {}) : this ``` fire if the software is killed and cannot be restarted
* ``` on("stop", () => void) : this ``` fire if the software is killed
* ``` on("end", () => void) : this ``` fire if the software is killed and cannot be restarted
## Examples
```js
const PersistantSoftware = require('node-persistent-software');
### Native
new PersistantSoftware(
"C:\\Program Files\\Mozilla Firefox\\firefox.exe",
[ "https://www.npmjs.com/package/node-persistent-software" ]
).on("error", (msg) => {
```javascript
const PersistantSoftware = require("node-persistent-software");
new PersistantSoftware("node", [ "-v" ]).on("error", (msg) => {
console.log(msg);

@@ -65,21 +58,18 @@ })

.on("firststart", () => {
console.log("Firefox is started for the first time !");
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("Firefox is started again...");
console.log("node is started again...");
}).on("start", (child_process) => {
console.log("anyway, Firefox is started.");
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("Firefox is stopped, trying to restart...");
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ Firefox is stopped and cannot be restarted /!\\");
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
new PersistantSoftware(
"C:\\Program Files\\Mozilla Firefox\\firefox.exe",
[ "https://github.com/Psychopoulet/node-persistent-software" ]
).on("error", (msg) {
console.log(msg);
new PersistantSoftware("node", [ "-v" ]).on("error", (err) => {
console.log(err);
})

@@ -90,16 +80,28 @@

.on("firststart", () => {
console.log("Firefox is started for the first time !");
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("Firefox is started again...");
console.log("node is started again...");
}).on("start", () => {
console.log("anyway, Firefox is started.");
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("Firefox is stopped, trying to restart...");
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ Firefox is stopped and cannot be restarted /!\\");
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
```
### Typescript
```typescript
import PersistantSoftware = require("node-persistent-software");
new PersistantSoftware("node", [ "-v" ]).on("error", (err) => {
console.log(err);
})
.infinite();
```
## Tests

@@ -106,0 +108,0 @@

@@ -12,2 +12,3 @@

const IPCONFIG = "win32" === require("os").platform() ? "ipconfig" : "ifconfig";
const MAX_TIMEOUT = 10000;

@@ -40,3 +41,3 @@ // tests

}).timeout(1 * 1000);
}).timeout(MAX_TIMEOUT);

@@ -68,3 +69,3 @@ it("should check no args running", () => {

}).timeout(1 * 1000);
}).timeout(MAX_TIMEOUT);

@@ -96,3 +97,3 @@ it("should check normal running with max", () => {

}).timeout(1 * 1000);
}).timeout(MAX_TIMEOUT);

@@ -120,3 +121,3 @@ it("should check normal running with infinite and end", () => {

}).timeout(1 * 1000);
}).timeout(MAX_TIMEOUT);

@@ -159,4 +160,4 @@ it("should check normal running with infinite and end", () => {

}).timeout(5 * 1000);
}).timeout(MAX_TIMEOUT);
});