daemonize-process 4.1.1 → 4.1.4

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/README.md CHANGED
@@ -10,14 +10,12 @@ Differences to the `daemon` module include:
10
10
  - Exposes all options of `child_process.spawn`.
11
11
  - Cleans up `process.env` after itself.
12
12
 
13
- ## Install
13
+ ## Usage
14
14
 
15
- ```console
16
- $ npm i daemonize-process
15
+ ```sh
16
+ pnpm add daemonize-process
17
17
  ```
18
18
 
19
- ## Examples
20
-
21
19
  ```js
22
20
  import {daemonizeProcess} from "daemonize-process";
23
21
 
@@ -39,6 +37,4 @@ The `options` object can contain any valid [`child_process.spawn` option](https:
39
37
 
40
38
  By default the standard streams of the child are ignored (e.g. attached to `/dev/null` or equivalent). If you need these streams, adjust the `stdio` option.
41
39
 
42
- ## License
43
-
44
40
  © [silverwind](https://github.com/silverwind), distributed under BSD licence
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { SpawnOptions } from 'node:child_process';
1
+ import { SpawnOptions } from "node:child_process";
2
+ //#region index.d.ts
2
3
  type DaemonizeProcessOpts = {
3
- /** The path to the script to be executed. Default: The current script. */
4
- script?: string;
5
- /** The command line arguments to be used. Default: The current arguments. */
6
- arguments?: string[];
7
- /** The path to the Node.js binary to be used. Default: The current Node.js binary. */
8
- node?: string;
9
- /** The exit code to be used when exiting the parent process. Default: `0`. */
10
- exitCode?: number;
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;
11
12
  } & SpawnOptions;
12
13
  export declare function daemonizeProcess(opts?: DaemonizeProcessOpts): void;
13
- export {};
14
- //# sourceMappingURL=index.d.ts.map
14
+ //#endregion
package/dist/index.js CHANGED
@@ -1,29 +1,23 @@
1
1
  import { spawn } from "node:child_process";
2
- import { env, argv, cwd, execPath, exit } from "node:process";
2
+ import { argv, cwd, env, execPath, exit } from "node:process";
3
+
4
+ //#region index.ts
3
5
  const id = "_DAEMONIZE_PROCESS";
4
6
  function daemonizeProcess(opts = {}) {
5
- if (id in env) {
6
- delete env[id];
7
- } else {
8
- const o = {
9
- // spawn options
10
- env: Object.assign(env, opts.env, { [id]: "1" }),
11
- cwd: cwd(),
12
- stdio: "ignore",
13
- detached: true,
14
- // custom options
15
- node: execPath,
16
- script: argv[1],
17
- arguments: argv.slice(2),
18
- exitCode: 0,
19
- ...opts
20
- };
21
- const args = [o.script, ...o.arguments];
22
- const proc = spawn(o.node, args, o);
23
- proc?.unref?.();
24
- exit(o.exitCode);
25
- }
7
+ if (id in env) delete env[id];
8
+ else {
9
+ const options = {
10
+ cwd: cwd(),
11
+ stdio: "ignore",
12
+ detached: true,
13
+ exitCode: 0,
14
+ ...opts,
15
+ env: opts.env ? Object.assign(Object.create(opts.env), { [id]: "1" }) : Object.assign(env, { [id]: "1" })
16
+ };
17
+ spawn(opts.node ?? execPath, [opts.script ?? argv[1], ...opts.arguments ?? argv.slice(2)], options).unref();
18
+ exit(options.exitCode);
19
+ }
26
20
  }
27
- export {
28
- daemonizeProcess
29
- };
21
+
22
+ //#endregion
23
+ export { daemonizeProcess };
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "daemonize-process",
3
- "version": "4.1.1",
3
+ "version": "4.1.4",
4
4
  "description": "Daemonize the current Node.js process",
5
5
  "author": "silverwind <me@silverwind.io>",
6
- "repository": "silverwind/daemonize-process",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/silverwind/daemonize-process.git"
9
+ },
7
10
  "license": "BSD-2-Clause",
8
11
  "type": "module",
9
12
  "sideEffects": false,
@@ -14,20 +17,21 @@
14
17
  "dist"
15
18
  ],
16
19
  "engines": {
17
- "node": ">=18"
20
+ "node": ">=18",
21
+ "bun": "*"
18
22
  },
19
23
  "devDependencies": {
20
- "@types/node": "22.13.4",
21
- "eslint": "8.57.0",
22
- "eslint-config-silverwind": "99.0.0",
23
- "eslint-config-silverwind-typescript": "9.2.2",
24
- "jest-extended": "4.0.2",
25
- "typescript": "5.7.3",
26
- "typescript-config-silverwind": "7.0.0",
27
- "updates": "16.4.2",
28
- "versions": "12.1.3",
29
- "vite": "6.1.0",
30
- "vite-config-silverwind": "4.0.0",
31
- "vitest": "3.0.5"
24
+ "@types/node": "26.6.3",
25
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
26
+ "eslint": "10.11.0",
27
+ "eslint-config-silverwind": "151.0.1",
28
+ "tsdown": "0.23.0",
29
+ "tsdown-config-silverwind": "4.1.2",
30
+ "typescript": "6.0.3",
31
+ "typescript-config-silverwind": "21.0.1",
32
+ "updates": "19.0.2",
33
+ "updates-config-silverwind": "4.0.7",
34
+ "versions": "15.5.1",
35
+ "vitest": "5.0.2"
32
36
  }
33
- }
37
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIrD,KAAK,oBAAoB,GAAG;IAC1B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,YAAY,CAAC;AAEjB,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,oBAAyB,QAyB/D"}