Compare commits
56 Commits
Author | SHA1 | Date | |
---|---|---|---|
83bcdc4eb0 | |||
5c2f318158 | |||
e8043c5734 | |||
b9805efa57 | |||
a52a4ab7fd | |||
ea609f83d7 | |||
3db25512ee | |||
5c2e3fea6c | |||
7e5178d825 | |||
9795489d67 | |||
28733cbd73 | |||
f12335ea62 | |||
f12a92660f | |||
c81800cfab | |||
05b94469b5 | |||
eda415893c | |||
630b7661d9 | |||
702c0164a2 | |||
0220252b28 | |||
fcdcd4b929 | |||
c2f7e98481 | |||
a2242105a1 | |||
44431e7d25 | |||
3999015b23 | |||
77ad483a8a | |||
904309564a | |||
d8c03fd9ca | |||
7e5c0fe678 | |||
93b44ba888 | |||
30249ad254 | |||
07be849d2f | |||
d31f85c6cb | |||
fb2b72a97f | |||
18dfa70d16 | |||
1cb892c357 | |||
275e242ad8 | |||
b295b55a92 | |||
8fbd9c0b51 | |||
1850f7d132 | |||
e0dffad3f2 | |||
241880f2b0 | |||
9d33a5df53 | |||
57ddf4c45d | |||
1329513543 | |||
e1acfd03e6 | |||
d73c877815 | |||
347036cf4e | |||
661e782367 | |||
6da41845f1 | |||
6b95c7e2ca | |||
9d08755705 | |||
00969c1d7f | |||
a16a66f1f6 | |||
05cbbda941 | |||
a0f3b1639c | |||
218deb9947 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
pages/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
121
.gitlab-ci.yml
121
.gitlab-ci.yml
@ -1,49 +1,128 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- page
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testLTS:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: page
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
68
README.md
68
README.md
@ -1,68 +0,0 @@
|
||||
# smartipc
|
||||
smart subprocess handling
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartipc)
|
||||
[](https://gitlab.com/pushrocks/smartipc)
|
||||
[](https://github.com/pushrocks/smartipc)
|
||||
[](https://pushrocks.gitlab.io/smartipc/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartipc/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartipc/commits/master)
|
||||
[](https://david-dm.org/pushrocks/smartipc)
|
||||
[](https://www.bithound.io/github/pushrocks/smartipc/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartipc)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## The purpose
|
||||
smartipc makes it easy to spawn tasks into subprocesses without loosing control over what those processes do.
|
||||
You can transparently call functions and expect returned data using promises.
|
||||
|
||||
## Usage
|
||||
|
||||
Server:
|
||||
```typescript
|
||||
import {Ipcserver} from 'smartipc'
|
||||
import * as q from 'q'
|
||||
|
||||
let myIpcserver = new Ipcserver({
|
||||
appspace: 'mymodule'
|
||||
})
|
||||
|
||||
// The subprocess js file cannot have any cli arguments
|
||||
// since this mechanism is used by IpcServer to setup the connection
|
||||
myIpcServer.spawnProcess('./myFile','mySubProcessNameAlias') // nameAlias identifies the subprocess and will prefix any logs from child Process
|
||||
|
||||
let someData = {
|
||||
key1: 'value1',
|
||||
key2: 'value2'
|
||||
}
|
||||
|
||||
myIpcServer.call('mySubProcessNameAlias','myAwesomeFunction',someData).then(someAnswerData => {
|
||||
console.log(someAnswerData.key1)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Client:
|
||||
```typescript
|
||||
import { Ipcclient } from './smartipc'
|
||||
import * as q from 'q'
|
||||
|
||||
let localIpc = new Ipcclient() // gets its connection information automatically using CLI args internally
|
||||
|
||||
let myAwesomeFunction = (dataArg) => {
|
||||
let done = plugins.q.defer()
|
||||
console.log('awesome') // this will log transparently in the same console stream as the host process
|
||||
let someAnswerData = {key1: 'this is an answer'}
|
||||
done.resolve(someAnswerData)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
localIpc.register([myAwesomeFunction])
|
||||
```
|
||||
|
||||
[](https://push.rocks)
|
2
assets/typescriptwrap.js
Normal file
2
assets/typescriptwrap.js
Normal file
@ -0,0 +1,2 @@
|
||||
require('@git.zone/tsrun');
|
||||
require('spawn-wrap').runMain()
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
export * from './smartipc.classes.thread';
|
||||
export * from './smartipc.classes.threadfunction';
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
__export(require("./smartipc.classes.thread"));
|
||||
__export(require("./smartipc.classes.threadfunction"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsK0NBQXlDO0FBQ3pDLHVEQUFpRCJ9
|
10
dist/smartipc.classes.thread.d.ts
vendored
10
dist/smartipc.classes.thread.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
export declare let setWorkerBasePath: (basePathArg: string) => void;
|
||||
export declare class Thread {
|
||||
thread: any;
|
||||
constructor(filePathArg: string);
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send<T>(message: any): Promise<T>;
|
||||
kill(): void;
|
||||
}
|
32
dist/smartipc.classes.thread.js
vendored
32
dist/smartipc.classes.thread.js
vendored
@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartipc.plugins");
|
||||
const q = require("smartq");
|
||||
exports.setWorkerBasePath = (basePathArg) => {
|
||||
plugins.threads.config.set({
|
||||
basepath: {
|
||||
node: basePathArg
|
||||
}
|
||||
});
|
||||
};
|
||||
class Thread {
|
||||
constructor(filePathArg) {
|
||||
this.thread = plugins.threads.spawn(filePathArg);
|
||||
}
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send(message) {
|
||||
let done = q.defer();
|
||||
this.thread.send(message).on('message', (message) => {
|
||||
done.resolve(message);
|
||||
}).on('error', err => {
|
||||
done.reject(err);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
kill() {
|
||||
this.thread.kill();
|
||||
}
|
||||
}
|
||||
exports.Thread = Thread;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLnRocmVhZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDRCQUEyQjtBQUVoQixRQUFBLGlCQUFpQixHQUFHLENBQUMsV0FBbUI7SUFDL0MsT0FBTyxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDO1FBQ3ZCLFFBQVEsRUFBRTtZQUNOLElBQUksRUFBRSxXQUFXO1NBQ3BCO0tBQ0osQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFBO0FBRUQ7SUFFSSxZQUFZLFdBQW1CO1FBQzNCLElBQUksQ0FBQyxNQUFNLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDcEQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSSxDQUFJLE9BQVk7UUFDaEIsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBSyxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxTQUFTLEVBQUUsQ0FBQyxPQUFVO1lBQy9DLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDekIsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLE9BQU8sRUFBRSxHQUFHO1lBQ2QsSUFBSSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUNwQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRCxJQUFJO1FBQ0EsSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLEVBQUUsQ0FBQTtJQUN0QixDQUFDO0NBQ0o7QUF0QkQsd0JBc0JDIn0=
|
13
dist/smartipc.classes.threadfunction.d.ts
vendored
13
dist/smartipc.classes.threadfunction.d.ts
vendored
@ -1,13 +0,0 @@
|
||||
import 'typings-global';
|
||||
export interface IThreadFunction {
|
||||
(input: any, done: any): void;
|
||||
}
|
||||
export declare class ThreadFunction {
|
||||
thread: any;
|
||||
constructor(functionArg: IThreadFunction);
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send<T>(message: any): Promise<T>;
|
||||
kill(): void;
|
||||
}
|
26
dist/smartipc.classes.threadfunction.js
vendored
26
dist/smartipc.classes.threadfunction.js
vendored
@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const plugins = require("./smartipc.plugins");
|
||||
const q = require("smartq");
|
||||
class ThreadFunction {
|
||||
constructor(functionArg) {
|
||||
this.thread = plugins.threads.spawn(functionArg);
|
||||
}
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send(message) {
|
||||
let done = q.defer();
|
||||
this.thread.send(message).on('message', (message) => {
|
||||
done.resolve(message);
|
||||
}).on('error', err => {
|
||||
done.reject(err);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
kill() {
|
||||
this.thread.kill();
|
||||
}
|
||||
}
|
||||
exports.ThreadFunction = ThreadFunction;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMudGhyZWFkZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qiw4Q0FBNkM7QUFDN0MsNEJBQTJCO0FBTTNCO0lBRUksWUFBWSxXQUE0QjtRQUNwQyxJQUFJLENBQUMsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQ3BELENBQUM7SUFFRDs7T0FFRztJQUNILElBQUksQ0FBSSxPQUFZO1FBQ2hCLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUssQ0FBQTtRQUN2QixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxFQUFFLENBQUMsU0FBUyxFQUFFLENBQUMsT0FBVTtZQUMvQyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsR0FBRztZQUNkLElBQUksQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUE7UUFDcEIsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQsSUFBSTtRQUNBLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxFQUFFLENBQUE7SUFDdEIsQ0FBQztDQUNKO0FBdEJELHdDQXNCQyJ9
|
4
dist/smartipc.plugins.d.ts
vendored
4
dist/smartipc.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import 'typings-global';
|
||||
declare let threads: any;
|
||||
import * as smartq from 'smartq';
|
||||
export { smartq, threads };
|
7
dist/smartipc.plugins.js
vendored
7
dist/smartipc.plugins.js
vendored
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
let threads = require('threads');
|
||||
exports.threads = threads;
|
||||
const smartq = require("smartq");
|
||||
exports.smartq = smartq;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFLNUIsMEJBQU87QUFKWCxpQ0FBZ0M7QUFHNUIsd0JBQU0ifQ==
|
0
dist/smartipc.pool.d.ts
vendored
0
dist/smartipc.pool.d.ts
vendored
1
dist/smartipc.pool.js
vendored
1
dist/smartipc.pool.js
vendored
@ -1 +0,0 @@
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucG9vbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBvb2wudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
@ -1,7 +1,35 @@
|
||||
{
|
||||
"npmts": {
|
||||
"testTs": {
|
||||
"./test/*.ts": "./test/"
|
||||
}
|
||||
"npmts": {
|
||||
"testTs": {
|
||||
"./test/*.ts": "./test/"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartspawn",
|
||||
"description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.",
|
||||
"npmPackagename": "@push.rocks/smartspawn",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"subprocess",
|
||||
"child_process",
|
||||
"spawn",
|
||||
"threading",
|
||||
"multithreading",
|
||||
"process management",
|
||||
"async",
|
||||
"promise"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
14878
package-lock.json
generated
Normal file
14878
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
67
package.json
67
package.json
@ -1,33 +1,62 @@
|
||||
{
|
||||
"name": "smartipc",
|
||||
"version": "1.0.1",
|
||||
"description": "smart subprocess handling",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartspawn",
|
||||
"version": "3.0.3",
|
||||
"private": false,
|
||||
"description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartipc.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartspawn.git"
|
||||
},
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartipc/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartipc#README",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartspawn",
|
||||
"dependencies": {
|
||||
"@types/lodash": "^4.14.50",
|
||||
"beautylog": "^6.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
"smartq": "^1.1.0",
|
||||
"threads": "^0.7.2",
|
||||
"typings-global": "^1.0.14"
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"spawn-wrap": "^2.0.0",
|
||||
"threads": "1.7.0",
|
||||
"tiny-worker": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.2",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
}
|
||||
"@git.zone/tsbuild": "^2.1.11",
|
||||
"@git.zone/tsrun": "^1.2.8",
|
||||
"@git.zone/tstest": "^1.0.24",
|
||||
"@push.rocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^20.12.12"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"keywords": [
|
||||
"subprocess",
|
||||
"child_process",
|
||||
"spawn",
|
||||
"threading",
|
||||
"multithreading",
|
||||
"process management",
|
||||
"async",
|
||||
"promise"
|
||||
]
|
||||
}
|
6651
pnpm-lock.yaml
generated
Normal file
6651
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
120
readme.md
Normal file
120
readme.md
Normal file
@ -0,0 +1,120 @@
|
||||
Given the provided files and their contents, the comprehensive documentation for using **`@push.rocks/smartspawn`** with TypeScript and in a manner that provides thorough examples and descriptions of features and scenarios is extensive. However, I'll outline a concise and informative usage guide that can serve as a helpful starting point. For an in-depth understanding and a complete reference to all features, further reading, exploration, and experimentation with the library are recommended.
|
||||
|
||||
# @push.rocks/smartspawn
|
||||
smart subprocess handling
|
||||
|
||||
## Install
|
||||
|
||||
To install `@push.rocks/smartspawn`, open your terminal and run the following command:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/smartspawn
|
||||
```
|
||||
|
||||
This command fetches the package from npm and adds it to your project's dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
This guide uses TypeScript and ESM syntax to demonstrate how to utilize `@push.rocks/smartspawn` for smart subprocess handling in your application.
|
||||
|
||||
First, ensure that your TypeScript environment is set up to support ECMAScript modules (ESM). Your `tsconfig.json` should include:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"target": "ESNext",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Starting and Stopping a Simple Thread
|
||||
|
||||
`ThreadSimple` class allows you to manage subprocesses effectively. Here's how to start and stop a simple thread:
|
||||
|
||||
```typescript
|
||||
// Import the necessary components from the library
|
||||
import { ThreadSimple } from '@push.rocks/smartspawn';
|
||||
|
||||
// Define a function that creates, starts, and stops a thread
|
||||
async function demonstrateThreadSimple() {
|
||||
// Create an instance of ThreadSimple
|
||||
const mySimpleThread = new ThreadSimple('./path/to/worker.js');
|
||||
|
||||
// Start the thread
|
||||
await mySimpleThread.start();
|
||||
console.log('Thread has started.');
|
||||
|
||||
// Stop the thread
|
||||
await mySimpleThread.stop();
|
||||
console.log('Thread has stopped.');
|
||||
}
|
||||
|
||||
// Call the function to demonstrate its functionality
|
||||
demonstrateThreadSimple();
|
||||
```
|
||||
|
||||
The `./path/to/worker.js` should be the path to your worker script that you want to execute in a separate process.
|
||||
|
||||
### Wrapping Processes
|
||||
|
||||
`smartspawn` also provides functionality to wrap subprocesses, allowing you to modify or set up an environment before execution. Here's how to wrap and unwrap subprocesses:
|
||||
|
||||
```typescript
|
||||
import { startSpawnWrap, endSpawnWrap } from '@push.rocks/smartspawn';
|
||||
|
||||
// Start a wrap
|
||||
startSpawnWrap('path/to/script', ['arg1', 'arg2'], { ENV_VAR: 'value' });
|
||||
console.log('Subprocess wrapped.');
|
||||
|
||||
// End the wrap when it's no longer needed
|
||||
endSpawnWrap();
|
||||
console.log('Subprocess unwrapped.');
|
||||
```
|
||||
|
||||
### Advanced Thread Management
|
||||
|
||||
`@push.rocks/smartspawn` integrates with the `threads` package to provide advanced threading capabilities. Here's a brief example showing how you might utilize it for more complex scenarios:
|
||||
|
||||
```typescript
|
||||
import { Thread, spawn, Worker } from 'threads';
|
||||
|
||||
async function advancedThreadExample() {
|
||||
const thread = await spawn(new Worker('./worker'));
|
||||
|
||||
const result = await thread.doWork();
|
||||
console.log(`Result from thread: ${result}`);
|
||||
|
||||
await Thread.terminate(thread);
|
||||
}
|
||||
|
||||
advancedThreadExample();
|
||||
```
|
||||
|
||||
Ensure you explore the `threads` documentation for a more detailed understanding of creating workers and communicating between the main process and threads.
|
||||
|
||||
### Conclusion
|
||||
|
||||
The `@push.rocks/smartspawn` package simplifies managing subprocesses in your Node.js applications, offering straightforward APIs for starting, stopping, and communicating with child processes. Whether you need to execute a simple script in the background or leverage sophisticated multi-threading capabilities, `smartspawn` provides the tools necessary to implement these features efficiently and robustly.
|
||||
|
||||
Remember, the examples above are starting points. Review the source code, tests, and type declarations for a comprehensive understanding of everything `@push.rocks/smartspawn` and its integrated packages can do. Experiment with the library in your projects to best learn how to utilize its full potential in real-world applications.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
2
test/child.d.ts
vendored
2
test/child.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import 'typings-global';
|
||||
import 'smartq';
|
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
require("smartq");
|
||||
module.exports = (input, done) => {
|
||||
done('hi');
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLGtCQUFlO0FBQ2YsTUFBTSxDQUFDLE9BQU8sR0FBRyxDQUFDLEtBQUssRUFBRSxJQUFJO0lBQ3pCLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUNkLENBQUMsQ0FBQSJ9
|
@ -1,5 +0,0 @@
|
||||
import 'typings-global'
|
||||
import 'smartq'
|
||||
module.exports = (input, done) => {
|
||||
done('hi')
|
||||
}
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
26
test/test.js
26
test/test.js
@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const smartipc = require("../dist/index");
|
||||
let testThreadFunction;
|
||||
let testThread;
|
||||
describe('smartipc', function () {
|
||||
it('should create an instance of ThreadFunction', function () {
|
||||
testThreadFunction = new smartipc.ThreadFunction((input, done) => {
|
||||
let url = require('url');
|
||||
done(url.parse(input));
|
||||
});
|
||||
testThreadFunction.send('https://google.com').then(message => {
|
||||
console.log(message);
|
||||
testThreadFunction.kill();
|
||||
});
|
||||
});
|
||||
it('should create an instance of Thread', function () {
|
||||
smartipc.setWorkerBasePath(__dirname);
|
||||
testThread = new smartipc.Thread('child.js');
|
||||
testThread.send('https://google.com').then(message => {
|
||||
console.log(message);
|
||||
testThread.kill();
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiwwQ0FBeUM7QUFFekMsSUFBSSxrQkFBMkMsQ0FBQTtBQUMvQyxJQUFJLFVBQTJCLENBQUE7QUFFL0IsUUFBUSxDQUFDLFVBQVUsRUFBQztJQUNoQixFQUFFLENBQUMsNkNBQTZDLEVBQUM7UUFDN0Msa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsY0FBYyxDQUFDLENBQUMsS0FBSyxFQUFFLElBQUk7WUFDekQsSUFBSSxHQUFHLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ3hCLElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7UUFDMUIsQ0FBQyxDQUFDLENBQUE7UUFDRixrQkFBa0IsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUN0RCxPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFBO1lBQ3BCLGtCQUFrQixDQUFDLElBQUksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMscUNBQXFDLEVBQUM7UUFDckMsUUFBUSxDQUFDLGlCQUFpQixDQUFDLFNBQVMsQ0FBQyxDQUFBO1FBQ3JDLFVBQVUsR0FBRyxJQUFJLFFBQVEsQ0FBQyxNQUFNLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDNUMsVUFBVSxDQUFDLElBQUksQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLElBQUksQ0FBQyxPQUFPO1lBQzlDLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUE7WUFDcEIsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1FBQ3JCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
28
test/test.ts
28
test/test.ts
@ -1,27 +1,7 @@
|
||||
import 'typings-test'
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as smartipc from '../dist/index'
|
||||
import * as smartspawn from '../ts/index.js';
|
||||
|
||||
let testThreadFunction: smartipc.ThreadFunction
|
||||
let testThread: smartipc.Thread
|
||||
tap.test('should create a simple test function', async () => {});
|
||||
|
||||
describe('smartipc',function(){
|
||||
it('should create an instance of ThreadFunction',function(){
|
||||
testThreadFunction = new smartipc.ThreadFunction((input, done) => {
|
||||
let url = require('url')
|
||||
done(url.parse(input))
|
||||
})
|
||||
testThreadFunction.send('https://google.com').then(message => {
|
||||
console.log(message)
|
||||
testThreadFunction.kill()
|
||||
})
|
||||
})
|
||||
it('should create an instance of Thread',function(){
|
||||
smartipc.setWorkerBasePath(__dirname)
|
||||
testThread = new smartipc.Thread('child.js')
|
||||
testThread.send('https://google.com').then(message => {
|
||||
console.log(message)
|
||||
testThread.kill()
|
||||
})
|
||||
})
|
||||
})
|
||||
export default tap.start();
|
||||
|
3
testassets/child.ts
Normal file
3
testassets/child.ts
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (input, done) => {
|
||||
done(input);
|
||||
};
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartspawn',
|
||||
version: '3.0.3',
|
||||
description: 'A node module for smart subprocess handling with support for promises and streamlined subprocess communication.'
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
export * from './smartipc.classes.thread'
|
||||
export * from './smartipc.classes.threadfunction'
|
||||
export * from './smartspawn.classes.threadsimple.js';
|
||||
export * from './smartspawn.wrap.js';
|
||||
|
||||
export * from 'threads';
|
||||
|
@ -1,34 +0,0 @@
|
||||
import * as plugins from './smartipc.plugins'
|
||||
import * as q from 'smartq'
|
||||
|
||||
export let setWorkerBasePath = (basePathArg: string) => {
|
||||
plugins.threads.config.set({
|
||||
basepath: {
|
||||
node: basePathArg
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export class Thread {
|
||||
thread
|
||||
constructor(filePathArg: string) {
|
||||
this.thread = plugins.threads.spawn(filePathArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send<T>(message: any): Promise<T> {
|
||||
let done = q.defer<T>()
|
||||
this.thread.send(message).on('message', (message: T) => {
|
||||
done.resolve(message)
|
||||
}).on('error', err => {
|
||||
done.reject(err)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.thread.kill()
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import 'typings-global'
|
||||
import * as plugins from './smartipc.plugins'
|
||||
import * as q from 'smartq'
|
||||
|
||||
export interface IThreadFunction {
|
||||
(input, done): void
|
||||
}
|
||||
|
||||
export class ThreadFunction {
|
||||
thread
|
||||
constructor(functionArg: IThreadFunction) {
|
||||
this.thread = plugins.threads.spawn(functionArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send<T>(message: any): Promise<T> {
|
||||
let done = q.defer<T>()
|
||||
this.thread.send(message).on('message', (message: T) => {
|
||||
done.resolve(message)
|
||||
}).on('error', err => {
|
||||
done.reject(err)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.thread.kill()
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
import 'typings-global'
|
||||
let threads = require('threads')
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
export {
|
||||
smartq,
|
||||
threads
|
||||
}
|
29
ts/smartspawn.classes.threadsimple.ts
Normal file
29
ts/smartspawn.classes.threadsimple.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as childProcess from 'child_process';
|
||||
|
||||
export class ThreadSimple {
|
||||
public workerPath: string;
|
||||
public threadChildProcess: childProcess.ChildProcess;
|
||||
public forkOptions: childProcess.ForkOptions;
|
||||
public argvArgs: string[];
|
||||
constructor(
|
||||
filePathArg: string,
|
||||
argvArgs: string[] = [],
|
||||
forkOptionsArg: childProcess.ForkOptions = {}
|
||||
) {
|
||||
this.workerPath = filePathArg;
|
||||
this.forkOptions = forkOptionsArg;
|
||||
this.argvArgs = argvArgs;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
const forkPath = this.workerPath;
|
||||
this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions);
|
||||
return this.threadChildProcess;
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
this.threadChildProcess.kill();
|
||||
}
|
||||
}
|
4
ts/smartspawn.paths.ts
Normal file
4
ts/smartspawn.paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
|
||||
export const packageBase = plugins.path.join(__dirname, '../');
|
||||
export const typescriptwrapJs = plugins.path.join(packageBase, 'assets/typescriptwrap.js');
|
5
ts/smartspawn.plugins.ts
Normal file
5
ts/smartspawn.plugins.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import * as threads from 'threads';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { path, smartpromise, threads };
|
18
ts/smartspawn.wrap.ts
Normal file
18
ts/smartspawn.wrap.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import * as spawnWrap from 'spawn-wrap';
|
||||
|
||||
let unwrap: any = null;
|
||||
|
||||
export const startSpawnWrap = (filePath: string, cliArgs: string[] = [], envArgs: any = {}) => {
|
||||
const spawnArray = [filePath];
|
||||
for (const cliArg of cliArgs) {
|
||||
spawnArray.push(cliArg);
|
||||
}
|
||||
unwrap = spawnWrap(spawnArray, envArgs);
|
||||
};
|
||||
|
||||
export const endSpawnWrap = () => {
|
||||
if (unwrap) {
|
||||
unwrap();
|
||||
unwrap = null;
|
||||
}
|
||||
};
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user