daemonize-process 4.0.0 → 4.1.0
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/dist/index.d.ts +14 -0
- package/dist/index.js +29 -0
- package/package.json +18 -11
- package/index.js +0 -28
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SpawnOptions } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
type DaemonizeProcessOpts = {
|
|
4
|
+
/** The path to the script to be executed. Default: The current script. */
|
|
5
|
+
script?: string;
|
|
6
|
+
/** The command line arguments to be used. Default: The current arguments. */
|
|
7
|
+
arguments?: string[];
|
|
8
|
+
/** The path to the Node.js binary to be used. Default: The current Node.js binary. */
|
|
9
|
+
node?: string;
|
|
10
|
+
/** The exit code to be used when exiting the parent process. Default: `0`. */
|
|
11
|
+
exitCode?: number;
|
|
12
|
+
} & SpawnOptions;
|
|
13
|
+
export declare function daemonizeProcess(opts?: DaemonizeProcessOpts): void;
|
|
14
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { env, cwd, execPath, argv, exit } from 'node:process';
|
|
3
|
+
|
|
4
|
+
const id = "_DAEMONIZE_PROCESS";
|
|
5
|
+
function daemonizeProcess(opts = {}) {
|
|
6
|
+
if (id in env) {
|
|
7
|
+
delete env[id];
|
|
8
|
+
} else {
|
|
9
|
+
const o = {
|
|
10
|
+
// spawn options
|
|
11
|
+
env: Object.assign(env, opts.env, { [id]: "1" }),
|
|
12
|
+
cwd: cwd(),
|
|
13
|
+
stdio: "ignore",
|
|
14
|
+
detached: true,
|
|
15
|
+
// custom options
|
|
16
|
+
node: execPath,
|
|
17
|
+
script: argv[1],
|
|
18
|
+
arguments: argv.slice(2),
|
|
19
|
+
exitCode: 0,
|
|
20
|
+
...opts
|
|
21
|
+
};
|
|
22
|
+
const args = [o.script, ...o.arguments];
|
|
23
|
+
const proc = spawn(o.node, args, o);
|
|
24
|
+
proc?.unref?.();
|
|
25
|
+
exit(o.exitCode);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { daemonizeProcess };
|
package/package.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daemonize-process",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Daemonize the current Node.js process",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/daemonize-process",
|
|
7
7
|
"license": "BSD-2-Clause",
|
|
8
|
-
"exports": "./index.js",
|
|
9
8
|
"type": "module",
|
|
10
9
|
"sideEffects": false,
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"exports": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
11
16
|
"engines": {
|
|
12
17
|
"node": ">=18"
|
|
13
18
|
},
|
|
14
|
-
"files": [
|
|
15
|
-
"./index.js"
|
|
16
|
-
],
|
|
17
19
|
"devDependencies": {
|
|
18
|
-
"
|
|
19
|
-
"eslint
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"@types/node": "20.12.12",
|
|
21
|
+
"eslint": "8.57.0",
|
|
22
|
+
"eslint-config-silverwind": "85.1.4",
|
|
23
|
+
"eslint-config-silverwind-typescript": "3.2.7",
|
|
24
|
+
"typescript": "5.4.5",
|
|
25
|
+
"typescript-config-silverwind": "4.3.2",
|
|
26
|
+
"updates": "16.1.1",
|
|
27
|
+
"versions": "12.0.2",
|
|
28
|
+
"vite": "5.2.11",
|
|
29
|
+
"vite-config-silverwind": "1.1.2",
|
|
30
|
+
"vite-plugin-dts": "3.9.1"
|
|
24
31
|
}
|
|
25
32
|
}
|
package/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {spawn} from "node:child_process";
|
|
2
|
-
import {env, cwd, execPath, argv, exit} from "node:process";
|
|
3
|
-
|
|
4
|
-
const id = "_DAEMONIZE_PROCESS";
|
|
5
|
-
|
|
6
|
-
export function daemonizeProcess(opts = {}) {
|
|
7
|
-
if (id in env) {
|
|
8
|
-
// In the child, clean up the tracking environment variable
|
|
9
|
-
delete env[id];
|
|
10
|
-
} else {
|
|
11
|
-
// In the parent, set the tracking environment variable, fork the child and exit
|
|
12
|
-
const o = {
|
|
13
|
-
// spawn options
|
|
14
|
-
env: Object.assign(env, opts.env, {[id]: "1"}),
|
|
15
|
-
cwd: cwd(),
|
|
16
|
-
stdio: "ignore",
|
|
17
|
-
detached: true,
|
|
18
|
-
// custom options
|
|
19
|
-
node: execPath,
|
|
20
|
-
script: argv[1],
|
|
21
|
-
arguments: argv.slice(2),
|
|
22
|
-
exitCode: 0, ...opts
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
spawn(o.node, [o.script].concat(o.arguments), o).unref();
|
|
26
|
-
exit(o.exitCode);
|
|
27
|
-
}
|
|
28
|
-
}
|